From 04ed822dcc21f18d80e974706599d201eb16e466 Mon Sep 17 00:00:00 2001 From: Jianjian GUAN Date: Fri, 16 Jun 2023 16:58:24 +0800 Subject: [PATCH] [RISCV] Match shl (ext v, splat 1) to vector widening add. Since we use match shl (v, splat 1) to vadd, we could also expand to widening add. Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D153112 --- llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td | 21 +++++++++++++++++++++ llvm/test/CodeGen/RISCV/rvv/mgather-sdnode.ll | 12 ++++-------- llvm/test/CodeGen/RISCV/rvv/mscatter-sdnode.ll | 12 ++++-------- llvm/test/CodeGen/RISCV/rvv/vpgather-sdnode.ll | 10 ++++------ llvm/test/CodeGen/RISCV/rvv/vpscatter-sdnode.ll | 10 ++++------ 5 files changed, 37 insertions(+), 28 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td index 58962e9..c03a4fa 100644 --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td @@ -733,6 +733,27 @@ defm : VPatWidenBinarySDNode_VV_VX_WV_WX; defm : VPatWidenBinarySDNode_VV_VX_WV_WX; defm : VPatWidenBinarySDNode_VV_VX_WV_WX; +// shl (ext v, splat 1) is a special case of widening add. +foreach vtiToWti = AllWidenableIntVectors in { + defvar vti = vtiToWti.Vti; + defvar wti = vtiToWti.Wti; + let Predicates = !listconcat(GetVTypePredicates.Predicates, + GetVTypePredicates.Predicates) in { + def : Pat<(shl (wti.Vector (sext_oneuse (vti.Vector vti.RegClass:$rs1))), + (wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), 1, (XLenVT srcvalue)))), + (!cast("PseudoVWADD_VV_"#vti.LMul.MX) + vti.RegClass:$rs1, vti.RegClass:$rs1, vti.AVL, vti.Log2SEW)>; + def : Pat<(shl (wti.Vector (zext_oneuse (vti.Vector vti.RegClass:$rs1))), + (wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), 1, (XLenVT srcvalue)))), + (!cast("PseudoVWADDU_VV_"#vti.LMul.MX) + vti.RegClass:$rs1, vti.RegClass:$rs1, vti.AVL, vti.Log2SEW)>; + def : Pat<(shl (wti.Vector (anyext_oneuse (vti.Vector vti.RegClass:$rs1))), + (wti.Vector (riscv_vmv_v_x_vl (wti.Vector undef), 1, (XLenVT srcvalue)))), + (!cast("PseudoVWADDU_VV_"#vti.LMul.MX) + vti.RegClass:$rs1, vti.RegClass:$rs1, vti.AVL, vti.Log2SEW)>; + } +} + // 11.3. Vector Integer Extension defm : VPatExtendSDNode_V<[zext, anyext], "PseudoVZEXT", "VF2", AllFractionableVF2IntVectors>; diff --git a/llvm/test/CodeGen/RISCV/rvv/mgather-sdnode.ll b/llvm/test/CodeGen/RISCV/rvv/mgather-sdnode.ll index 16d79db..d6ec784 100644 --- a/llvm/test/CodeGen/RISCV/rvv/mgather-sdnode.ll +++ b/llvm/test/CodeGen/RISCV/rvv/mgather-sdnode.ll @@ -549,10 +549,8 @@ define @mgather_baseidx_zext_nxv8i8_nxv8i16(ptr %base, @mgather_baseidx_nxv8i16(ptr %base, %idxs, %m, %passthru) { ; RV32-LABEL: mgather_baseidx_nxv8i16: ; RV32: # %bb.0: -; RV32-NEXT: vsetvli a1, zero, e32, m4, ta, ma -; RV32-NEXT: vsext.vf2 v12, v8 -; RV32-NEXT: vadd.vv v12, v12, v12 -; RV32-NEXT: vsetvli zero, zero, e16, m2, ta, mu +; RV32-NEXT: vsetvli a1, zero, e16, m2, ta, mu +; RV32-NEXT: vwadd.vv v12, v8, v8 ; RV32-NEXT: vluxei32.v v10, (a0), v12, v0.t ; RV32-NEXT: vmv.v.v v8, v10 ; RV32-NEXT: ret @@ -1510,10 +1508,8 @@ define @mgather_baseidx_zext_nxv8i8_nxv8f16(ptr %base, @mgather_baseidx_nxv8f16(ptr %base, %idxs, %m, %passthru) { ; RV32-LABEL: mgather_baseidx_nxv8f16: ; RV32: # %bb.0: -; RV32-NEXT: vsetvli a1, zero, e32, m4, ta, ma -; RV32-NEXT: vsext.vf2 v12, v8 -; RV32-NEXT: vadd.vv v12, v12, v12 -; RV32-NEXT: vsetvli zero, zero, e16, m2, ta, mu +; RV32-NEXT: vsetvli a1, zero, e16, m2, ta, mu +; RV32-NEXT: vwadd.vv v12, v8, v8 ; RV32-NEXT: vluxei32.v v10, (a0), v12, v0.t ; RV32-NEXT: vmv.v.v v8, v10 ; RV32-NEXT: ret diff --git a/llvm/test/CodeGen/RISCV/rvv/mscatter-sdnode.ll b/llvm/test/CodeGen/RISCV/rvv/mscatter-sdnode.ll index e92bf5d..65588d5 100644 --- a/llvm/test/CodeGen/RISCV/rvv/mscatter-sdnode.ll +++ b/llvm/test/CodeGen/RISCV/rvv/mscatter-sdnode.ll @@ -406,10 +406,8 @@ define void @mscatter_baseidx_zext_nxv8i8_nxv8i16( %val, ptr % define void @mscatter_baseidx_nxv8i16( %val, ptr %base, %idxs, %m) { ; RV32-LABEL: mscatter_baseidx_nxv8i16: ; RV32: # %bb.0: -; RV32-NEXT: vsetvli a1, zero, e32, m4, ta, ma -; RV32-NEXT: vsext.vf2 v12, v10 -; RV32-NEXT: vadd.vv v12, v12, v12 -; RV32-NEXT: vsetvli zero, zero, e16, m2, ta, ma +; RV32-NEXT: vsetvli a1, zero, e16, m2, ta, ma +; RV32-NEXT: vwadd.vv v12, v10, v10 ; RV32-NEXT: vsoxei32.v v8, (a0), v12, v0.t ; RV32-NEXT: ret ; @@ -1192,10 +1190,8 @@ define void @mscatter_baseidx_zext_nxv8i8_nxv8f16( %val, ptr define void @mscatter_baseidx_nxv8f16( %val, ptr %base, %idxs, %m) { ; RV32-LABEL: mscatter_baseidx_nxv8f16: ; RV32: # %bb.0: -; RV32-NEXT: vsetvli a1, zero, e32, m4, ta, ma -; RV32-NEXT: vsext.vf2 v12, v10 -; RV32-NEXT: vadd.vv v12, v12, v12 -; RV32-NEXT: vsetvli zero, zero, e16, m2, ta, ma +; RV32-NEXT: vsetvli a1, zero, e16, m2, ta, ma +; RV32-NEXT: vwadd.vv v12, v10, v10 ; RV32-NEXT: vsoxei32.v v8, (a0), v12, v0.t ; RV32-NEXT: ret ; diff --git a/llvm/test/CodeGen/RISCV/rvv/vpgather-sdnode.ll b/llvm/test/CodeGen/RISCV/rvv/vpgather-sdnode.ll index aa8850f..1f37ddc 100644 --- a/llvm/test/CodeGen/RISCV/rvv/vpgather-sdnode.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vpgather-sdnode.ll @@ -601,9 +601,8 @@ define @vpgather_baseidx_zext_nxv8i8_nxv8i16(ptr %base, @vpgather_baseidx_nxv8i16(ptr %base, %idxs, %m, i32 zeroext %evl) { ; RV32-LABEL: vpgather_baseidx_nxv8i16: ; RV32: # %bb.0: -; RV32-NEXT: vsetvli a2, zero, e32, m4, ta, ma -; RV32-NEXT: vsext.vf2 v12, v8 -; RV32-NEXT: vadd.vv v12, v12, v12 +; RV32-NEXT: vsetvli a2, zero, e16, m2, ta, ma +; RV32-NEXT: vwadd.vv v12, v8, v8 ; RV32-NEXT: vsetvli zero, a1, e16, m2, ta, ma ; RV32-NEXT: vluxei32.v v8, (a0), v12, v0.t ; RV32-NEXT: ret @@ -1423,9 +1422,8 @@ define @vpgather_baseidx_zext_nxv8i8_nxv8f16(ptr %base, @vpgather_baseidx_nxv8f16(ptr %base, %idxs, %m, i32 zeroext %evl) { ; RV32-LABEL: vpgather_baseidx_nxv8f16: ; RV32: # %bb.0: -; RV32-NEXT: vsetvli a2, zero, e32, m4, ta, ma -; RV32-NEXT: vsext.vf2 v12, v8 -; RV32-NEXT: vadd.vv v12, v12, v12 +; RV32-NEXT: vsetvli a2, zero, e16, m2, ta, ma +; RV32-NEXT: vwadd.vv v12, v8, v8 ; RV32-NEXT: vsetvli zero, a1, e16, m2, ta, ma ; RV32-NEXT: vluxei32.v v8, (a0), v12, v0.t ; RV32-NEXT: ret diff --git a/llvm/test/CodeGen/RISCV/rvv/vpscatter-sdnode.ll b/llvm/test/CodeGen/RISCV/rvv/vpscatter-sdnode.ll index 0ef217f..208fef3 100644 --- a/llvm/test/CodeGen/RISCV/rvv/vpscatter-sdnode.ll +++ b/llvm/test/CodeGen/RISCV/rvv/vpscatter-sdnode.ll @@ -400,9 +400,8 @@ define void @vpscatter_baseidx_zext_nxv8i8_nxv8i16( %val, ptr define void @vpscatter_baseidx_nxv8i16( %val, ptr %base, %idxs, %m, i32 zeroext %evl) { ; RV32-LABEL: vpscatter_baseidx_nxv8i16: ; RV32: # %bb.0: -; RV32-NEXT: vsetvli a2, zero, e32, m4, ta, ma -; RV32-NEXT: vsext.vf2 v12, v10 -; RV32-NEXT: vadd.vv v12, v12, v12 +; RV32-NEXT: vsetvli a2, zero, e16, m2, ta, ma +; RV32-NEXT: vwadd.vv v12, v10, v10 ; RV32-NEXT: vsetvli zero, a1, e16, m2, ta, ma ; RV32-NEXT: vsoxei32.v v8, (a0), v12, v0.t ; RV32-NEXT: ret @@ -1181,9 +1180,8 @@ define void @vpscatter_baseidx_zext_nxv8i8_nxv8f16( %val, ptr define void @vpscatter_baseidx_nxv8f16( %val, ptr %base, %idxs, %m, i32 zeroext %evl) { ; RV32-LABEL: vpscatter_baseidx_nxv8f16: ; RV32: # %bb.0: -; RV32-NEXT: vsetvli a2, zero, e32, m4, ta, ma -; RV32-NEXT: vsext.vf2 v12, v10 -; RV32-NEXT: vadd.vv v12, v12, v12 +; RV32-NEXT: vsetvli a2, zero, e16, m2, ta, ma +; RV32-NEXT: vwadd.vv v12, v10, v10 ; RV32-NEXT: vsetvli zero, a1, e16, m2, ta, ma ; RV32-NEXT: vsoxei32.v v8, (a0), v12, v0.t ; RV32-NEXT: ret -- 2.7.4