From patchwork Mon Nov 28 02:14:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Wang X-Patchwork-Id: 26457 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5390001wrr; Sun, 27 Nov 2022 18:15:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf77fvNjLET/UR/lU0Vmhgrpfwx4UOA2RTZeWCQlYpuk9Z3TITFzctPW13pFYBl66d39pYPN X-Received: by 2002:a17:907:7e86:b0:7af:bc9:5e8d with SMTP id qb6-20020a1709077e8600b007af0bc95e8dmr42385292ejc.3.1669601703503; Sun, 27 Nov 2022 18:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669601703; cv=none; d=google.com; s=arc-20160816; b=bmbcEcAP9Lvtz4BjpzNOnfLAfu+9hsYRTiHF+HEWShjcIysMm20oBiorN03ScI/yGj ZM6aJJzyg3mZIv4IszbFKw0g51owSjgtjG1AamNx5jV6mCwxbT0rELzbvisbGnROQ68T 0zWhFXb76+XWWnzFqBo5u4KwPRtl04r62b+pXViSXbJXH/+p2ltGeX1oxHbZbcQac5WC r4DFH/a1Ey89bS3iITtIZ2dSHhETPRB2D/oMUV8z2I2/CSKfwSR7K1lhYoaStCzbHwn0 U1S+ce5ALNK/jaMwg9X3o/Ftmz1QDZnoYuHyi24kBiatDzT9XLav3cwjstdi6lFJhe+M esSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:message-id:date:subject:cc:to :from:dmarc-filter:delivered-to; bh=0AW6ArF/jrZdlNeRmPCWd6stObt7XnWP40MdPwEpqPw=; b=cPHALnRXSRe/ZIhzCxPdY9cLgGX0+3uB3pRi4tTkasFW4QXsaY7t5k6zgx4xrpWV8r mfzhpW+n6xp4hrlwXvEv8fQJtggREG8N/nyx4u3ppskqJzD/MResD+bPnrLGDdZGCcqS dDru2zETyyMREmlCfHREWhPx955XKX2GtJuOgeyeymvh6X6sCpLiu4V2DlaYh2yL3o2k +B3z4RbQCo8KFgIebD29PLppQpXFGECagS/WgqETs/9O8teFeUjkjV/ajXiYj41u7fFj +zNz6c3O53qixFUqRm2tZLSgaWfknKDG+0KNRBrriZOevO6B8w46JVFHAgIuTI5gSJBd fGjw== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id wg14-20020a17090705ce00b007c00323cc16si1190535ejb.973.2022.11.27.18.15.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Nov 2022 18:15:03 -0800 (PST) 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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D9AF43858421 for ; Mon, 28 Nov 2022 02:15:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from zg8tmja5ljk3lje4ms43mwaa.icoremail.net (zg8tmja5ljk3lje4ms43mwaa.icoremail.net [209.97.181.73]) by sourceware.org (Postfix) with SMTP id DB7763858D3C for ; Mon, 28 Nov 2022 02:14:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DB7763858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eswincomputing.com Received: from localhost.localdomain (unknown [10.12.130.31]) by app1 (Coremail) with SMTP id EwgMCgCXXYaGGYRjOsoTAA--.5873S4; Mon, 28 Nov 2022 10:14:30 +0800 (CST) From: Feng Wang To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, research_trasio@irq.a4lg.com, wangfeng Subject: [PATCH] RISC-V: Support the ins "rol" with immediate operand Date: Mon, 28 Nov 2022 02:14:28 +0000 Message-Id: <20221128021428.13824-1-wangfeng@eswincomputing.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: EwgMCgCXXYaGGYRjOsoTAA--.5873S4 X-Coremail-Antispam: 1UD129KBjvJXoWxJFy8Jw17WryDury5trW8WFg_yoWruF1Dpw 4xKw43trW8Jr4fK34SyFW5Ka15ArnFqF4Yv39ayryjyry5Jryqga10y34aq3y5JF4FkF17 ZFW3uw45urs0gaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkF14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCY02Avz4vE-syl42xK 82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGw C20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48J MIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMI IF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E 87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x0JUywZ7UUUUU= X-CM-SenderInfo: pzdqwwxhqjqvxvzl0uprps33xlqjhudrp/ X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP 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: , 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?1750704275871068126?= X-GMAIL-MSGID: =?utf-8?q?1750704275871068126?= From: wangfeng There is no Immediate operand of ins "rol" accroding to the B-ext, so the immediate operand should be loaded into register at first. But we can convert it to the ins "rori" or "roriw", and then one immediate load ins can be reduced. Please refer to the following use cases: unsigned long foo2(unsigned long rs1) { return (rs1 << 10) | (rs1 >> 54); } The complier result is: li a1,10 rol a0,a0,a1 This patch will generate one ins rori a0,a0,54 gcc/ChangeLog: * config/riscv/bitmanip.md: Add immediate_operand support in rotl RTL pattern gcc/testsuite/ChangeLog: * gcc.target/riscv/zbb-rol-ror-04.c: New test. * gcc.target/riscv/zbb-rol-ror-05.c: New test. --- gcc/config/riscv/bitmanip.md | 36 +++++++++++++++---- .../gcc.target/riscv/zbb-rol-ror-04.c | 24 +++++++++++++ .../gcc.target/riscv/zbb-rol-ror-05.c | 15 ++++++++ 3 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/zbb-rol-ror-04.c create mode 100644 gcc/testsuite/gcc.target/riscv/zbb-rol-ror-05.c diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index d17133d58c1..cddfa2a4b19 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -300,25 +300,49 @@ (define_insn "rotlsi3" [(set (match_operand:SI 0 "register_operand" "=r") (rotate:SI (match_operand:SI 1 "register_operand" "r") - (match_operand:QI 2 "register_operand" "r")))] + (match_operand:QI 2 "arith_operand" "rI")))] "TARGET_ZBB" - "rol%~\t%0,%1,%2" + { + if (immediate_operand(operands[2], QImode)) + { + operands[2] = GEN_INT(GET_MODE_BITSIZE (SImode) - INTVAL(operands[2])); + return "rori\t%0,%1,%2"; + } + else + return "rol\t%0,%1,%2"; + } [(set_attr "type" "bitmanip")]) (define_insn "rotldi3" [(set (match_operand:DI 0 "register_operand" "=r") (rotate:DI (match_operand:DI 1 "register_operand" "r") - (match_operand:QI 2 "register_operand" "r")))] + (match_operand:QI 2 "arith_operand" "rI")))] "TARGET_64BIT && TARGET_ZBB" - "rol\t%0,%1,%2" + { + if (immediate_operand(operands[2], QImode)) + { + operands[2] = GEN_INT(GET_MODE_BITSIZE (DImode) - INTVAL(operands[2])); + return "rori\t%0,%1,%2"; + } + else + return "rol\t%0,%1,%2"; + } [(set_attr "type" "bitmanip")]) (define_insn "rotlsi3_sext" [(set (match_operand:DI 0 "register_operand" "=r") (sign_extend:DI (rotate:SI (match_operand:SI 1 "register_operand" "r") - (match_operand:QI 2 "register_operand" "r"))))] + (match_operand:QI 2 "arith_operand" "rI"))))] "TARGET_64BIT && TARGET_ZBB" - "rolw\t%0,%1,%2" + { + if (immediate_operand(operands[2], QImode)) + { + operands[2] = GEN_INT(GET_MODE_BITSIZE (SImode) - INTVAL(operands[2])); + return "roriw\t%0,%1,%2"; + } + else + return "rolw\t%0,%1,%2"; + } [(set_attr "type" "bitmanip")]) ;; orc.b (or-combine) is added as an unspec for the benefit of the support diff --git a/gcc/testsuite/gcc.target/riscv/zbb-rol-ror-04.c b/gcc/testsuite/gcc.target/riscv/zbb-rol-ror-04.c new file mode 100644 index 00000000000..23883cc3a5e --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbb-rol-ror-04.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zbb -mabi=lp64d -O2" } */ +/* { dg-skip-if "" { *-*-* } { "-g" } } */ + +unsigned long foo1 (unsigned long rs1) +{ return (rs1 >> (34)) | (rs1 << 30); } + +unsigned long foo2(unsigned long rs1) +{ + return (rs1 << 10) | (rs1 >> 54); +} + +unsigned int foo3(unsigned int rs1) +{ + return (rs1 >> 20) | (rs1 << 12); +} + +unsigned int foo4(unsigned int rs1) +{ + return (rs1 << 10) | (rs1 >> 22); +} + +/* { dg-final { scan-assembler-times "rori\t" 2 } } */ +/* { dg-final { scan-assembler-times "roriw" 2 } } */ \ No newline at end of file diff --git a/gcc/testsuite/gcc.target/riscv/zbb-rol-ror-05.c b/gcc/testsuite/gcc.target/riscv/zbb-rol-ror-05.c new file mode 100644 index 00000000000..3e300a30b9b --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbb-rol-ror-05.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32gc_zbb -mabi=ilp32" } */ +/* { dg-skip-if "" { rv64-*-* } { "-g" } } */ + +unsigned int foo1(unsigned int rs1) +{ + return (rs1 >> 20) | (rs1 << 12); +} + +unsigned int foo2(unsigned int rs1) +{ + return (rs1 << 10) | (rs1 >> 22); +} + +/* { dg-final { scan-assembler-times "rori" 2 } } */ \ No newline at end of file