[llvm-branch-commits] [llvm] [DAGCombiner][GlobalISel] Prevent FMA contraction when fmul cannot be eliminated (FADD/FSUB pattern) (PR #188114)

Christudasan Devadasan via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Apr 5 22:16:02 PDT 2026


================
@@ -6309,6 +6309,32 @@ 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.
+///
+/// Currently checks for the following pattern:
+///   - fmul --> fadd/fsub: Direct contraction
+bool CombinerHelper::allMulUsesCanBeContracted(const MachineInstr &MI) const {
----------------
cdevadas wrote:

This function can be simplified to:
```cpp
bool CombinerHelper::allMulUsesCanBeContracted(const MachineInstr &MI) const {
  return llvm::all_of(MRI.use_nodbg_instructions(MI.getOperand(0).getReg()),
                      [](const MachineInstr &UseMI) {
    unsigned Opcode = UseMI.getOpcode();
    return Opcode == TargetOpcode::G_FADD || Opcode == TargetOpcode::G_FSUB;
  });
}

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


More information about the llvm-branch-commits mailing list