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 @@ -1046,6 +1046,11 @@ return N->hasOneUse(); }]>; +def fpext_oneuse : PatFrag<(ops node:$A), + (any_fpextend 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 @@ -413,6 +413,41 @@ } } +multiclass VPatWidenBinaryFPSDNode_VV_VF { + foreach vti = AllWidenableFloatVectors in { + def : Pat<(op (vti.Wti.Vector (fpext_oneuse (vti.Vti.Vector vti.Vti.RegClass:$rs2))), + (vti.Wti.Vector (fpext_oneuse (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 (fpext_oneuse (vti.Vti.Vector vti.Vti.RegClass:$rs2))), + (vti.Wti.Vector (fpext_oneuse (vti.Vti.Vector (SplatPat vti.Vti.ScalarRegClass:$rs1))))), + (!cast(instruction_name#"_V"#vti.Vti.ScalarSuffix#"_"#vti.Vti.LMul.MX) + vti.Vti.RegClass:$rs2, vti.Vti.ScalarRegClass:$rs1, + vti.Vti.AVL, vti.Vti.Log2SEW)>; + } +} + +multiclass VPatWidenBinaryFPSDNode_WV_WF { + foreach vti = AllWidenableFloatVectors in { + def : Pat<(op (vti.Wti.Vector vti.Wti.RegClass:$rs2), + (vti.Wti.Vector (fpext_oneuse (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 (fpext_oneuse (vti.Vti.Vector (SplatPat vti.Vti.ScalarRegClass:$rs1))))), + (!cast(instruction_name#"_W"#vti.Vti.ScalarSuffix#"_"#vti.Vti.LMul.MX) + vti.Wti.RegClass:$rs2, vti.Vti.ScalarRegClass:$rs1, + vti.Vti.AVL, vti.Vti.Log2SEW)>; + } +} + +multiclass VPatWidenBinaryFPSDNode_VV_VF_WV_WF { + defm : VPatWidenBinaryFPSDNode_VV_VF; + defm : VPatWidenBinaryFPSDNode_WV_WF; +} + //===----------------------------------------------------------------------===// // Patterns. //===----------------------------------------------------------------------===// @@ -650,6 +685,10 @@ defm : VPatBinaryFPSDNode_VV_VF; defm : VPatBinaryFPSDNode_R_VF; +// 14.3. Vector Widening Floating-Point Add/Subtract Instructions +defm : VPatWidenBinaryFPSDNode_VV_VF_WV_WF; +defm : VPatWidenBinaryFPSDNode_VV_VF_WV_WF; + // 14.4. Vector Single-Width Floating-Point Multiply/Divide Instructions defm : VPatBinaryFPSDNode_VV_VF; defm : VPatBinaryFPSDNode_VV_VF; diff --git a/llvm/test/CodeGen/RISCV/rvv/vfwadd-sdnode.ll b/llvm/test/CodeGen/RISCV/rvv/vfwadd-sdnode.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/rvv/vfwadd-sdnode.ll @@ -0,0 +1,217 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=riscv32 -mattr=+d,+zfh,+experimental-v -target-abi=ilp32d \ +; RUN: -verify-machineinstrs < %s | FileCheck %s +; RUN: llc -mtriple=riscv64 -mattr=+d,+zfh,+experimental-v -target-abi=lp64d \ +; RUN: -verify-machineinstrs < %s | FileCheck %s + +define @vfwadd_vv_nxv1f64( %va, %vb) { +; CHECK-LABEL: vfwadd_vv_nxv1f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu +; CHECK-NEXT: vfwadd.vv v10, v8, v9 +; CHECK-NEXT: vmv1r.v v8, v10 +; CHECK-NEXT: ret + %vc = fpext %va to + %vd = fpext %vb to + %ve = fadd %vc, %vd + ret %ve +} + +define @vfwadd_vf_nxv1f64( %va, float %b) { +; CHECK-LABEL: vfwadd_vf_nxv1f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu +; CHECK-NEXT: vfwadd.vf v9, v8, fa0 +; CHECK-NEXT: vmv1r.v v8, v9 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %va to + %vd = fpext %splat to + %ve = fadd %vc, %vd + ret %ve +} + +define @vfwadd_wv_nxv1f64( %va, %vb) { +; CHECK-LABEL: vfwadd_wv_nxv1f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu +; CHECK-NEXT: vfwadd.wv v10, v8, v9 +; CHECK-NEXT: vmv1r.v v8, v10 +; CHECK-NEXT: ret + %vc = fpext %vb to + %vd = fadd %va, %vc + ret %vd +} + +define @vfwadd_wf_nxv1f64( %va, float %b) { +; CHECK-LABEL: vfwadd_wf_nxv1f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu +; CHECK-NEXT: vfwadd.wf v8, v8, fa0 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %splat to + %vd = fadd %va, %vc + ret %vd +} + +define @vfwadd_vv_nxv2f64( %va, %vb) { +; CHECK-LABEL: vfwadd_vv_nxv2f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu +; CHECK-NEXT: vfwadd.vv v10, v8, v9 +; CHECK-NEXT: vmv2r.v v8, v10 +; CHECK-NEXT: ret + %vc = fpext %va to + %vd = fpext %vb to + %ve = fadd %vc, %vd + ret %ve +} + +define @vfwadd_vf_nxv2f64( %va, float %b) { +; CHECK-LABEL: vfwadd_vf_nxv2f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu +; CHECK-NEXT: vfwadd.vf v10, v8, fa0 +; CHECK-NEXT: vmv2r.v v8, v10 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %va to + %vd = fpext %splat to + %ve = fadd %vc, %vd + ret %ve +} + +define @vfwadd_wv_nxv2f64( %va, %vb) { +; CHECK-LABEL: vfwadd_wv_nxv2f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu +; CHECK-NEXT: vfwadd.wv v12, v8, v10 +; CHECK-NEXT: vmv2r.v v8, v12 +; CHECK-NEXT: ret + %vc = fpext %vb to + %vd = fadd %va, %vc + ret %vd +} + +define @vfwadd_wf_nxv2f64( %va, float %b) { +; CHECK-LABEL: vfwadd_wf_nxv2f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu +; CHECK-NEXT: vfwadd.wf v8, v8, fa0 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %splat to + %vd = fadd %va, %vc + ret %vd +} + +define @vfwadd_vv_nxv4f64( %va, %vb) { +; CHECK-LABEL: vfwadd_vv_nxv4f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, mu +; CHECK-NEXT: vfwadd.vv v12, v8, v10 +; CHECK-NEXT: vmv4r.v v8, v12 +; CHECK-NEXT: ret + %vc = fpext %va to + %vd = fpext %vb to + %ve = fadd %vc, %vd + ret %ve +} + +define @vfwadd_vf_nxv4f64( %va, float %b) { +; CHECK-LABEL: vfwadd_vf_nxv4f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, mu +; CHECK-NEXT: vfwadd.vf v12, v8, fa0 +; CHECK-NEXT: vmv4r.v v8, v12 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %va to + %vd = fpext %splat to + %ve = fadd %vc, %vd + ret %ve +} + +define @vfwadd_wv_nxv4f64( %va, %vb) { +; CHECK-LABEL: vfwadd_wv_nxv4f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, mu +; CHECK-NEXT: vfwadd.wv v16, v8, v12 +; CHECK-NEXT: vmv4r.v v8, v16 +; CHECK-NEXT: ret + %vc = fpext %vb to + %vd = fadd %va, %vc + ret %vd +} + +define @vfwadd_wf_nxv4f64( %va, float %b) { +; CHECK-LABEL: vfwadd_wf_nxv4f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, mu +; CHECK-NEXT: vfwadd.wf v8, v8, fa0 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %splat to + %vd = fadd %va, %vc + ret %vd +} + +define @vfwadd_vv_nxv8f64( %va, %vb) { +; CHECK-LABEL: vfwadd_vv_nxv8f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, mu +; CHECK-NEXT: vfwadd.vv v16, v8, v12 +; CHECK-NEXT: vmv8r.v v8, v16 +; CHECK-NEXT: ret + %vc = fpext %va to + %vd = fpext %vb to + %ve = fadd %vc, %vd + ret %ve +} + +define @vfwadd_vf_nxv8f64( %va, float %b) { +; CHECK-LABEL: vfwadd_vf_nxv8f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, mu +; CHECK-NEXT: vfwadd.vf v16, v8, fa0 +; CHECK-NEXT: vmv8r.v v8, v16 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %va to + %vd = fpext %splat to + %ve = fadd %vc, %vd + ret %ve +} + +define @vfwadd_wv_nxv8f64( %va, %vb) { +; CHECK-LABEL: vfwadd_wv_nxv8f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, mu +; CHECK-NEXT: vfwadd.wv v24, v8, v16 +; CHECK-NEXT: vmv8r.v v8, v24 +; CHECK-NEXT: ret + %vc = fpext %vb to + %vd = fadd %va, %vc + ret %vd +} + +define @vfwadd_wf_nxv8f64( %va, float %b) { +; CHECK-LABEL: vfwadd_wf_nxv8f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, mu +; CHECK-NEXT: vfwadd.wf v8, v8, fa0 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %splat to + %vd = fadd %va, %vc + ret %vd +} diff --git a/llvm/test/CodeGen/RISCV/rvv/vfwsub-sdnode.ll b/llvm/test/CodeGen/RISCV/rvv/vfwsub-sdnode.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/rvv/vfwsub-sdnode.ll @@ -0,0 +1,217 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=riscv32 -mattr=+d,+zfh,+experimental-v -target-abi=ilp32d \ +; RUN: -verify-machineinstrs < %s | FileCheck %s +; RUN: llc -mtriple=riscv64 -mattr=+d,+zfh,+experimental-v -target-abi=lp64d \ +; RUN: -verify-machineinstrs < %s | FileCheck %s + +define @vfwsub_vv_nxv1f64( %va, %vb) { +; CHECK-LABEL: vfwsub_vv_nxv1f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu +; CHECK-NEXT: vfwsub.vv v10, v8, v9 +; CHECK-NEXT: vmv1r.v v8, v10 +; CHECK-NEXT: ret + %vc = fpext %va to + %vd = fpext %vb to + %ve = fsub %vc, %vd + ret %ve +} + +define @vfwsub_vf_nxv1f64( %va, float %b) { +; CHECK-LABEL: vfwsub_vf_nxv1f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu +; CHECK-NEXT: vfwsub.vf v9, v8, fa0 +; CHECK-NEXT: vmv1r.v v8, v9 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %va to + %vd = fpext %splat to + %ve = fsub %vc, %vd + ret %ve +} + +define @vfwsub_wv_nxv1f64( %va, %vb) { +; CHECK-LABEL: vfwsub_wv_nxv1f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu +; CHECK-NEXT: vfwsub.wv v10, v8, v9 +; CHECK-NEXT: vmv1r.v v8, v10 +; CHECK-NEXT: ret + %vc = fpext %vb to + %vd = fsub %va, %vc + ret %vd +} + +define @vfwsub_wf_nxv1f64( %va, float %b) { +; CHECK-LABEL: vfwsub_wf_nxv1f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, mf2, ta, mu +; CHECK-NEXT: vfwsub.wf v8, v8, fa0 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %splat to + %vd = fsub %va, %vc + ret %vd +} + +define @vfwsub_vv_nxv2f64( %va, %vb) { +; CHECK-LABEL: vfwsub_vv_nxv2f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu +; CHECK-NEXT: vfwsub.vv v10, v8, v9 +; CHECK-NEXT: vmv2r.v v8, v10 +; CHECK-NEXT: ret + %vc = fpext %va to + %vd = fpext %vb to + %ve = fsub %vc, %vd + ret %ve +} + +define @vfwsub_vf_nxv2f64( %va, float %b) { +; CHECK-LABEL: vfwsub_vf_nxv2f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu +; CHECK-NEXT: vfwsub.vf v10, v8, fa0 +; CHECK-NEXT: vmv2r.v v8, v10 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %va to + %vd = fpext %splat to + %ve = fsub %vc, %vd + ret %ve +} + +define @vfwsub_wv_nxv2f64( %va, %vb) { +; CHECK-LABEL: vfwsub_wv_nxv2f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu +; CHECK-NEXT: vfwsub.wv v12, v8, v10 +; CHECK-NEXT: vmv2r.v v8, v12 +; CHECK-NEXT: ret + %vc = fpext %vb to + %vd = fsub %va, %vc + ret %vd +} + +define @vfwsub_wf_nxv2f64( %va, float %b) { +; CHECK-LABEL: vfwsub_wf_nxv2f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, mu +; CHECK-NEXT: vfwsub.wf v8, v8, fa0 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %splat to + %vd = fsub %va, %vc + ret %vd +} + +define @vfwsub_vv_nxv4f64( %va, %vb) { +; CHECK-LABEL: vfwsub_vv_nxv4f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, mu +; CHECK-NEXT: vfwsub.vv v12, v8, v10 +; CHECK-NEXT: vmv4r.v v8, v12 +; CHECK-NEXT: ret + %vc = fpext %va to + %vd = fpext %vb to + %ve = fsub %vc, %vd + ret %ve +} + +define @vfwsub_vf_nxv4f64( %va, float %b) { +; CHECK-LABEL: vfwsub_vf_nxv4f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, mu +; CHECK-NEXT: vfwsub.vf v12, v8, fa0 +; CHECK-NEXT: vmv4r.v v8, v12 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %va to + %vd = fpext %splat to + %ve = fsub %vc, %vd + ret %ve +} + +define @vfwsub_wv_nxv4f64( %va, %vb) { +; CHECK-LABEL: vfwsub_wv_nxv4f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, mu +; CHECK-NEXT: vfwsub.wv v16, v8, v12 +; CHECK-NEXT: vmv4r.v v8, v16 +; CHECK-NEXT: ret + %vc = fpext %vb to + %vd = fsub %va, %vc + ret %vd +} + +define @vfwsub_wf_nxv4f64( %va, float %b) { +; CHECK-LABEL: vfwsub_wf_nxv4f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, mu +; CHECK-NEXT: vfwsub.wf v8, v8, fa0 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %splat to + %vd = fsub %va, %vc + ret %vd +} + +define @vfwsub_vv_nxv8f64( %va, %vb) { +; CHECK-LABEL: vfwsub_vv_nxv8f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, mu +; CHECK-NEXT: vfwsub.vv v16, v8, v12 +; CHECK-NEXT: vmv8r.v v8, v16 +; CHECK-NEXT: ret + %vc = fpext %va to + %vd = fpext %vb to + %ve = fsub %vc, %vd + ret %ve +} + +define @vfwsub_vf_nxv8f64( %va, float %b) { +; CHECK-LABEL: vfwsub_vf_nxv8f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, mu +; CHECK-NEXT: vfwsub.vf v16, v8, fa0 +; CHECK-NEXT: vmv8r.v v8, v16 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %va to + %vd = fpext %splat to + %ve = fsub %vc, %vd + ret %ve +} + +define @vfwsub_wv_nxv8f64( %va, %vb) { +; CHECK-LABEL: vfwsub_wv_nxv8f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, mu +; CHECK-NEXT: vfwsub.wv v24, v8, v16 +; CHECK-NEXT: vmv8r.v v8, v24 +; CHECK-NEXT: ret + %vc = fpext %vb to + %vd = fsub %va, %vc + ret %vd +} + +define @vfwsub_wf_nxv8f64( %va, float %b) { +; CHECK-LABEL: vfwsub_wf_nxv8f64: +; CHECK: # %bb.0: +; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, mu +; CHECK-NEXT: vfwsub.wf v8, v8, fa0 +; CHECK-NEXT: ret + %head = insertelement undef, float %b, i32 0 + %splat = shufflevector %head, undef, zeroinitializer + %vc = fpext %splat to + %vd = fsub %va, %vc + ret %vd +}