[llvm] 4541633 - [RISCV] Allow FWMUL formation for an FP extend used twice by the same multiply.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue May 30 15:08:24 PDT 2023


Author: Craig Topper
Date: 2023-05-30T15:08:08-07:00
New Revision: 454163354b0b2755746f9b3c32059adff4d34bd3

URL: https://github.com/llvm/llvm-project/commit/454163354b0b2755746f9b3c32059adff4d34bd3
DIFF: https://github.com/llvm/llvm-project/commit/454163354b0b2755746f9b3c32059adff4d34bd3.diff

LOG: [RISCV] Allow FWMUL formation for an FP extend used twice by the same multiply.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVISelLowering.cpp
    llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vfwmul.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 9d0267912c9f..229345159280 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -11372,7 +11372,8 @@ static SDValue performVFMUL_VLCombine(SDNode *N, SelectionDAG &DAG) {
 
   // TODO: Refactor to handle more complex cases similar to
   // combineBinOp_VLToVWBinOp_VL.
-  if (!Op0.hasOneUse() || !Op1.hasOneUse())
+  if ((!Op0.hasOneUse() || !Op1.hasOneUse()) &&
+      (Op0 != Op1 || !Op0->hasNUsesOfValue(2, 0)))
     return SDValue();
 
   // Check the mask and VL are the same.

diff  --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vfwmul.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vfwmul.ll
index 83f6571bd325..c45349f975b5 100644
--- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vfwmul.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-vfwmul.ll
@@ -391,3 +391,44 @@ define <32 x double> @vfwmul_vf_v32f32(ptr %x, float %y) {
   %f = fmul <32 x double> %d, %e
   ret <32 x double> %f
 }
+
+define <2 x float> @vfwmul_squared_v2f16_v2f32(ptr %x) {
+; CHECK-LABEL: vfwmul_squared_v2f16_v2f32:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    vsetivli zero, 2, e16, mf4, ta, ma
+; CHECK-NEXT:    vle16.v v9, (a0)
+; CHECK-NEXT:    vfwmul.vv v8, v9, v9
+; CHECK-NEXT:    ret
+  %a = load <2 x half>, ptr %x
+  %b = fpext <2 x half> %a to <2 x float>
+  %c = fmul <2 x float> %b, %b
+  ret <2 x float> %c
+}
+
+define <2 x double> @vfwmul_squared_v2f32_v2f64(ptr %x) {
+; CHECK-LABEL: vfwmul_squared_v2f32_v2f64:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    vsetivli zero, 2, e32, mf2, ta, ma
+; CHECK-NEXT:    vle32.v v9, (a0)
+; CHECK-NEXT:    vfwmul.vv v8, v9, v9
+; CHECK-NEXT:    ret
+  %a = load <2 x float>, ptr %x
+  %b = fpext <2 x float> %a to <2 x double>
+  %c = fmul <2 x double> %b, %b
+  ret <2 x double> %c
+}
+
+define <2 x double> @vfwmul_squared_v2f16_v2f64(ptr %x) {
+; CHECK-LABEL: vfwmul_squared_v2f16_v2f64:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    vsetivli zero, 2, e16, mf4, ta, ma
+; CHECK-NEXT:    vle16.v v8, (a0)
+; CHECK-NEXT:    vfwcvt.f.f.v v9, v8
+; CHECK-NEXT:    vsetvli zero, zero, e32, mf2, ta, ma
+; CHECK-NEXT:    vfwmul.vv v8, v9, v9
+; CHECK-NEXT:    ret
+  %a = load <2 x half>, ptr %x
+  %b = fpext <2 x half> %a to <2 x double>
+  %c = fmul <2 x double> %b, %b
+  ret <2 x double> %c
+}


        


More information about the llvm-commits mailing list