@@ -15816,8 +15816,6 @@ SDValue DAGCombiner::visitFADDForFMACombine(SDNode *N) {
15816
15816
if (!HasFMAD && !HasFMA)
15817
15817
return SDValue();
15818
15818
15819
- bool CanReassociate =
15820
- Options.UnsafeFPMath || N->getFlags().hasAllowReassociation();
15821
15819
bool AllowFusionGlobally = (Options.AllowFPOpFusion == FPOpFusion::Fast ||
15822
15820
Options.UnsafeFPMath || HasFMAD);
15823
15821
// If the addition is not contractable, do not combine.
@@ -15877,6 +15875,8 @@ SDValue DAGCombiner::visitFADDForFMACombine(SDNode *N) {
15877
15875
// fadd (G, (fma A, B, (fma (C, D, (fmul (E, F)))))) -->
15878
15876
// fma A, B, (fma C, D, fma (E, F, G)).
15879
15877
// This requires reassociation because it changes the order of operations.
15878
+ bool CanReassociate =
15879
+ Options.UnsafeFPMath || N->getFlags().hasAllowReassociation();
15880
15880
if (CanReassociate) {
15881
15881
SDValue FMA, E;
15882
15882
if (isFusedOp(N0) && N0.hasOneUse()) {
@@ -17033,9 +17033,6 @@ template <class MatchContextClass> SDValue DAGCombiner::visitFMA(SDNode *N) {
17033
17033
SelectionDAG::FlagInserter FlagsInserter(DAG, N);
17034
17034
MatchContextClass matcher(DAG, TLI, N);
17035
17035
17036
- bool CanReassociate =
17037
- Options.UnsafeFPMath || N->getFlags().hasAllowReassociation();
17038
-
17039
17036
// Constant fold FMA.
17040
17037
if (isa<ConstantFPSDNode>(N0) &&
17041
17038
isa<ConstantFPSDNode>(N1) &&
@@ -17078,6 +17075,8 @@ template <class MatchContextClass> SDValue DAGCombiner::visitFMA(SDNode *N) {
17078
17075
!DAG.isConstantFPBuildVectorOrConstantFP(N1))
17079
17076
return matcher.getNode(ISD::FMA, SDLoc(N), VT, N1, N0, N2);
17080
17077
17078
+ bool CanReassociate =
17079
+ Options.UnsafeFPMath || N->getFlags().hasAllowReassociation();
17081
17080
if (CanReassociate) {
17082
17081
// (fma x, c1, (fmul x, c2)) -> (fmul x, c1+c2)
17083
17082
if (matcher.match(N2, ISD::FMUL) && N0 == N2.getOperand(0) &&
0 commit comments