@@ -89,10 +89,6 @@ static cl::opt<bool> DisableFDivExpand(
8989 cl::ReallyHidden,
9090 cl::init(false ));
9191
92- static bool hasUnsafeFPMath (const Function &F) {
93- return F.getFnAttribute (" unsafe-fp-math" ).getValueAsBool ();
94- }
95-
9692class AMDGPUCodeGenPrepareImpl
9793 : public InstVisitor<AMDGPUCodeGenPrepareImpl, bool > {
9894public:
@@ -104,7 +100,6 @@ class AMDGPUCodeGenPrepareImpl
104100 const DominatorTree *DT;
105101 const UniformityInfo &UA;
106102 const DataLayout &DL;
107- const bool HasUnsafeFPMath;
108103 const bool HasFP32DenormalFlush;
109104 bool FlowChanged = false ;
110105 mutable Function *SqrtF32 = nullptr ;
@@ -117,7 +112,6 @@ class AMDGPUCodeGenPrepareImpl
117112 const DominatorTree *DT, const UniformityInfo &UA)
118113 : F(F), ST(TM.getSubtarget<GCNSubtarget>(F)), TM(TM), TLI(TLI), AC(AC),
119114 DT (DT), UA(UA), DL(F.getDataLayout()),
120- HasUnsafeFPMath(hasUnsafeFPMath(F)),
121115 HasFP32DenormalFlush(SIModeRegisterDefaults(F, ST).FP32Denormals ==
122116 DenormalMode::getPreserveSign()) {}
123117
@@ -637,8 +631,7 @@ bool AMDGPUCodeGenPrepareImpl::canOptimizeWithRsq(const FPMathOperator *SqrtOp,
637631 return false ;
638632
639633 // v_rsq_f32 gives 1ulp
640- return SqrtFMF.approxFunc () || HasUnsafeFPMath ||
641- SqrtOp->getFPAccuracy () >= 1 .0f ;
634+ return SqrtFMF.approxFunc () || SqrtOp->getFPAccuracy () >= 1 .0f ;
642635}
643636
644637Value *AMDGPUCodeGenPrepareImpl::optimizeWithRsq (
@@ -664,7 +657,7 @@ Value *AMDGPUCodeGenPrepareImpl::optimizeWithRsq(
664657 IRBuilder<>::FastMathFlagGuard Guard (Builder);
665658 Builder.setFastMathFlags (DivFMF | SqrtFMF);
666659
667- if ((DivFMF.approxFunc () && SqrtFMF.approxFunc ()) || HasUnsafeFPMath ||
660+ if ((DivFMF.approxFunc () && SqrtFMF.approxFunc ()) ||
668661 canIgnoreDenormalInput (Den, CtxI)) {
669662 Value *Result = Builder.CreateUnaryIntrinsic (Intrinsic::amdgcn_rsq, Den);
670663 // -1.0 / sqrt(x) -> fneg(rsq(x))
@@ -680,7 +673,7 @@ Value *AMDGPUCodeGenPrepareImpl::optimizeWithRsq(
680673// Optimize fdiv with rcp:
681674//
682675// 1/x -> rcp(x) when rcp is sufficiently accurate or inaccurate rcp is
683- // allowed with unsafe-fp-math or afn.
676+ // allowed with afn.
684677//
685678// a/b -> a*rcp(b) when arcp is allowed, and we only need provide ULP 1.0
686679Value *
@@ -803,9 +796,9 @@ Value *AMDGPUCodeGenPrepareImpl::visitFDivElement(
803796//
804797// With rcp:
805798// 1/x -> rcp(x) when rcp is sufficiently accurate or inaccurate rcp is
806- // allowed with unsafe-fp-math or afn.
799+ // allowed with afn.
807800//
808- // a/b -> a*rcp(b) when inaccurate rcp is allowed with unsafe-fp-math or afn.
801+ // a/b -> a*rcp(b) when inaccurate rcp is allowed with afn.
809802//
810803// With fdiv.fast:
811804// a/b -> fdiv.fast(a, b) when !fpmath >= 2.5ulp with denormals flushed.
@@ -843,7 +836,7 @@ bool AMDGPUCodeGenPrepareImpl::visitFDiv(BinaryOperator &FDiv) {
843836 RsqOp = SqrtOp->getOperand (0 );
844837 }
845838
846- // Inaccurate rcp is allowed with unsafe-fp-math or afn.
839+ // Inaccurate rcp is allowed with afn.
847840 //
848841 // Defer to codegen to handle this.
849842 //
@@ -852,7 +845,7 @@ bool AMDGPUCodeGenPrepareImpl::visitFDiv(BinaryOperator &FDiv) {
852845 // expansion of afn to codegen. The current interpretation is so aggressive we
853846 // don't need any pre-consideration here when we have better information. A
854847 // more conservative interpretation could use handling here.
855- const bool AllowInaccurateRcp = HasUnsafeFPMath || DivFMF.approxFunc ();
848+ const bool AllowInaccurateRcp = DivFMF.approxFunc ();
856849 if (!RsqOp && AllowInaccurateRcp)
857850 return false ;
858851
@@ -2026,7 +2019,7 @@ bool AMDGPUCodeGenPrepareImpl::visitSqrt(IntrinsicInst &Sqrt) {
20262019
20272020 // We're trying to handle the fast-but-not-that-fast case only. The lowering
20282021 // of fast llvm.sqrt will give the raw instruction anyway.
2029- if (SqrtFMF.approxFunc () || HasUnsafeFPMath )
2022+ if (SqrtFMF.approxFunc ())
20302023 return false ;
20312024
20322025 const float ReqdAccuracy = FPOp->getFPAccuracy ();
0 commit comments