From patchwork Wed Apr 26 12:00:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 87839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp185442vqo; Wed, 26 Apr 2023 05:01:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5+4dgxxnXyOk8M13YBKAEkfY46hbwTvxesjjDdK4BDf7gdXOp6IBlrvs03iFZS/PYOE3X3 X-Received: by 2002:a17:906:9c86:b0:95f:4889:412a with SMTP id fj6-20020a1709069c8600b0095f4889412amr1265307ejc.33.1682510507736; Wed, 26 Apr 2023 05:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682510507; cv=none; d=google.com; s=arc-20160816; b=HHwg78LbLFxUicckHR84q1fzKnuKHJUpqJ3WD1JCJBcFJnPg90HZXB7CsPhdUvdhGo 0WdPsc9kRwX+S10NxwQNLcGK37PyIjF9td/8PJAsgxb7B6AIwsE8XeUQfVixmfhWwxOc O2ZnczAxlguyDUmeWBlRsoy+T4g/61iiCEgB7wrnd94EoaqKAVmB2Oyn2JpNjPVp49xh s5dZbnzWOsFS5jg13+FkcMwWaBboYuR4PRdI9bqRpOfF+Sr4Feht0w9l8jlTNuYMOIEA RWWBxR3fFlTC+h+8EtdRnNC5ZNBZZkWPpe7CEtXQ15Ub3OYjc47x+QFLqhxe/bN59B/k bdSQ== 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=5KWJ89A/jqQtIcDBG3S0PTte/uuEP/reLosm1xQmlE0=; b=eY6SHCt7mBh6+INTs1YPf/dcF2wcV+k71bz0iv7vfSKPWFDHoJrDTgKOZTWwDCCaRZ b1qRRB9T4ELRZDlg7ufpXhJj8sYM7g7rUBttchPCh3ki63u8+14sIJ7icmIn3/uqiT3/ e1clWWW1BsAw5bmkypdK57dJ/WwrM9w2Uz4i44FT6teJmb8ejsy+17Dds7uj8k7fjEMo d0a24tjfHu4UnVQ1tKb8GshNlFqcWG1No7JdIDjd7rMjrT3nghVRtwElhc9+eon22a9k AlM8S+AXyidVGbIO6mie5qBRng8kEurbUvUqqhjrM0D11GEQU+0pAC3m9XUfJtD5FUtJ WMYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="CSMHLV/b"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id q21-20020aa7da95000000b005089ebf6cb7si10280789eds.252.2023.04.26.05.01.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 05:01:47 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="CSMHLV/b"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 207B23856DC2 for ; Wed, 26 Apr 2023 12:01:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 207B23856DC2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682510460; bh=5KWJ89A/jqQtIcDBG3S0PTte/uuEP/reLosm1xQmlE0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=CSMHLV/bhikuoGCbeh4Z43748tHzLFJ+y9tuxh0pC6WAZ6nBzb90Y/62XbIvBK3Wd Dp75tZcjwgT+wdfgct4ZNB8cRgIoZu9n/BxXyoRh2RXAHTCP1Vs51IH9Vqs4ch1Asw nuNQJ7KYn7IUFEEw2RhXP3tvr4jfnUwMUjvraDpM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by sourceware.org (Postfix) with ESMTPS id 73F02385701A for ; Wed, 26 Apr 2023 12:00:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73F02385701A X-IronPort-AV: E=McAfee;i="6600,9927,10691"; a="375037781" X-IronPort-AV: E=Sophos;i="5.99,228,1677571200"; d="scan'208";a="375037781" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2023 05:00:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10691"; a="644221185" X-IronPort-AV: E=Sophos;i="5.99,228,1677571200"; d="scan'208";a="644221185" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by orsmga003.jf.intel.com with ESMTP; 26 Apr 2023 05:00:09 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail02.sh.intel.com (Postfix) with ESMTP id DF5291005676; Wed, 26 Apr 2023 20:00:08 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@sifive.com, yanzhang.wang@intel.com, Pan Li Subject: [PATCH] RISC-V: Legitimise the const0_rtx for RVV load/store address Date: Wed, 26 Apr 2023 20:00:06 +0800 Message-Id: <20230426120006.2362465-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: Pan Li via Gcc-patches From: "Li, Pan2" Reply-To: pan2.li@intel.com 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?1764240137940960439?= X-GMAIL-MSGID: =?utf-8?q?1764240137940960439?= From: Pan Li This patch try to legitimise the const0_rtx (aka zero register) as the base register for the RVV load/store instructions. For example: vint32m1_t test_vle32_v_i32m1_shortcut (size_t vl) { return __riscv_vle32_v_i32m1 ((int32_t *)0, vl); } Before this patch: li a5,0 vsetvli zero,a1,e32,m1,ta,ma vle32.v v24,0(a5) <- can propagate the const 0 to a5 here vs1r.v v24,0(a0) After this patch: vsetvli zero,a1,e32,m1,ta,ma vle32.v v24,0(zero) vs1r.v v24,0(a0) As above, this patch allow you to propagaate the const 0 (aka zero register) to the base register of the RVV Unit-Stride load in the combine pass. This may benefit the underlying RVV auto-vectorization. However, the indexed load failed to perform the optimization and it will be token care of in another PATCH. gcc/ChangeLog: * config/riscv/riscv.cc (riscv_classify_address): Allow const0_rtx for the RVV load/store. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/zero_base_load_store_optimization.c: New test. Signed-off-by: Pan Li Co-authored-by: Ju-Zhe Zhong --- gcc/config/riscv/riscv.cc | 17 ++- .../base/zero_base_load_store_optimization.c | 135 ++++++++++++++++++ 2 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/zero_base_load_store_optimization.c diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index ac8e4420896..a2d2dd0bb67 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -1088,9 +1088,22 @@ riscv_classify_address (struct riscv_address_info *info, rtx x, && riscv_valid_lo_sum_p (info->symbol_type, mode, info->offset)); case CONST_INT: - /* RVV load/store disallow CONST_INT. */ + /* We only allow the const0_rtx for the RVV load/store. For example: + +----------------------------------------------------------+ + | li a5,0 | + | vsetvli zero,a1,e32,m1,ta,ma | + | vle32.v v24,0(a5) <- propagate the const 0 to a5 here. | + | vs1r.v v24,0(a0) | + +----------------------------------------------------------+ + It can be folded to: + +----------------------------------------------------------+ + | vsetvli zero,a1,e32,m1,ta,ma | + | vle32.v v24,0(zero) | + | vs1r.v v24,0(a0) | + +----------------------------------------------------------+ + This behavior will benefit the underlying RVV auto vectorization. */ if (riscv_v_ext_vector_mode_p (mode)) - return false; + return x == const0_rtx; /* Small-integer addresses don't occur very often, but they are legitimate if x0 is a valid base register. */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/zero_base_load_store_optimization.c b/gcc/testsuite/gcc.target/riscv/rvv/base/zero_base_load_store_optimization.c new file mode 100644 index 00000000000..4b30d3505c5 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/zero_base_load_store_optimization.c @@ -0,0 +1,135 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv -mabi=lp64 -O3" } */ + +// #include +#include "riscv_vector.h" + +#define float32_t float + +// Unit-Stride Load/Store +vint32m1_t test_vle32_v_i32m1_shortcut (size_t vl) +{ + return __riscv_vle32_v_i32m1 ((int32_t *)0, vl); +} + +vuint32m1_t test_vle32_v_u32m1_shortcut (size_t vl) +{ + return __riscv_vle32_v_u32m1 ((int32_t *)0, vl); +} + +vfloat32m1_t test_vle32_v_f32m1_shortcut (size_t vl) +{ + return __riscv_vle32_v_f32m1 ((float32_t *)0, vl); +} + +void test_vse32_v_i32m1_shortcut (vint32m1_t val, size_t vl) +{ + __riscv_vse32_v_i32m1 ((int32_t *)0, val, vl); +} + +void test_vse32_v_u32m1_shortcut (vuint32m1_t val, size_t vl) +{ + __riscv_vse32_v_u32m1 ((uint32_t *)0, val, vl); +} + +void test_vse32_v_f32m1_shortcut (vfloat32m1_t val, size_t vl) +{ + __riscv_vse32_v_f32m1 ((float32_t *)0, val, vl); +} + +// Stride Load/Store +vint32m1_t test_vlse32_v_i32m1_shortcut (ptrdiff_t bstride, size_t vl) +{ + return __riscv_vlse32_v_i32m1 ((int32_t *)0, bstride, vl); +} + +vuint32m1_t test_vlse32_v_u32m1_shortcut (ptrdiff_t bstride, size_t vl) +{ + return __riscv_vlse32_v_u32m1 ((uint32_t *)0, bstride, vl); +} + +vfloat32m1_t test_vlse32_v_f32m1_shortcut (ptrdiff_t bstride, size_t vl) +{ + return __riscv_vlse32_v_f32m1 ((float32_t *)0, bstride, vl); +} + +void test_vsse32_v_i32m1_shortcut (ptrdiff_t bstride, vint32m1_t val, size_t vl) +{ + __riscv_vsse32_v_i32m1 ((int32_t *)0, bstride, val, vl); +} + +void test_vsse32_v_u32m1_shortcut (ptrdiff_t bstride, vuint32m1_t val, size_t vl) +{ + __riscv_vsse32_v_u32m1 ((uint32_t *)0, bstride, val, vl); +} + +void test_vsse32_v_f32m1_shortcut (ptrdiff_t bstride, vfloat32m1_t val,size_t vl) +{ + __riscv_vsse32_v_f32m1 ((float32_t *)0, bstride, val, vl); +} + +// Indexed-Unordered Load/Store +vint32m1_t test_vluxei32_v_i32m1_shortcut (vuint32m1_t bindex, size_t vl) +{ + return __riscv_vluxei32_v_i32m1 ((int32_t *)0, bindex, vl); +} + +vuint32m1_t test_vluxei32_v_u32m1_shortcut (vuint32m1_t bindex, size_t vl) +{ + return __riscv_vluxei32_v_u32m1 ((uint32_t *)0, bindex, vl); +} + +vfloat32m1_t test_vluxei32_v_f32m1_shortcut (vuint32m1_t bindex, size_t vl) +{ + return __riscv_vluxei32_v_f32m1 ((float32_t *)0, bindex, vl); +} + +void test_vsuxei32_v_i32m1_shortcut (vuint32m1_t bindex, vint32m1_t val, size_t vl) +{ + __riscv_vsuxei32_v_i32m1 ((int32_t *)0, bindex, val, vl); +} + +void test_vsuxei32_v_u32m1_shortcut (vuint32m1_t bindex, vuint32m1_t val, size_t vl) +{ + __riscv_vsuxei32_v_u32m1 ((uint32_t *)0, bindex, val, vl); +} + +void test_vsuxei32_v_f32m1_shortcut (vuint32m1_t bindex, vfloat32m1_t val, size_t vl) +{ + __riscv_vsuxei32_v_f32m1 ((float32_t *)0, bindex, val, vl); +} + +// Indexed-Ordered Load/Store +vint32m1_t test_vloxei32_v_i32m1_shortcut (vuint32m1_t bindex, size_t vl) +{ + return __riscv_vloxei32_v_i32m1 ((int32_t *)0, bindex, vl); +} + +vuint32m1_t test_vloxei32_v_u32m1_shortcut (vuint32m1_t bindex, size_t vl) +{ + return __riscv_vloxei32_v_u32m1 ((uint32_t *)0, bindex, vl); +} + +vfloat32m1_t test_vloxei32_v_f32m1_shortcut (vuint32m1_t bindex, size_t vl) +{ + return __riscv_vloxei32_v_f32m1 ((float32_t *)0, bindex, vl); +} + +void test_vsoxei32_v_i32m1_shortcut (vuint32m1_t bindex, vint32m1_t val, size_t vl) +{ + __riscv_vsoxei32_v_i32m1 ((int32_t *)0, bindex, val, vl); +} + +void test_vsoxei32_v_u32m1_shortcut (vuint32m1_t bindex, vuint32m1_t val, size_t vl) +{ + __riscv_vsoxei32_v_u32m1 ((uint32_t *)0, bindex, val, vl); +} + +void test_vsoxei32_v_f32m1_shortcut (vuint32m1_t bindex, vfloat32m1_t val, size_t vl) +{ + __riscv_vsoxei32_v_f32m1 ((float32_t *)0, bindex, val, vl); +} + +/* { dg-final { scan-assembler-times {v[ls]e[0-9]+\.v\s+v[0-9]+,\s*0\(zero\)} 6 } } */ +/* { dg-final { scan-assembler-times {v[ls]se[0-9]+\.v\s+v[0-9]+,\s*0\(zero\),\s*[ax][0-9]+} 6 } } */ +/* { dg-final { scan-assembler-times {li\s+[a-x][0-9]+,\s*0} 12 } } */