From patchwork Sat May 6 00:02:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 90633 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp764793vqo; Fri, 5 May 2023 17:03:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47XprVFNVXt+56yilB8HcbMbBLkDGbuFMV4AIZiXaSKy24k7yI5W0xhyWL4SF7K7vhga5s X-Received: by 2002:a17:907:2d1f:b0:94f:a309:67b9 with SMTP id gs31-20020a1709072d1f00b0094fa30967b9mr2599859ejc.6.1683331420664; Fri, 05 May 2023 17:03:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683331420; cv=none; d=google.com; s=arc-20160816; b=gP2kRC8uksGGOJNu1n8ERyWwgp0vtEBL3NBkm589bw8HatH6qG5IHO8rWah6rIFPsK JbXeYVqat3pX0DdToNTdijjtvg/aRoIk4YHdxNp3faDt4w0VvknFy6U3TlrgIIxwCBq1 K7o5WPcNr8zKnXAQNSmfI7cM57YoG3WAHbiD0yrznFJEGs8ZG96yyz0COu/nJy+B+htk tlQ8f6AOlOGZbjaK6j0h7UL6QIAixuiLKIDtBWjt4zQLmK1gTE83r7yK29WyHL9oMSCD disT78tmnuq5m5KhVFELTq+1MVNIDyaYG5eSZ1moT3NWm9SB5tKzJh5W7y5w/xE6cYnn UAHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:date:message-id :content-transfer-encoding:mime-version:subject:to:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=cVO4x7gwKrqS79ZVaAOVHmBfVONr83M95ecB/byDOC0=; b=YPYyvuH0DeKhHqeAX6o89SktA/WG1pOlOagWsxxauOohhv+Kch/vM6Hrp9yWfTAVo0 bVrVl7YMyK8XaesR7/oiEE2ChdXRDYutmtF6z6bm0F2PwFirfIk2XSN+nD6VF4yvUDrc PAQKF/9wk9mr4sfgDZPhMNq5/DHR6jKxy/yPKyL+Ftp87JIksAtRhhOBgdkM7X9s6Xw/ 4MQprR7OJfnQ6vKNtt9H6sxZJuliQnkL5FPxvNR7mosJsg4YAlqCj7cd/Kjorp8RdlDs 4q4Y012PopYz85dPt5NV8zCauFQYwSHlQ5WSn6pqKh+TIwtWrE7tDJVrE3mmxhnkfafn aihg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yO02FmPh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gt18-20020a170906f21200b0094f8b2177c3si1829561ejb.200.2023.05.05.17.03.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 17:03:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yO02FmPh; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 547D93858D35 for ; Sat, 6 May 2023 00:03:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 547D93858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683331419; bh=cVO4x7gwKrqS79ZVaAOVHmBfVONr83M95ecB/byDOC0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yO02FmPhGsYbSeIci38GOUZvSLoXFD02EtPsMZ5HHjOEJenwh8V+/nkiKynfoT0QC dPQNm0y0pwWEb/dAr8uQdLI87ieZkas962bEjrQD16EMFLzOL/EHx5SUJ1wDHeO7jx 4SzTpEqBzRiHvDvEleJl767ugJ0YO4sZwb14BuGk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp1.axis.com (smtp1.axis.com [195.60.68.17]) by sourceware.org (Postfix) with ESMTPS id 417CB3858D1E for ; Sat, 6 May 2023 00:02:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 417CB3858D1E To: Subject: [committed] CRIS: peephole2 an add into two addq or subq MIME-Version: 1.0 Message-ID: <20230506000251.0DDBD20448@pchp3.se.axis.com> Date: Sat, 6 May 2023 02:02:51 +0200 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Hans-Peter Nilsson via Gcc-patches From: Hans-Peter Nilsson Reply-To: Hans-Peter Nilsson Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765100927642992954?= X-GMAIL-MSGID: =?utf-8?q?1765100927642992954?= Unfortunately, doesn't cause a performance improvement for coremark, but happens a few times in newlib, just enough to affect coremark 0.01% by size (or 4 bytes, and three cycles (__fwalk_sglue and __vfiprintf_r each two bytes). gcc: * config/cris/cris.md (splitop): Add PLUS. * config/cris/cris.cc (cris_split_constant): Also handle PLUS when a split into two insns may be useful. gcc/testsuite: * gcc.target/cris/peep2-addsplit1.c: New test. --- gcc/config/cris/cris.cc | 25 +++++++- gcc/config/cris/cris.md | 6 +- .../gcc.target/cris/peep2-addsplit1.c | 59 +++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/cris/peep2-addsplit1.c diff --git a/gcc/config/cris/cris.cc b/gcc/config/cris/cris.cc index 331f5908a538..561ca1b3fa92 100644 --- a/gcc/config/cris/cris.cc +++ b/gcc/config/cris/cris.cc @@ -2642,7 +2642,30 @@ cris_split_constant (HOST_WIDE_INT wval, enum rtx_code code, int32_t ival = (int32_t) wval; uint32_t uval = (uint32_t) wval; - if (code != AND || IN_RANGE(ival, -32, 31) + /* Can we do with two addq or two subq, improving chances of filling a + delay-slot? At worst, we break even, both performance and + size-wise. */ + if (code == PLUS + && (IN_RANGE (ival, -63 * 2, -63 - 1) + || IN_RANGE (ival, 63 + 1, 63 * 2))) + { + if (generate) + { + int sign = ival < 0 ? -1 : 1; + int aval = abs (ival); + + if (mode != SImode) + { + dest = gen_rtx_REG (SImode, REGNO (dest)); + op = gen_rtx_REG (SImode, REGNO (op)); + } + emit_insn (gen_addsi3 (dest, op, GEN_INT (63 * sign))); + emit_insn (gen_addsi3 (dest, op, GEN_INT ((aval - 63) * sign))); + } + return 2; + } + + if (code != AND || IN_RANGE (ival, -32, 31) /* Implemented using movu.[bw] elsewhere. */ || ival == 255 || ival == 65535 /* Implemented using clear.[bw] elsewhere. */ diff --git a/gcc/config/cris/cris.md b/gcc/config/cris/cris.md index 53fc2f2de4af..243d47748b78 100644 --- a/gcc/config/cris/cris.md +++ b/gcc/config/cris/cris.md @@ -209,7 +209,7 @@ (define_code_iterator plusminusumin [plus minus umin]) (define_code_iterator plusumin [plus umin]) ;; For opsplit1. -(define_code_iterator splitop [and]) +(define_code_iterator splitop [and plus]) ;; The addsubbo and nd code-attributes form a hack. We need to output ;; "addu.b", "subu.b" but "bound.b" (no "u"-suffix) which means we'd @@ -2984,6 +2984,10 @@ (define_peephole2 ; movandsplit1 ;; Large (read: non-quick) numbers can sometimes be AND:ed by other means. ;; Testcase: gcc.target/cris/peep2-andsplit1.c +;; +;; Another case is add N,rx with -126..-64,64..126: it has the same +;; size and execution time as two addq or subq, but addq and subq can fill +;; a delay-slot. (define_peephole2 ; opsplit1 [(parallel [(set (match_operand 0 "register_operand") diff --git a/gcc/testsuite/gcc.target/cris/peep2-addsplit1.c b/gcc/testsuite/gcc.target/cris/peep2-addsplit1.c new file mode 100644 index 000000000000..7dff1d8c77c7 --- /dev/null +++ b/gcc/testsuite/gcc.target/cris/peep2-addsplit1.c @@ -0,0 +1,52 @@ +/* Check that "opsplit1" with PLUS does its job. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-leading-underscore" } */ +/* { dg-final { check-function-bodies "**" "" "" } } */ + +int addsi (int x) +{ + return x + 64; +} + +char addqi (char x) +{ + return x + 126; +} + +short addhi (short x) +{ + return x - 64; +} + +unsigned short addhi2 (short x) +{ + return x - 126; +} + +/* +** addsi: +** addq 63,.r10 +** ret +** addq 1,.r10 +*/ + +/* +** addqi: +** addq 63,.r10 +** ret +** addq 63,.r10 +*/ + +/* +** addhi: +** subq 63,.r10 +** ret +** subq 1,.r10 +*/ + +/* +** addhi2: +** subq 63,.r10 +** ret +** subq 63,.r10 +*/