[PATCH] D151890: [DAGCombiner] Do not fold fadd (fmul x, y), (fmul x, y) -> fma x, y, (fmul x, y)

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 1 08:35:29 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb7052fa3295e: [DAGCombiner] Do not fold fadd (fmul x, y), (fmul x, y) -> fma x, y, (fmul x, y) (authored by foad).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151890/new/

https://reviews.llvm.org/D151890

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/AMDGPU/dagcombine-fma-fmad.ll


Index: llvm/test/CodeGen/AMDGPU/dagcombine-fma-fmad.ll
===================================================================
--- llvm/test/CodeGen/AMDGPU/dagcombine-fma-fmad.ll
+++ llvm/test/CodeGen/AMDGPU/dagcombine-fma-fmad.ll
@@ -277,9 +277,7 @@
 define amdgpu_ps float @fma_vs_output_modifier_2(float %x) #0 {
 ; GCN-LABEL: fma_vs_output_modifier_2:
 ; GCN:       ; %bb.0:
-; GCN-NEXT:    v_mul_f32_e32 v1, v0, v0
-; GCN-NEXT:    v_fmac_f32_e32 v1, v0, v0
-; GCN-NEXT:    v_mov_b32_e32 v0, v1
+; GCN-NEXT:    v_mul_f32_e64 v0, v0, v0 mul:2
 ; GCN-NEXT:    ; return to shader part epilog
   %m = fmul contract float %x, %x
   %a = fadd nsz contract float %m, %m
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -15233,6 +15233,13 @@
   if (!AllowFusionGlobally && !N->getFlags().hasAllowContract())
     return SDValue();
 
+  // Folding fadd (fmul x, y), (fmul x, y) -> fma x, y, (fmul x, y) is never
+  // beneficial. It does not reduce latency. It increases register pressure. It
+  // replaces an fadd with an fma which is a more complex instruction, so is
+  // likely to have a larger encoding, use more functional units, etc.
+  if (N0 == N1)
+    return SDValue();
+
   if (TLI.generateFMAsInMachineCombiner(VT, OptLevel))
     return SDValue();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151890.527433.patch
Type: text/x-patch
Size: 1432 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230601/e40464c8/attachment.bin>


More information about the llvm-commits mailing list