Message ID | 20230410050701.10254-1-mynameisxiaou@gmail.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1681849vqo; Sun, 9 Apr 2023 22:08:04 -0700 (PDT) X-Google-Smtp-Source: AKy350ayQmwnY4xYzpHCkVSvarBpvdRjJi/fw2UPKqZPJQDykICx0XFKRRGIYoQygvQpS8iNc2So X-Received: by 2002:aa7:d0cf:0:b0:4fb:2060:4c20 with SMTP id u15-20020aa7d0cf000000b004fb20604c20mr5514154edo.31.1681103284410; Sun, 09 Apr 2023 22:08:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681103284; cv=none; d=google.com; s=arc-20160816; b=hAnUVoMIh7A7CaEj7JczZgXEpWPCPajdlJea1lnfvuO3V/Nqqx71I8MsSxNGzooYd/ y6UhFVPluwtTx9Kn4K8Marzg5iMV3fXaT86JyhrS0q8ekx/n4HiyeC3CZl8E9PxJojYW EumaG75tN/L3TMvvDN8r8WwoBUqNCBBlCosv1HO3OqXmxs3rcfTHPN9trhddGu0RU0SC UB9hy/Wm+FFcAnN+NIibvLA9Dg0mU6Rv79mLCrXnzrPizku5gV9TIhN4ivBxN1Rc6EJC UqbA/BNmOQ8PzQo7D71P5NV5fCO8qQDZekppcm8sWqZ6PqP00rXV8aL2PnoUc0DLRDXA 9pdw== 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 :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=fWV7W5AeWeSC5n4A+2pSI4GHv+j9Az1oHBwjMcd8sS8=; b=vvSw996+KbCgHrUt2UEHDDXVWs8PKaheS6uBkDpevdvaldBJk1N830dn+Fl3X+0dC1 +LRlkIfSNX9uQnY40Fiwc1WzIb7uvl+hsiT0AvAXD8NaVPKLqAMq6PpnNjqmLkbK8P5W PkPk0ff3m/QgNuH9oRZjWH8fZsksuJrp2XFuFFU+jzifK7FodAN5X41lK8GN29GE4quP zZcaReM284u2ols0EA+Cqxp7zIWLR5EKUPr0cVgNK1c1+UjeKatHnz+XTMknE1K+atgL Kn8Az5y0dLl5vXlm/EiAYItN73rJaOvxe0FUyG+nmkkiXVUeK/fmbE+Xa/kjfZGWy1cn wzRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=t8ibdSn5; 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 k17-20020aa7c391000000b004fafc269d55si9181831edq.113.2023.04.09.22.08.04 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Apr 2023 22:08:04 -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=t8ibdSn5; 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 0E60C385842D for <ouuuleilei@gmail.com>; Mon, 10 Apr 2023 05:08:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E60C385842D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681103283; bh=fWV7W5AeWeSC5n4A+2pSI4GHv+j9Az1oHBwjMcd8sS8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=t8ibdSn5umzo/Bn+eSpE+FoP9KTX/5gNOzWwM1EsGZGK+N0Dw8i2T7MId0E98+qAx b0BShtrPl6t/Sr65oqSLW+OspNPcHcdkQdVRpdfXXgEDpF4GAboLGqhRdrGMpYguq+ 9qj1mMCLDUHdeGGNOmujfM/n62l0XLmCQX1lawMw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id EC3FF3858D3C for <gcc-patches@gcc.gnu.org>; Mon, 10 Apr 2023 05:07:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC3FF3858D3C Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1a52648fcddso425475ad.0 for <gcc-patches@gcc.gnu.org>; Sun, 09 Apr 2023 22:07:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681103237; x=1683695237; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fWV7W5AeWeSC5n4A+2pSI4GHv+j9Az1oHBwjMcd8sS8=; b=WkunhXLVj9ViJINxMFvwscif5GOaz8gkcHrwnFXBwuC+zCqr5VW6p75OpG+1OvWw04 auUOxezErv73yNFZz9J9mUZDA1OP2dk8NHhh+2De12SVz+8UgfPS+vcQmQShvALSTATE dzP22NhkDKXQmnJ0nD43vK+9hyDL2juiQXuK+GduHVBpSag72y9Ql6dHn91u7/8rJU7I 7oiJS5pqFJN9u2Z88LRu1J5nEpgKMD3iCdZDpVtqS59iMIVNHKAMvGNTqTjObPIn2r8/ D4dwMkvkYPFaH7UZbREnDsh4nmLywWWomvumN9ApaOA4CTWIjsSfiokuVMT0wQDcoht8 qU8Q== X-Gm-Message-State: AAQBX9ec73WU57ekPmdxWv6g78EdmPq/3tVyoVZBbO3Uj8mD+7D8yFPp A0nHnXUZzktxOg68B3JeEHC/MT+F7Nutz0W0HjbJHw== X-Received: by 2002:a05:6a20:440d:b0:d9:3de:541e with SMTP id ce13-20020a056a20440d00b000d903de541emr13297196pzb.6.1681103236896; Sun, 09 Apr 2023 22:07:16 -0700 (PDT) Received: from localhost.localdomain ([47.246.101.50]) by smtp.gmail.com with ESMTPSA id z24-20020a1709028f9800b0019aeddce6casm5115816plo.205.2023.04.09.22.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Apr 2023 22:07:16 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: philipp.tomsich@vrull.eu, kito.cheng@gmail.com, palmer@dabbelt.com, andrew@sifive.com, Sinan Lin <linsinan.lsn@linux.alibaba.com> Subject: [PATCH] RISC-V: avoid splitting small constant in <or_optab>i<mode>_extrabit pattern Date: Mon, 10 Apr 2023 13:07:01 +0800 Message-Id: <20230410050701.10254-1-mynameisxiaou@gmail.com> X-Mailer: git-send-email 2.36.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Lin Sinan via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Lin Sinan <mynameisxiaou@gmail.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762764557623873163?= X-GMAIL-MSGID: =?utf-8?q?1762764557623873163?= |
Series |
RISC-V: avoid splitting small constant in <or_optab>i<mode>_extrabit pattern
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Lin Sinan
April 10, 2023, 5:07 a.m. UTC
From: Sinan Lin <linsinan.lsn@linux.alibaba.com>
there is no need to split an xori/ori with an small constant. take the test
case `int foo(int idx) { return idx|3; }` as an example,
rv64im_zba generates:
ori a0,a0,3
ret
but, rv64im_zba_zbs generates:
ori a0,a0,1
ori a0,a0,2
ret
with this change, insn `ori r2,r1,3` will not be splitted in zbs.
---
gcc/config/riscv/predicates.md | 2 +-
.../gcc.target/riscv/zbs-extra-bit-or-twobits.c | 14 ++++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.target/riscv/zbs-extra-bit-or-twobits.c
Comments
On 4/9/23 23:07, Lin Sinan via Gcc-patches wrote: > From: Sinan Lin <linsinan.lsn@linux.alibaba.com> > > there is no need to split an xori/ori with an small constant. take the test > case `int foo(int idx) { return idx|3; }` as an example, > > rv64im_zba generates: > ori a0,a0,3 > ret > but, rv64im_zba_zbs generates: > ori a0,a0,1 > ori a0,a0,2 > ret > > with this change, insn `ori r2,r1,3` will not be splitted in zbs. > --- > gcc/config/riscv/predicates.md | 2 +- > .../gcc.target/riscv/zbs-extra-bit-or-twobits.c | 14 ++++++++++++++ > 2 files changed, 15 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.target/riscv/zbs-extra-bit-or-twobits.c A minor oversight in the VRULL patches in this space. This is actually a regression as we were previously generating the single [xo]ri. The patch looks fine, though it does need to go through a test cycle. jeff
On Mon, 10 Apr 2023 at 17:57, Jeff Law <jeffreyalaw@gmail.com> wrote: > > > > On 4/9/23 23:07, Lin Sinan via Gcc-patches wrote: > > From: Sinan Lin <linsinan.lsn@linux.alibaba.com> > > > > there is no need to split an xori/ori with an small constant. take the test > > case `int foo(int idx) { return idx|3; }` as an example, > > > > rv64im_zba generates: > > ori a0,a0,3 > > ret > > but, rv64im_zba_zbs generates: > > ori a0,a0,1 > > ori a0,a0,2 > > ret > > > > with this change, insn `ori r2,r1,3` will not be splitted in zbs. > > --- > > gcc/config/riscv/predicates.md | 2 +- > > .../gcc.target/riscv/zbs-extra-bit-or-twobits.c | 14 ++++++++++++++ > > 2 files changed, 15 insertions(+), 1 deletion(-) > > create mode 100644 gcc/testsuite/gcc.target/riscv/zbs-extra-bit-or-twobits.c > A minor oversight in the VRULL patches in this space. This is actually > a regression as we were previously generating the single [xo]ri. Thanks for catching this one! I looked this change over and it looks fine. I hope this is the last fallout from this set of changes. > > The patch looks fine, though it does need to go through a test cycle. > > jeff >
On 4/10/23 14:59, Philipp Tomsich wrote: > On Mon, 10 Apr 2023 at 17:57, Jeff Law <jeffreyalaw@gmail.com> wrote: >> >> >> >> On 4/9/23 23:07, Lin Sinan via Gcc-patches wrote: >>> From: Sinan Lin <linsinan.lsn@linux.alibaba.com> >>> >>> there is no need to split an xori/ori with an small constant. take the test >>> case `int foo(int idx) { return idx|3; }` as an example, >>> >>> rv64im_zba generates: >>> ori a0,a0,3 >>> ret >>> but, rv64im_zba_zbs generates: >>> ori a0,a0,1 >>> ori a0,a0,2 >>> ret >>> >>> with this change, insn `ori r2,r1,3` will not be splitted in zbs. >>> --- >>> gcc/config/riscv/predicates.md | 2 +- >>> .../gcc.target/riscv/zbs-extra-bit-or-twobits.c | 14 ++++++++++++++ >>> 2 files changed, 15 insertions(+), 1 deletion(-) >>> create mode 100644 gcc/testsuite/gcc.target/riscv/zbs-extra-bit-or-twobits.c >> A minor oversight in the VRULL patches in this space. This is actually >> a regression as we were previously generating the single [xo]ri. > > Thanks for catching this one! > > I looked this change over and it looks fine. I hope this is the last > fallout from this set of changes. Just for completeness, I bootstrapped and regression tested Sinan's change on rv64. Given it's a regression, I'm going to go ahead and commit it to the trunk momentarily. jeff
On 4/9/23 23:07, Lin Sinan via Gcc-patches wrote: > From: Sinan Lin <linsinan.lsn@linux.alibaba.com> > > there is no need to split an xori/ori with an small constant. take the test > case `int foo(int idx) { return idx|3; }` as an example, > > rv64im_zba generates: > ori a0,a0,3 > ret > but, rv64im_zba_zbs generates: > ori a0,a0,1 > ori a0,a0,2 > ret > > with this change, insn `ori r2,r1,3` will not be splitted in zbs. As noted, this was actually a regression. I've bootstrapped this change on rv64 with no regressions and pushed it to the trunk. Thanks! jeff
diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md index 0d9d7701c7e..8654dbc5943 100644 --- a/gcc/config/riscv/predicates.md +++ b/gcc/config/riscv/predicates.md @@ -399,7 +399,7 @@ (define_predicate "uimm_extra_bit_or_twobits" (and (match_code "const_int") (ior (match_operand 0 "uimm_extra_bit_operand") - (match_operand 0 "const_twobits_operand")))) + (match_operand 0 "const_twobits_not_arith_operand")))) ;; A CONST_INT operand that fits into the negative half of a ;; signed-immediate after a single cleared top bit has been diff --git a/gcc/testsuite/gcc.target/riscv/zbs-extra-bit-or-twobits.c b/gcc/testsuite/gcc.target/riscv/zbs-extra-bit-or-twobits.c new file mode 100644 index 00000000000..ef7ed60461a --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zbs-extra-bit-or-twobits.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gc_zbs -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" } } */ + +int or_two_bit(int idx) { + return idx|3; +} + +int xor_two_bit(int idx) { + return idx^3; +} + +/* { dg-final { scan-assembler-times "\tori\t" 1 } } */ +/* { dg-final { scan-assembler-times "\txori\t" 1 } } */