[llvm] [DAG] Add generic m_TernaryOp() / m_c_TernaryOp() matchers (PR #165520)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 29 06:48:50 PDT 2025


================
@@ -18369,11 +18369,13 @@ template <class MatchContextClass> SDValue DAGCombiner::visitFMA(SDNode *N) {
     }
   }
 
-  // FIXME: Support splat of constant.
-  if (N0CFP && N0CFP->isExactlyValue(1.0))
-    return matcher.getNode(ISD::FADD, DL, VT, N1, N2);
-  if (N1CFP && N1CFP->isExactlyValue(1.0))
-    return matcher.getNode(ISD::FADD, DL, VT, N0, N2);
+  SDValue X, Y;
+
+  // (fma 1.0, X, Y) or (fma X, 1.0, Y) -> (fadd X, Y)
+  SDValue C1 = DAG.getConstantFP(1.0, DL, VT);
+  if (sd_match(N,
+               m_c_TernaryOp(ISD::FMA, m_Specific(C1), m_Value(X), m_Value(Y))))
----------------
RKSimon wrote:

Probably best to avoid doing this until we don't need to create a speculative constant node (IR PatternMatch has m_SpecificFP which we don't).

Don't worry if we don't have any DAGCombine coverage in this initial patch - it's only a nice-to-have for now.

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


More information about the llvm-commits mailing list