diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td @@ -1034,6 +1034,18 @@ return false; }]>; +def sext_oneuse : PatFrag<(ops node:$A), (sext node:$A), [{ + return N->hasOneUse(); +}]>; + +def zext_oneuse : PatFrag<(ops node:$A), (zext node:$A), [{ + return N->hasOneUse(); +}]>; + +def anyext_oneuse : PatFrag<(ops node:$A), (anyext node:$A), [{ + return N->hasOneUse(); +}]>; + /// Simple arithmetic operations def : PatGprGpr; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td @@ -363,6 +363,31 @@ } } +multiclass VPatWidenBinarySDNode_VV_VX_WV_WX { + foreach vti = AllWidenableIntVectors in { + def : Pat<(op (vti.Wti.Vector (extop (vti.Vti.Vector vti.Vti.RegClass:$rs2))), + (vti.Wti.Vector (extop (vti.Vti.Vector vti.Vti.RegClass:$rs1)))), + (!cast(instruction_name#"_VV_"#vti.Vti.LMul.MX) + vti.Vti.RegClass:$rs2, vti.Vti.RegClass:$rs1, + vti.Vti.AVL, vti.Vti.Log2SEW)>; + def : Pat<(op (vti.Wti.Vector (extop (vti.Vti.Vector vti.Vti.RegClass:$rs2))), + (vti.Wti.Vector (extop (vti.Vti.Vector (SplatPat GPR:$rs1))))), + (!cast(instruction_name#"_VX_"#vti.Vti.LMul.MX) + vti.Vti.RegClass:$rs2, GPR:$rs1, + vti.Vti.AVL, vti.Vti.Log2SEW)>; + def : Pat<(op (vti.Wti.Vector vti.Wti.RegClass:$rs2), + (vti.Wti.Vector (extop (vti.Vti.Vector vti.Vti.RegClass:$rs1)))), + (!cast(instruction_name#"_WV_"#vti.Vti.LMul.MX) + vti.Wti.RegClass:$rs2, vti.Vti.RegClass:$rs1, + vti.Vti.AVL, vti.Vti.Log2SEW)>; + def : Pat<(op (vti.Wti.Vector vti.Wti.RegClass:$rs2), + (vti.Wti.Vector (extop (vti.Vti.Vector (SplatPat GPR:$rs1))))), + (!cast(instruction_name#"_WX_"#vti.Vti.LMul.MX) + vti.Wti.RegClass:$rs2, GPR:$rs1, + vti.Vti.AVL, vti.Vti.Log2SEW)>; + } +} + //===----------------------------------------------------------------------===// // Patterns. //===----------------------------------------------------------------------===// @@ -399,6 +424,15 @@ vti.RegClass:$rs1, simm5:$rs2, vti.AVL, vti.Log2SEW)>; } +// 12.2. Vector Widening Integer Add and Subtract +defm : VPatWidenBinarySDNode_VV_VX_WV_WX; +defm : VPatWidenBinarySDNode_VV_VX_WV_WX; +defm : VPatWidenBinarySDNode_VV_VX_WV_WX; + +defm : VPatWidenBinarySDNode_VV_VX_WV_WX; +defm : VPatWidenBinarySDNode_VV_VX_WV_WX; +defm : VPatWidenBinarySDNode_VV_VX_WV_WX; + // 12.3. Vector Integer Extension defm : VPatExtendSDNode_V<[zext, anyext], "PseudoVZEXT", "VF2", AllFractionableVF2IntVectors>; diff --git a/llvm/test/CodeGen/RISCV/rvv/vwadd-sdnode.ll b/llvm/test/CodeGen/RISCV/rvv/vwadd-sdnode.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/rvv/vwadd-sdnode.ll @@ -0,0 +1,427 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=riscv32 -mattr=+experimental-v -verify-machineinstrs < %s | FileCheck %s +; RUN: llc -mtriple=riscv64 -mattr=+experimental-v -verify-machineinstrs < %s | FileCheck %s + +define @vwadd_vv_nxv1i64( %va, %vb) { +; CHECK-LABEL: vwadd_vv_nxv1i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu +; CHECK-NEXT: vwadd.vv v10, v8, v9 +; CHECK-NEXT: vmv1r.v v8, v10 +; CHECK-NEXT: ret + %vc = sext %va to + %vd = sext %vb to + %ve = add %vc, %vd + ret %ve +} + +define @vwaddu_vv_nxv1i64( %va, %vb) { +; CHECK-LABEL: vwaddu_vv_nxv1i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu +; CHECK-NEXT: vwaddu.vv v10, v8, v9 +; CHECK-NEXT: vmv1r.v v8, v10 +; CHECK-NEXT: ret + %vc = zext %va to + %vd = zext %vb to + %ve = add %vc, %vd + ret %ve +} + +define @vwadd_vx_nxv1i64( %va, i32 %b) { +; CHECK-LABEL: vwadd_vx_nxv1i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, mf2, ta, mu +; CHECK-NEXT: vwadd.vx v9, v8, a0 +; CHECK-NEXT: vmv1r.v v8, v9 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = sext %va to + %vd = sext %splat to + %ve = add %vc, %vd + ret %ve +} + +define @vwaddu_vx_nxv1i64( %va, i32 %b) { +; CHECK-LABEL: vwaddu_vx_nxv1i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, mf2, ta, mu +; CHECK-NEXT: vwaddu.vx v9, v8, a0 +; CHECK-NEXT: vmv1r.v v8, v9 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = zext %va to + %vd = zext %splat to + %ve = add %vc, %vd + ret %ve +} + +define @vwadd_wv_nxv1i64( %va, %vb) { +; CHECK-LABEL: vwadd_wv_nxv1i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu +; CHECK-NEXT: vwadd.wv v10, v8, v9 +; CHECK-NEXT: vmv1r.v v8, v10 +; CHECK-NEXT: ret + %vc = sext %vb to + %vd = add %va, %vc + ret %vd +} + +define @vwaddu_wv_nxv1i64( %va, %vb) { +; CHECK-LABEL: vwaddu_wv_nxv1i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu +; CHECK-NEXT: vwaddu.wv v10, v8, v9 +; CHECK-NEXT: vmv1r.v v8, v10 +; CHECK-NEXT: ret + %vc = zext %vb to + %vd = add %va, %vc + ret %vd +} + +define @vwadd_wx_nxv1i64( %va, i32 %b) { +; CHECK-LABEL: vwadd_wx_nxv1i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, mf2, ta, mu +; CHECK-NEXT: vwadd.wx v8, v8, a0 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vb = sext %splat to + %vc = add %va, %vb + ret %vc +} + +define @vwaddu_wx_nxv1i64( %va, i32 %b) { +; CHECK-LABEL: vwaddu_wx_nxv1i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, mf2, ta, mu +; CHECK-NEXT: vwaddu.wx v8, v8, a0 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vb = zext %splat to + %vc = add %va, %vb + ret %vc +} + +define @vwadd_vv_nxv2i64( %va, %vb) { +; CHECK-LABEL: vwadd_vv_nxv2i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu +; CHECK-NEXT: vwadd.vv v10, v8, v9 +; CHECK-NEXT: vmv2r.v v8, v10 +; CHECK-NEXT: ret + %vc = sext %va to + %vd = sext %vb to + %ve = add %vc, %vd + ret %ve +} + +define @vwaddu_vv_nxv2i64( %va, %vb) { +; CHECK-LABEL: vwaddu_vv_nxv2i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu +; CHECK-NEXT: vwaddu.vv v10, v8, v9 +; CHECK-NEXT: vmv2r.v v8, v10 +; CHECK-NEXT: ret + %vc = zext %va to + %vd = zext %vb to + %ve = add %vc, %vd + ret %ve +} + +define @vwadd_vx_nxv2i64( %va, i32 %b) { +; CHECK-LABEL: vwadd_vx_nxv2i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, m1, ta, mu +; CHECK-NEXT: vwadd.vx v10, v8, a0 +; CHECK-NEXT: vmv2r.v v8, v10 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = sext %va to + %vd = sext %splat to + %ve = add %vc, %vd + ret %ve +} + +define @vwaddu_vx_nxv2i64( %va, i32 %b) { +; CHECK-LABEL: vwaddu_vx_nxv2i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, m1, ta, mu +; CHECK-NEXT: vwaddu.vx v10, v8, a0 +; CHECK-NEXT: vmv2r.v v8, v10 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = zext %va to + %vd = zext %splat to + %ve = add %vc, %vd + ret %ve +} + +define @vwadd_wv_nxv2i64( %va, %vb) { +; CHECK-LABEL: vwadd_wv_nxv2i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu +; CHECK-NEXT: vwadd.wv v12, v8, v10 +; CHECK-NEXT: vmv2r.v v8, v12 +; CHECK-NEXT: ret + %vc = sext %vb to + %vd = add %va, %vc + ret %vd +} + +define @vwaddu_wv_nxv2i64( %va, %vb) { +; CHECK-LABEL: vwaddu_wv_nxv2i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu +; CHECK-NEXT: vwaddu.wv v12, v8, v10 +; CHECK-NEXT: vmv2r.v v8, v12 +; CHECK-NEXT: ret + %vc = zext %vb to + %vd = add %va, %vc + ret %vd +} + +define @vwadd_wx_nxv2i64( %va, i32 %b) { +; CHECK-LABEL: vwadd_wx_nxv2i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, m1, ta, mu +; CHECK-NEXT: vwadd.wx v8, v8, a0 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vb = sext %splat to + %vc = add %va, %vb + ret %vc +} + +define @vwaddu_wx_nxv2i64( %va, i32 %b) { +; CHECK-LABEL: vwaddu_wx_nxv2i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, m1, ta, mu +; CHECK-NEXT: vwaddu.wx v8, v8, a0 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vb = zext %splat to + %vc = add %va, %vb + ret %vc +} + +define @vwadd_vv_nxv4i64( %va, %vb) { +; CHECK-LABEL: vwadd_vv_nxv4i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, mu +; CHECK-NEXT: vwadd.vv v12, v8, v10 +; CHECK-NEXT: vmv4r.v v8, v12 +; CHECK-NEXT: ret + %vc = sext %va to + %vd = sext %vb to + %ve = add %vc, %vd + ret %ve +} + +define @vwaddu_vv_nxv4i64( %va, %vb) { +; CHECK-LABEL: vwaddu_vv_nxv4i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, mu +; CHECK-NEXT: vwaddu.vv v12, v8, v10 +; CHECK-NEXT: vmv4r.v v8, v12 +; CHECK-NEXT: ret + %vc = zext %va to + %vd = zext %vb to + %ve = add %vc, %vd + ret %ve +} + +define @vwadd_vx_nxv4i64( %va, i32 %b) { +; CHECK-LABEL: vwadd_vx_nxv4i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, m2, ta, mu +; CHECK-NEXT: vwadd.vx v12, v8, a0 +; CHECK-NEXT: vmv4r.v v8, v12 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = sext %va to + %vd = sext %splat to + %ve = add %vc, %vd + ret %ve +} + +define @vwaddu_vx_nxv4i64( %va, i32 %b) { +; CHECK-LABEL: vwaddu_vx_nxv4i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, m2, ta, mu +; CHECK-NEXT: vwaddu.vx v12, v8, a0 +; CHECK-NEXT: vmv4r.v v8, v12 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = zext %va to + %vd = zext %splat to + %ve = add %vc, %vd + ret %ve +} + +define @vwadd_wv_nxv4i64( %va, %vb) { +; CHECK-LABEL: vwadd_wv_nxv4i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, mu +; CHECK-NEXT: vwadd.wv v16, v8, v12 +; CHECK-NEXT: vmv4r.v v8, v16 +; CHECK-NEXT: ret + %vc = sext %vb to + %vd = add %va, %vc + ret %vd +} + +define @vwaddu_wv_nxv4i64( %va, %vb) { +; CHECK-LABEL: vwaddu_wv_nxv4i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, mu +; CHECK-NEXT: vwaddu.wv v16, v8, v12 +; CHECK-NEXT: vmv4r.v v8, v16 +; CHECK-NEXT: ret + %vc = zext %vb to + %vd = add %va, %vc + ret %vd +} + +define @vwadd_wx_nxv4i64( %va, i32 %b) { +; CHECK-LABEL: vwadd_wx_nxv4i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, m2, ta, mu +; CHECK-NEXT: vwadd.wx v8, v8, a0 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vb = sext %splat to + %vc = add %va, %vb + ret %vc +} + +define @vwaddu_wx_nxv4i64( %va, i32 %b) { +; CHECK-LABEL: vwaddu_wx_nxv4i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, m2, ta, mu +; CHECK-NEXT: vwaddu.wx v8, v8, a0 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vb = zext %splat to + %vc = add %va, %vb + ret %vc +} + +define @vwadd_vv_nxv8i64( %va, %vb) { +; CHECK-LABEL: vwadd_vv_nxv8i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, mu +; CHECK-NEXT: vwadd.vv v16, v8, v12 +; CHECK-NEXT: vmv8r.v v8, v16 +; CHECK-NEXT: ret + %vc = sext %va to + %vd = sext %vb to + %ve = add %vc, %vd + ret %ve +} + +define @vwaddu_vv_nxv8i64( %va, %vb) { +; CHECK-LABEL: vwaddu_vv_nxv8i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, mu +; CHECK-NEXT: vwaddu.vv v16, v8, v12 +; CHECK-NEXT: vmv8r.v v8, v16 +; CHECK-NEXT: ret + %vc = zext %va to + %vd = zext %vb to + %ve = add %vc, %vd + ret %ve +} + +define @vwadd_vx_nxv8i64( %va, i32 %b) { +; CHECK-LABEL: vwadd_vx_nxv8i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, m4, ta, mu +; CHECK-NEXT: vwadd.vx v16, v8, a0 +; CHECK-NEXT: vmv8r.v v8, v16 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = sext %va to + %vd = sext %splat to + %ve = add %vc, %vd + ret %ve +} + +define @vwaddu_vx_nxv8i64( %va, i32 %b) { +; CHECK-LABEL: vwaddu_vx_nxv8i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, m4, ta, mu +; CHECK-NEXT: vwaddu.vx v16, v8, a0 +; CHECK-NEXT: vmv8r.v v8, v16 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = zext %va to + %vd = zext %splat to + %ve = add %vc, %vd + ret %ve +} + +define @vwadd_wv_nxv8i64( %va, %vb) { +; CHECK-LABEL: vwadd_wv_nxv8i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, mu +; CHECK-NEXT: vwadd.wv v24, v8, v16 +; CHECK-NEXT: vmv8r.v v8, v24 +; CHECK-NEXT: ret + %vc = sext %vb to + %vd = add %va, %vc + ret %vd +} + +define @vwaddu_wv_nxv8i64( %va, %vb) { +; CHECK-LABEL: vwaddu_wv_nxv8i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, mu +; CHECK-NEXT: vwaddu.wv v24, v8, v16 +; CHECK-NEXT: vmv8r.v v8, v24 +; CHECK-NEXT: ret + %vc = zext %vb to + %vd = add %va, %vc + ret %vd +} + +define @vwadd_wx_nxv8i64( %va, i32 %b) { +; CHECK-LABEL: vwadd_wx_nxv8i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, m4, ta, mu +; CHECK-NEXT: vwadd.wx v8, v8, a0 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vb = sext %splat to + %vc = add %va, %vb + ret %vc +} + +define @vwaddu_wx_nxv8i64( %va, i32 %b) { +; CHECK-LABEL: vwaddu_wx_nxv8i64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a1, zero, e32, m4, ta, mu +; CHECK-NEXT: vwaddu.wx v8, v8, a0 +; CHECK-NEXT: ret + %head = insertelement undef, i32 %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vb = zext %splat to + %vc = add %va, %vb + ret %vc +}