[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


================
@@ -17678,6 +17678,30 @@ static bool isFusedOp(const MatchContextClass &Matcher, SDValue N) {
   return Matcher.match(N, ISD::FMA) || Matcher.match(N, ISD::FMAD);
 }
 
+/// 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
+static bool allMulUsesCanBeContracted(SDValue Mul) {
----------------
cdevadas wrote:

Same as the GlobalISel counterpart:
```cpp
static bool allMulUsesCanBeContracted(SDValue Mul) {
    return llvm::all_of(Mul->users(), [](const SDNode *User) {
      unsigned Opcode = User->getOpcode();
      return Opcode == ISD::FADD || Opcode == ISD::FSUB;
    });
  }

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


More information about the llvm-branch-commits mailing list