@@ -16280,15 +16280,6 @@ ConstantFoldBITCASTofBUILD_VECTOR(SDNode *BV, EVT DstEltVT) {
16280
16280
return DAG.getBuildVector(VT, DL, Ops);
16281
16281
}
16282
16282
16283
- // Returns true if floating point contraction is allowed on the FMUL-SDValue
16284
- // `N`
16285
- static bool isContractableFMUL(const TargetOptions &Options, SDValue N) {
16286
- assert(N.getOpcode() == ISD::FMUL);
16287
-
16288
- return Options.AllowFPOpFusion == FPOpFusion::Fast || Options.UnsafeFPMath ||
16289
- N->getFlags().hasAllowContract();
16290
- }
16291
-
16292
16283
// Returns true if `N` can assume no infinities involved in its computation.
16293
16284
static bool hasNoInfs(const TargetOptions &Options, SDValue N) {
16294
16285
return Options.NoInfsFPMath || N->getFlags().hasNoInfs();
@@ -16320,8 +16311,9 @@ SDValue DAGCombiner::visitFADDForFMACombine(SDNode *N) {
16320
16311
if (!HasFMAD && !HasFMA)
16321
16312
return SDValue();
16322
16313
16323
- bool AllowFusionGlobally = (Options.AllowFPOpFusion == FPOpFusion::Fast ||
16324
- Options.UnsafeFPMath || HasFMAD);
16314
+ bool UnsafeFPMath = DAG.getMachineFunction().hasUnsafeFPMath();
16315
+ bool AllowFusionGlobally =
16316
+ (Options.AllowFPOpFusion == FPOpFusion::Fast || UnsafeFPMath || HasFMAD);
16325
16317
// If the addition is not contractable, do not combine.
16326
16318
if (!AllowFusionGlobally && !N->getFlags().hasAllowContract())
16327
16319
return SDValue();
@@ -16379,8 +16371,7 @@ SDValue DAGCombiner::visitFADDForFMACombine(SDNode *N) {
16379
16371
// fadd (G, (fma A, B, (fma (C, D, (fmul (E, F)))))) -->
16380
16372
// fma A, B, (fma C, D, fma (E, F, G)).
16381
16373
// This requires reassociation because it changes the order of operations.
16382
- bool CanReassociate =
16383
- Options.UnsafeFPMath || N->getFlags().hasAllowReassociation();
16374
+ bool CanReassociate = UnsafeFPMath || N->getFlags().hasAllowReassociation();
16384
16375
if (CanReassociate) {
16385
16376
SDValue FMA, E;
16386
16377
if (isFusedOp(N0) && N0.hasOneUse()) {
@@ -16558,8 +16549,9 @@ SDValue DAGCombiner::visitFSUBForFMACombine(SDNode *N) {
16558
16549
return SDValue();
16559
16550
16560
16551
const SDNodeFlags Flags = N->getFlags();
16561
- bool AllowFusionGlobally = (Options.AllowFPOpFusion == FPOpFusion::Fast ||
16562
- Options.UnsafeFPMath || HasFMAD);
16552
+ bool UnsafeFPMath = DAG.getMachineFunction().hasUnsafeFPMath();
16553
+ bool AllowFusionGlobally =
16554
+ (Options.AllowFPOpFusion == FPOpFusion::Fast || UnsafeFPMath || HasFMAD);
16563
16555
16564
16556
// If the subtraction is not contractable, do not combine.
16565
16557
if (!AllowFusionGlobally && !N->getFlags().hasAllowContract())
@@ -16714,8 +16706,8 @@ SDValue DAGCombiner::visitFSUBForFMACombine(SDNode *N) {
16714
16706
}
16715
16707
}
16716
16708
16717
- auto isReassociable = [&Options ](SDNode *N) {
16718
- return Options. UnsafeFPMath || N->getFlags().hasAllowReassociation();
16709
+ auto isReassociable = [UnsafeFPMath ](SDNode *N) {
16710
+ return UnsafeFPMath || N->getFlags().hasAllowReassociation();
16719
16711
};
16720
16712
16721
16713
auto isContractableAndReassociableFMUL = [&isContractableFMUL,
@@ -16729,7 +16721,7 @@ SDValue DAGCombiner::visitFSUBForFMACombine(SDNode *N) {
16729
16721
16730
16722
// More folding opportunities when target permits.
16731
16723
if (Aggressive && isReassociable(N)) {
16732
- bool CanFuse = Options. UnsafeFPMath || N->getFlags().hasAllowContract();
16724
+ bool CanFuse = UnsafeFPMath || N->getFlags().hasAllowContract();
16733
16725
// fold (fsub (fma x, y, (fmul u, v)), z)
16734
16726
// -> (fma x, y (fma u, v, (fneg z)))
16735
16727
if (CanFuse && isFusedOp(N0) &&
@@ -16878,6 +16870,16 @@ SDValue DAGCombiner::visitFMULForFMADistributiveCombine(SDNode *N) {
16878
16870
if (!hasNoInfs(Options, FAdd))
16879
16871
return SDValue();
16880
16872
16873
+ // Returns true if floating point contraction is allowed on the FMUL-SDValue
16874
+ // `N`
16875
+ auto isContractableFMUL = [this](const TargetOptions &Options, SDValue N) {
16876
+ assert(N.getOpcode() == ISD::FMUL);
16877
+
16878
+ return Options.AllowFPOpFusion == FPOpFusion::Fast ||
16879
+ DAG.getMachineFunction().hasUnsafeFPMath() ||
16880
+ N->getFlags().hasAllowContract();
16881
+ };
16882
+
16881
16883
// Floating-point multiply-add without intermediate rounding.
16882
16884
bool HasFMA =
16883
16885
isContractableFMUL(Options, SDValue(N, 0)) &&
@@ -16886,7 +16888,7 @@ SDValue DAGCombiner::visitFMULForFMADistributiveCombine(SDNode *N) {
16886
16888
16887
16889
// Floating-point multiply-add with intermediate rounding. This can result
16888
16890
// in a less precise result due to the changed rounding order.
16889
- bool HasFMAD = Options.UnsafeFPMath &&
16891
+ bool HasFMAD = DAG.getMachineFunction().hasUnsafeFPMath() &&
16890
16892
(LegalOperations && TLI.isFMADLegal(DAG, N));
16891
16893
16892
16894
// No valid opcode, do not combine.
@@ -16971,6 +16973,7 @@ SDValue DAGCombiner::visitFADD(SDNode *N) {
16971
16973
SDValue N1 = N->getOperand(1);
16972
16974
bool N0CFP = DAG.isConstantFPBuildVectorOrConstantFP(N0);
16973
16975
bool N1CFP = DAG.isConstantFPBuildVectorOrConstantFP(N1);
16976
+ bool UnsafeFPMath = DAG.getMachineFunction().hasUnsafeFPMath();
16974
16977
EVT VT = N->getValueType(0);
16975
16978
SDLoc DL(N);
16976
16979
const TargetOptions &Options = DAG.getTarget().Options;
@@ -17052,7 +17055,7 @@ SDValue DAGCombiner::visitFADD(SDNode *N) {
17052
17055
// If 'unsafe math' or reassoc and nsz, fold lots of things.
17053
17056
// TODO: break out portions of the transformations below for which Unsafe is
17054
17057
// considered and which do not require both nsz and reassoc
17055
- if (((Options. UnsafeFPMath && Options.NoSignedZerosFPMath) ||
17058
+ if (((UnsafeFPMath && Options.NoSignedZerosFPMath) ||
17056
17059
(Flags.hasAllowReassociation() && Flags.hasNoSignedZeros())) &&
17057
17060
AllowNewConst) {
17058
17061
// fadd (fadd x, c1), c2 -> fadd x, c1 + c2
@@ -17190,6 +17193,7 @@ SDValue DAGCombiner::visitFSUB(SDNode *N) {
17190
17193
const TargetOptions &Options = DAG.getTarget().Options;
17191
17194
const SDNodeFlags Flags = N->getFlags();
17192
17195
SelectionDAG::FlagInserter FlagsInserter(DAG, N);
17196
+ bool UnsafeFPMath = DAG.getMachineFunction().hasUnsafeFPMath();
17193
17197
17194
17198
if (SDValue R = DAG.simplifyFPBinop(N->getOpcode(), N0, N1, Flags))
17195
17199
return R;
@@ -17239,7 +17243,7 @@ SDValue DAGCombiner::visitFSUB(SDNode *N) {
17239
17243
}
17240
17244
}
17241
17245
17242
- if (((Options. UnsafeFPMath && Options.NoSignedZerosFPMath) ||
17246
+ if (((UnsafeFPMath && Options.NoSignedZerosFPMath) ||
17243
17247
(Flags.hasAllowReassociation() && Flags.hasNoSignedZeros())) &&
17244
17248
N1.getOpcode() == ISD::FADD) {
17245
17249
// X - (X + Y) -> -Y
@@ -17376,7 +17380,6 @@ SDValue DAGCombiner::visitFMUL(SDNode *N) {
17376
17380
ConstantFPSDNode *N1CFP = isConstOrConstSplatFP(N1, true);
17377
17381
EVT VT = N->getValueType(0);
17378
17382
SDLoc DL(N);
17379
- const TargetOptions &Options = DAG.getTarget().Options;
17380
17383
const SDNodeFlags Flags = N->getFlags();
17381
17384
SelectionDAG::FlagInserter FlagsInserter(DAG, N);
17382
17385
@@ -17400,7 +17403,8 @@ SDValue DAGCombiner::visitFMUL(SDNode *N) {
17400
17403
if (SDValue NewSel = foldBinOpIntoSelect(N))
17401
17404
return NewSel;
17402
17405
17403
- if (Options.UnsafeFPMath || Flags.hasAllowReassociation()) {
17406
+ if (DAG.getMachineFunction().hasUnsafeFPMath() ||
17407
+ Flags.hasAllowReassociation()) {
17404
17408
// fmul (fmul X, C1), C2 -> fmul X, C1 * C2
17405
17409
if (DAG.isConstantFPBuildVectorOrConstantFP(N1) &&
17406
17410
N0.getOpcode() == ISD::FMUL) {
@@ -17526,10 +17530,10 @@ template <class MatchContextClass> SDValue DAGCombiner::visitFMA(SDNode *N) {
17526
17530
ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1);
17527
17531
EVT VT = N->getValueType(0);
17528
17532
SDLoc DL(N);
17529
- const TargetOptions &Options = DAG.getTarget().Options;
17530
17533
// FMA nodes have flags that propagate to the created nodes.
17531
17534
SelectionDAG::FlagInserter FlagsInserter(DAG, N);
17532
17535
MatchContextClass matcher(DAG, TLI, N);
17536
+ bool UnsafeFPMath = DAG.getMachineFunction().hasUnsafeFPMath();
17533
17537
17534
17538
// Constant fold FMA.
17535
17539
if (SDValue C =
@@ -17552,8 +17556,8 @@ template <class MatchContextClass> SDValue DAGCombiner::visitFMA(SDNode *N) {
17552
17556
return matcher.getNode(ISD::FMA, DL, VT, NegN0, NegN1, N2);
17553
17557
}
17554
17558
17555
- // FIXME: use fast math flags instead of Options.UnsafeFPMath
17556
- if (Options. UnsafeFPMath) {
17559
+ // FIXME: use fast math flags instead of MachineFunction::hasUnsafeFPMath()
17560
+ if (UnsafeFPMath) {
17557
17561
if (N0CFP && N0CFP->isZero())
17558
17562
return N2;
17559
17563
if (N1CFP && N1CFP->isZero())
@@ -17571,8 +17575,7 @@ template <class MatchContextClass> SDValue DAGCombiner::visitFMA(SDNode *N) {
17571
17575
!DAG.isConstantFPBuildVectorOrConstantFP(N1))
17572
17576
return matcher.getNode(ISD::FMA, DL, VT, N1, N0, N2);
17573
17577
17574
- bool CanReassociate =
17575
- Options.UnsafeFPMath || N->getFlags().hasAllowReassociation();
17578
+ bool CanReassociate = UnsafeFPMath || N->getFlags().hasAllowReassociation();
17576
17579
if (CanReassociate) {
17577
17580
// (fma x, c1, (fmul x, c2)) -> (fmul x, c1+c2)
17578
17581
if (matcher.match(N2, ISD::FMUL) && N0 == N2.getOperand(0) &&
@@ -17667,7 +17670,7 @@ SDValue DAGCombiner::combineRepeatedFPDivisors(SDNode *N) {
17667
17670
// TODO: Limit this transform based on optsize/minsize - it always creates at
17668
17671
// least 1 extra instruction. But the perf win may be substantial enough
17669
17672
// that only minsize should restrict this.
17670
- bool UnsafeMath = DAG.getTarget ().Options.UnsafeFPMath ;
17673
+ bool UnsafeMath = DAG.getMachineFunction ().hasUnsafeFPMath() ;
17671
17674
const SDNodeFlags Flags = N->getFlags();
17672
17675
if (LegalDAG || (!UnsafeMath && !Flags.hasAllowReciprocal()))
17673
17676
return SDValue();
@@ -17744,6 +17747,7 @@ SDValue DAGCombiner::visitFDIV(SDNode *N) {
17744
17747
const TargetOptions &Options = DAG.getTarget().Options;
17745
17748
SDNodeFlags Flags = N->getFlags();
17746
17749
SelectionDAG::FlagInserter FlagsInserter(DAG, N);
17750
+ bool UnsafeFPMath = DAG.getMachineFunction().hasUnsafeFPMath();
17747
17751
17748
17752
if (SDValue R = DAG.simplifyFPBinop(N->getOpcode(), N0, N1, Flags))
17749
17753
return R;
@@ -17774,7 +17778,7 @@ SDValue DAGCombiner::visitFDIV(SDNode *N) {
17774
17778
// isn't too nasty (eg NaN, denormal, ...).
17775
17779
if (((st == APFloat::opOK && !Recip.isDenormal()) ||
17776
17780
(st == APFloat::opInexact &&
17777
- (Options. UnsafeFPMath || Flags.hasAllowReciprocal()))) &&
17781
+ (UnsafeFPMath || Flags.hasAllowReciprocal()))) &&
17778
17782
(!LegalOperations ||
17779
17783
// FIXME: custom lowering of ConstantFP might fail (see e.g. ARM
17780
17784
// backend)... we should handle this gracefully after Legalize.
@@ -17785,7 +17789,7 @@ SDValue DAGCombiner::visitFDIV(SDNode *N) {
17785
17789
DAG.getConstantFP(Recip, DL, VT));
17786
17790
}
17787
17791
17788
- if (Options. UnsafeFPMath || Flags.hasAllowReciprocal()) {
17792
+ if (UnsafeFPMath || Flags.hasAllowReciprocal()) {
17789
17793
// If this FDIV is part of a reciprocal square root, it may be folded
17790
17794
// into a target-specific square root estimate instruction.
17791
17795
if (N1.getOpcode() == ISD::FSQRT) {
@@ -17860,7 +17864,7 @@ SDValue DAGCombiner::visitFDIV(SDNode *N) {
17860
17864
17861
17865
// Fold X/Sqrt(X) -> Sqrt(X)
17862
17866
if ((Options.NoSignedZerosFPMath || Flags.hasNoSignedZeros()) &&
17863
- (Options. UnsafeFPMath || Flags.hasAllowReassociation()))
17867
+ (UnsafeFPMath || Flags.hasAllowReassociation()))
17864
17868
if (N1.getOpcode() == ISD::FSQRT && N0 == N1.getOperand(0))
17865
17869
return N1;
17866
17870
@@ -18356,7 +18360,7 @@ SDValue DAGCombiner::visitFP_ROUND(SDNode *N) {
18356
18360
// single-step fp_round we want to fold to.
18357
18361
// In other words, double rounding isn't the same as rounding.
18358
18362
// Also, this is a value preserving truncation iff both fp_round's are.
18359
- if (DAG.getTarget ().Options.UnsafeFPMath || N0IsTrunc)
18363
+ if (DAG.getMachineFunction ().hasUnsafeFPMath() || N0IsTrunc)
18360
18364
return DAG.getNode(
18361
18365
ISD::FP_ROUND, DL, VT, N0.getOperand(0),
18362
18366
DAG.getIntPtrConstant(NIsTrunc && N0IsTrunc, DL, /*isTarget=*/true));
0 commit comments