[llvm] [AMDGPU][DAGCombiner][GlobalISel] Prevent FMA contraction when multiply cannot be eliminated (PR #169735)

Christudasan Devadasan via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 12 23:15:21 PST 2025


================
@@ -6208,6 +6208,114 @@ static bool hasMoreUses(const MachineInstr &MI0, const MachineInstr &MI1,
                        MRI.use_instr_nodbg_end());
 }
 
+// Check if all uses of a multiply can be contracted into FMA operations.
+// Returns true if all uses of the multiply are contractable, meaning the
+// multiply can potentially be eliminated through FMA contraction.
+// Returns false if any use cannot be contracted, which would mean contracting
+// would duplicate the multiply without reducing the total number of operations.
+//
+// This uses a simple, non-recursive check for the following patterns:
+//   - fmul → fadd/fsub: Direct contraction
+//   - fmul → fneg → fsub: FNEG folds into FMA with negated operand
+//   - fmul → fpext → {fadd, fsub, fma}: FPEXT folds if it can be folded
+//   - fmul → fma: Assume FMA contraction will handle it (to avoid complexity)
+static bool allMulUsesCanBeContracted(const MachineInstr &MulMI,
----------------
cdevadas wrote:

Nit: just use MI instead of MulMI.

https://github.com/llvm/llvm-project/pull/169735


More information about the llvm-commits mailing list