[llvm] 3c174c7 - [GlobalISel][NFC] Remove incorrect attempt to find fewest uses (#218037)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 24 06:56:23 PDT 2026


Author: LU-JOHN
Date: 2026-08-24T08:56:18-05:00
New Revision: 3c174c71e9db9b8f3845ed83d3b5b68ed26cdddf

URL: https://github.com/llvm/llvm-project/commit/3c174c71e9db9b8f3845ed83d3b5b68ed26cdddf
DIFF: https://github.com/llvm/llvm-project/commit/3c174c71e9db9b8f3845ed83d3b5b68ed26cdddf.diff

LOG: [GlobalISel][NFC] Remove incorrect attempt to find fewest uses (#218037)

When folding: `(fadd (fma x, y, (fmul u, v)), z) -> (fma x, y, (fma u,
v, z))` remove code that was looking for the addend with the fewest uses
in an expression of the form `(fadd (fmul u, v), (fmul x, y))`. This is
a mismatch and also subsequent code already only allows optimization if
the fma and fmul each have only one non-debug use.

Also fix incorrect comment when looking for the operand with fewest uses
in (fsub (fmul u, v), (fmul x, y)).

---------

Signed-off-by: John Lu <John.Lu at amd.com>

Added: 
    

Modified: 
    llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
index 55c4339edc39e..5804be63fad48 100644
--- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
@@ -6638,14 +6638,6 @@ bool CombinerHelper::matchCombineFAddFMAFMulToFMadOrFMA(
   unsigned PreferredFusedOpcode =
       HasFMAD ? TargetOpcode::G_FMAD : TargetOpcode::G_FMA;
 
-  // If we have two choices trying to fold (fadd (fmul u, v), (fmul x, y)),
-  // prefer to fold the multiply with fewer uses.
-  if (Aggressive && isContractableFMul(*LHS.MI, AllowFusionGlobally) &&
-      isContractableFMul(*RHS.MI, AllowFusionGlobally)) {
-    if (hasMoreUses(*LHS.MI, *RHS.MI, MRI))
-      std::swap(LHS, RHS);
-  }
-
   MachineInstr *FMA = nullptr;
   Register Z;
   // fold (fadd (fma x, y, (fmul u, v)), z) -> (fma x, y, (fma u, v, z))
@@ -6855,7 +6847,7 @@ bool CombinerHelper::matchCombineFSubFMulToFMadOrFMA(
   DefinitionAndSourceRegister RHS = {Op2Def, Op2};
   LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
 
-  // If we have two choices trying to fold (fadd (fmul u, v), (fmul x, y)),
+  // If we have two choices trying to fold (fsub (fmul u, v), (fmul x, y)),
   // prefer to fold the multiply with fewer uses.
   int FirstMulHasFewerUses = true;
   if (isContractableFMul(*LHS.MI, AllowFusionGlobally) &&


        


More information about the llvm-commits mailing list