Skip to content

Commit de8c30d

Browse files
[DAG] Optimize FMA handling for constant 1.0 by transforming to FADD
1 parent 324cca2 commit de8c30d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18369,11 +18369,14 @@ template <class MatchContextClass> SDValue DAGCombiner::visitFMA(SDNode *N) {
1836918369
}
1837018370
}
1837118371

18372-
// FIXME: Support splat of constant.
18373-
if (N0CFP && N0CFP->isExactlyValue(1.0))
18374-
return matcher.getNode(ISD::FADD, DL, VT, N1, N2);
18375-
if (N1CFP && N1CFP->isExactlyValue(1.0))
18376-
return matcher.getNode(ISD::FADD, DL, VT, N0, N2);
18372+
using namespace SDPatternMatch;
18373+
SDValue X, Y, Cst;
18374+
18375+
// (fma 1.0, X, Y) or (fma X, 1.0, Y) -> (fadd X, Y)
18376+
SDValue C1 = DAG.getConstantFP(1.0, DL, VT);
18377+
if (sd_match(N,
18378+
m_c_TernaryOp(ISD::FMA, m_Specific(C1), m_Value(X), m_Value(Y))))
18379+
return matcher.getNode(ISD::FADD, DL, VT, X, Y);
1837718380

1837818381
// Canonicalize (fma c, x, y) -> (fma x, c, y)
1837918382
if (DAG.isConstantFPBuildVectorOrConstantFP(N0) &&

0 commit comments

Comments
 (0)