From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by sourceware.org (Postfix) with ESMTPS id E7DBF3858D28 for ; Thu, 4 May 2023 08:35:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E7DBF3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683189344; x=1714725344; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Gn5VNl3hdYuazaVMpYUPRdDLyOdG/XxjyGU1vZ2mCVs=; b=RA+TdTHkp9Jhs91OVfhJZCpIPYw/YZpKhOoy0KvW/n3RHJvT6FJJY5Hl PDE+ZPVfBK02GI48ZT7w/xDbb1b9fWLxfH3R2COglBfmBuLxpEkzGHspT nFTynV+vzrmx1+4rHcz2kQLDNhFiyqYKQba14tosUbrDD4mxPBpIhj3ft 89JVv9gaI8i3+FLf3mtNEsTWZToZsS4C7/6rke4UIF2t9+QzmD2J5tjAk 3khv4A9l8NxhEE5eBHMz3z9D/HOI//rAotvFqW1VslbtDd37NgyyVPkSX 6Zd+ipDE9phyDFpIpRoHbuORtDtg1dvWhs5UELx57mw2XUDkNb8M/aYOV w==; X-IronPort-AV: E=McAfee;i="6600,9927,10699"; a="333242217" X-IronPort-AV: E=Sophos;i="5.99,249,1677571200"; d="scan'208";a="333242217" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2023 01:35:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10699"; a="1026834054" X-IronPort-AV: E=Sophos;i="5.99,249,1677571200"; d="scan'208";a="1026834054" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga005.fm.intel.com with ESMTP; 04 May 2023 01:35:40 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail03.sh.intel.com (Postfix) with ESMTP id BA8791005699; Thu, 4 May 2023 16:35:39 +0800 (CST) From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@sifive.com, pan2.li@intel.com, yanzhang.wang@intel.com Subject: [PATCH] RISC-V: Legitimise the const0_rtx for RVV indexed load/store Date: Thu, 4 May 2023 16:35:37 +0800 Message-Id: <20230504083537.2719788-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,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 List-Id: From: Pan Li This patch try to legitimise the const0_rtx (aka zero register) as the base register for the RVV indexed load/store instructions by allowing the const as the operand of the indexed RTL pattern. Then the underlying combine pass will try to perform the const propagation. For example: vint32m1_t test_vluxei32_v_i32m1_shortcut (vuint32m1_t bindex, size_t vl) { return __riscv_vluxei32_v_i32m1 ((int32_t *)0, bindex, vl); } Before this patch: li a5,0 <- can be eliminated. vl1re32.v v1,0(a1) vsetvli zero,a2,e32,m1,ta,ma vluxei32.v v1,(a5),v1 <- can propagate the const 0 to a5 here. vs1r.v v1,0(a0) ret After this patch: test_vluxei32_v_i32m1_shortcut: vl1re32.v v1,0(a1) vsetvli zero,a2,e32,m1,ta,ma vluxei32.v v1,(0),v1 vs1r.v v1,0(a0) ret As above, this patch allow you to propagaate the const 0 (aka zero register) to the base register of the RVV indexed load in the combine pass. This may benefit the underlying RVV auto-vectorization. Signed-off-by: Pan Li Co-authored-by: Ju-Zhe Zhong gcc/ChangeLog: * config/riscv/vector.md: Allow const as the operand of RVV indexed load/store. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/zero_base_load_store_optimization.c: Adjust indexed load/store check condition. --- gcc/config/riscv/vector.md | 32 +++++++++---------- .../base/zero_base_load_store_optimization.c | 3 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md index 92115e3935f..c3210eacd47 100644 --- a/gcc/config/riscv/vector.md +++ b/gcc/config/riscv/vector.md @@ -1511,7 +1511,7 @@ (define_insn "@pred_indexed_load_same_eew" (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) (unspec:V - [(match_operand 3 "pmode_register_operand" " r, r, r, r") + [(match_operand 3 "pmode_reg_or_0_operand" " rJ, rJ,rJ, rJ") (mem:BLK (scratch)) (match_operand: 4 "register_operand" " vr, vr,vr, vr")] ORDER) (match_operand:V 2 "vector_merge_operand" " vu, vu, 0, 0")))] @@ -1533,7 +1533,7 @@ (define_insn "@pred_indexed_load_x2_greater_eew" (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) (unspec:VEEWEXT2 - [(match_operand 3 "pmode_register_operand" " r, r") + [(match_operand 3 "pmode_reg_or_0_operand" " rJ, rJ") (mem:BLK (scratch)) (match_operand: 4 "register_operand" " vr, vr")] ORDER) (match_operand:VEEWEXT2 2 "vector_merge_operand" " vu, 0")))] @@ -1554,7 +1554,7 @@ (define_insn "@pred_indexed_load_x4_greater_eew" (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) (unspec:VEEWEXT4 - [(match_operand 3 "pmode_register_operand" " r, r") + [(match_operand 3 "pmode_reg_or_0_operand" " rJ, rJ") (mem:BLK (scratch)) (match_operand: 4 "register_operand" " vr, vr")] ORDER) (match_operand:VEEWEXT4 2 "vector_merge_operand" " vu, 0")))] @@ -1575,7 +1575,7 @@ (define_insn "@pred_indexed_load_x8_greater_eew" (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) (unspec:VEEWEXT8 - [(match_operand 3 "pmode_register_operand" " r, r") + [(match_operand 3 "pmode_reg_or_0_operand" " rJ, rJ") (mem:BLK (scratch)) (match_operand: 4 "register_operand" " vr, vr")] ORDER) (match_operand:VEEWEXT8 2 "vector_merge_operand" " vu, 0")))] @@ -1597,7 +1597,7 @@ (define_insn "@pred_indexed_load_x2_smaller_eew" (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) (unspec:VEEWTRUNC2 - [(match_operand 3 "pmode_register_operand" " r, r, r, r, r, r") + [(match_operand 3 "pmode_reg_or_0_operand" " rJ, rJ, rJ, rJ, rJ, rJ") (mem:BLK (scratch)) (match_operand: 4 "register_operand" " 0, 0, 0, 0, vr, vr")] ORDER) (match_operand:VEEWTRUNC2 2 "vector_merge_operand" " vu, 0, vu, 0, vu, 0")))] @@ -1618,7 +1618,7 @@ (define_insn "@pred_indexed_load_x4_smaller_eew" (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) (unspec:VEEWTRUNC4 - [(match_operand 3 "pmode_register_operand" " r, r, r, r, r, r") + [(match_operand 3 "pmode_reg_or_0_operand" " rJ, rJ, rJ, rJ, rJ, rJ") (mem:BLK (scratch)) (match_operand: 4 "register_operand" " 0, 0, 0, 0, vr, vr")] ORDER) (match_operand:VEEWTRUNC4 2 "vector_merge_operand" " vu, 0, vu, 0, vu, 0")))] @@ -1639,7 +1639,7 @@ (define_insn "@pred_indexed_load_x8_smaller_eew" (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) (unspec:VEEWTRUNC8 - [(match_operand 3 "pmode_register_operand" " r, r, r, r, r, r") + [(match_operand 3 "pmode_reg_or_0_operand" " rJ, rJ, rJ, rJ, rJ, rJ") (mem:BLK (scratch)) (match_operand: 4 "register_operand" " 0, 0, 0, 0, vr, vr")] ORDER) (match_operand:VEEWTRUNC8 2 "vector_merge_operand" " vu, 0, vu, 0, vu, 0")))] @@ -1657,7 +1657,7 @@ (define_insn "@pred_indexed_store" (match_operand 5 "const_int_operand" " i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (match_operand 1 "pmode_register_operand" " r") + (match_operand 1 "pmode_reg_or_0_operand" " rJ") (match_operand:VNX1_QHSDI 2 "register_operand" " vr") (match_operand:VNX1_QHSD 3 "register_operand" " vr")] ORDER))] "TARGET_VECTOR" @@ -1674,7 +1674,7 @@ (define_insn "@pred_indexed_store" (match_operand 5 "const_int_operand" " i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (match_operand 1 "pmode_register_operand" " r") + (match_operand 1 "pmode_reg_or_0_operand" " rJ") (match_operand:VNX2_QHSDI 2 "register_operand" " vr") (match_operand:VNX2_QHSD 3 "register_operand" " vr")] ORDER))] "TARGET_VECTOR" @@ -1691,7 +1691,7 @@ (define_insn "@pred_indexed_store" (match_operand 5 "const_int_operand" " i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (match_operand 1 "pmode_register_operand" " r") + (match_operand 1 "pmode_reg_or_0_operand" " rJ") (match_operand:VNX4_QHSDI 2 "register_operand" " vr") (match_operand:VNX4_QHSD 3 "register_operand" " vr")] ORDER))] "TARGET_VECTOR" @@ -1708,7 +1708,7 @@ (define_insn "@pred_indexed_store" (match_operand 5 "const_int_operand" " i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (match_operand 1 "pmode_register_operand" " r") + (match_operand 1 "pmode_reg_or_0_operand" " rJ") (match_operand:VNX8_QHSDI 2 "register_operand" " vr") (match_operand:VNX8_QHSD 3 "register_operand" " vr")] ORDER))] "TARGET_VECTOR" @@ -1725,7 +1725,7 @@ (define_insn "@pred_indexed_store" (match_operand 5 "const_int_operand" " i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (match_operand 1 "pmode_register_operand" " r") + (match_operand 1 "pmode_reg_or_0_operand" " rJ") (match_operand:VNX16_QHSI 2 "register_operand" " vr") (match_operand:VNX16_QHS 3 "register_operand" " vr")] ORDER))] "TARGET_VECTOR" @@ -1742,7 +1742,7 @@ (define_insn "@pred_indexed_store" (match_operand 5 "const_int_operand" " i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (match_operand 1 "pmode_register_operand" " r") + (match_operand 1 "pmode_reg_or_0_operand" " rJ") (match_operand:VNX32_QHSI 2 "register_operand" " vr") (match_operand:VNX32_QHS 3 "register_operand" " vr")] ORDER))] "TARGET_VECTOR" @@ -1759,8 +1759,8 @@ (define_insn "@pred_indexed_store" (match_operand 5 "const_int_operand" " i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (match_operand 1 "pmode_register_operand" " r") - (match_operand:VNX64_QHI 2 "register_operand" " vr") + (match_operand 1 "pmode_reg_or_0_operand" " rJ") + (match_operand:VNX64_QHI 2 "register_operand" " vr") (match_operand:VNX64_QH 3 "register_operand" " vr")] ORDER))] "TARGET_VECTOR" "vsxei.v\t%3,(%1),%2%p0" @@ -1776,7 +1776,7 @@ (define_insn "@pred_indexed_store" (match_operand 5 "const_int_operand" " i") (reg:SI VL_REGNUM) (reg:SI VTYPE_REGNUM)] UNSPEC_VPREDICATE) - (match_operand 1 "pmode_register_operand" " r") + (match_operand 1 "pmode_reg_or_0_operand" " rJ") (match_operand:VNX128_Q 2 "register_operand" " vr") (match_operand:VNX128_Q 3 "register_operand" " vr")] ORDER))] "TARGET_VECTOR" 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 index 9f323b0ba9c..38f39647687 100644 --- 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 @@ -131,4 +131,5 @@ void test_vsoxei32_v_f32m1_shortcut (vuint32m1_t bindex, vfloat32m1_t val, size_ /* { 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 } } */ +/* { dg-final { scan-assembler-times {v[ls][uo]xei[0-9]+\.v\s+v[0-9]+,\s*\(0\),\s*v[0-9]+} 12 } } */ +/* { dg-final { scan-assembler-not {li\s+[a-x][0-9]+,\s*0} } } */ -- 2.34.1