Skip to content

Commit 1ca40ff

Browse files
committed
Remove UnsafeFPMath in *ISelLowering.cpp
1 parent 1f7d136 commit 1ca40ff

File tree

12 files changed

+369
-1377
lines changed

12 files changed

+369
-1377
lines changed

llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,7 @@ bool AMDGPUTargetLowering::allowApproxFunc(const SelectionDAG &DAG,
26342634
if (Flags.hasApproximateFuncs())
26352635
return true;
26362636
auto &Options = DAG.getTarget().Options;
2637-
return Options.UnsafeFPMath || Options.ApproxFuncFPMath;
2637+
return Options.ApproxFuncFPMath;
26382638
}
26392639

26402640
bool AMDGPUTargetLowering::needsDenormHandlingF32(const SelectionDAG &DAG,
@@ -2757,7 +2757,7 @@ SDValue AMDGPUTargetLowering::LowerFLOGCommon(SDValue Op,
27572757

27582758
const auto &Options = getTargetMachine().Options;
27592759
if (VT == MVT::f16 || Flags.hasApproximateFuncs() ||
2760-
Options.ApproxFuncFPMath || Options.UnsafeFPMath) {
2760+
Options.ApproxFuncFPMath) {
27612761

27622762
if (VT == MVT::f16 && !Subtarget->has16BitInsts()) {
27632763
// Log and multiply in f32 is good enough for f16.
@@ -3585,7 +3585,7 @@ SDValue AMDGPUTargetLowering::LowerFP_TO_FP16(SDValue Op, SelectionDAG &DAG) con
35853585
if (N0.getValueType() == MVT::f32)
35863586
return DAG.getNode(AMDGPUISD::FP_TO_FP16, DL, Op.getValueType(), N0);
35873587

3588-
if (getTargetMachine().Options.UnsafeFPMath) {
3588+
if (Op->getFlags().hasApproximateFuncs()) {
35893589
// There is a generic expand for FP_TO_FP16 with unsafe fast math.
35903590
return SDValue();
35913591
}

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7199,7 +7199,7 @@ SDValue SITargetLowering::lowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const {
71997199
SDValue Trunc = DAG.getNode(ISD::TRUNCATE, DL, MVT::i16, FpToFp16);
72007200
return DAG.getNode(ISD::BITCAST, DL, MVT::f16, Trunc);
72017201
}
7202-
if (getTargetMachine().Options.UnsafeFPMath) {
7202+
if (Op->getFlags().hasApproximateFuncs()) {
72037203
SDValue Flags = Op.getOperand(1);
72047204
SDValue Src32 = DAG.getNode(ISD::FP_ROUND, DL, MVT::f32, Src, Flags);
72057205
return DAG.getNode(ISD::FP_ROUND, DL, MVT::f16, Src32, Flags);
@@ -11294,8 +11294,7 @@ SDValue SITargetLowering::lowerFastUnsafeFDIV(SDValue Op,
1129411294
EVT VT = Op.getValueType();
1129511295
const SDNodeFlags Flags = Op->getFlags();
1129611296

11297-
bool AllowInaccurateRcp =
11298-
Flags.hasApproximateFuncs() || DAG.getTarget().Options.UnsafeFPMath;
11297+
bool AllowInaccurateRcp = Flags.hasApproximateFuncs();
1129911298

1130011299
if (const ConstantFPSDNode *CLHS = dyn_cast<ConstantFPSDNode>(LHS)) {
1130111300
// Without !fpmath accuracy information, we can't do more because we don't
@@ -11314,7 +11313,7 @@ SDValue SITargetLowering::lowerFastUnsafeFDIV(SDValue Op,
1131411313

1131511314
// 1.0 / sqrt(x) -> rsq(x)
1131611315

11317-
// XXX - Is UnsafeFPMath sufficient to do this for f64? The maximum ULP
11316+
// XXX - Is afn sufficient to do this for f64? The maximum ULP
1131811317
// error seems really high at 2^29 ULP.
1131911318
// 1.0 / x -> rcp(x)
1132011319
return DAG.getNode(AMDGPUISD::RCP, SL, VT, RHS);
@@ -11348,8 +11347,7 @@ SDValue SITargetLowering::lowerFastUnsafeFDIV64(SDValue Op,
1134811347
EVT VT = Op.getValueType();
1134911348
const SDNodeFlags Flags = Op->getFlags();
1135011349

11351-
bool AllowInaccurateDiv =
11352-
Flags.hasApproximateFuncs() || DAG.getTarget().Options.UnsafeFPMath;
11350+
bool AllowInaccurateDiv = Flags.hasApproximateFuncs();
1135311351
if (!AllowInaccurateDiv)
1135411352
return SDValue();
1135511353

@@ -14601,7 +14599,7 @@ unsigned SITargetLowering::getFusedOpcode(const SelectionDAG &DAG,
1460114599
return ISD::FMAD;
1460214600

1460314601
const TargetOptions &Options = DAG.getTarget().Options;
14604-
if ((Options.AllowFPOpFusion == FPOpFusion::Fast || Options.UnsafeFPMath ||
14602+
if ((Options.AllowFPOpFusion == FPOpFusion::Fast ||
1460514603
(N0->getFlags().hasAllowContract() &&
1460614604
N1->getFlags().hasAllowContract())) &&
1460714605
isFMAFasterThanFMulAndFAdd(DAG.getMachineFunction(), VT)) {
@@ -15724,9 +15722,9 @@ SDValue SITargetLowering::performFMACombine(SDNode *N,
1572415722

1572515723
// fdot2_f32_f16 always flushes fp32 denormal operand and output to zero,
1572615724
// regardless of the denorm mode setting. Therefore,
15727-
// unsafe-fp-math/fp-contract is sufficient to allow generating fdot2.
15725+
// fp-contract is sufficient to allow generating fdot2.
1572815726
const TargetOptions &Options = DAG.getTarget().Options;
15729-
if (Options.AllowFPOpFusion == FPOpFusion::Fast || Options.UnsafeFPMath ||
15727+
if (Options.AllowFPOpFusion == FPOpFusion::Fast ||
1573015728
(N->getFlags().hasAllowContract() &&
1573115729
FMA->getFlags().hasAllowContract())) {
1573215730
Op1 = Op1.getOperand(0);

llvm/test/CodeGen/AMDGPU/fdiv.f16.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ entry:
17021702
%gep.r = getelementptr inbounds half, ptr addrspace(1) %r, i64 %tid.ext
17031703
%a.val = load volatile half, ptr addrspace(1) %gep.a
17041704
%b.val = load volatile half, ptr addrspace(1) %gep.b
1705-
%r.val = fdiv half %a.val, %b.val
1705+
%r.val = fdiv afn half %a.val, %b.val
17061706
store half %r.val, ptr addrspace(1) %gep.r
17071707
ret void
17081708
}
@@ -2475,4 +2475,4 @@ declare <2 x half> @llvm.sqrt.v2f16(<2 x half>) #2
24752475

24762476
attributes #0 = { nounwind }
24772477
attributes #1 = { nounwind readnone }
2478-
attributes #2 = { nounwind "unsafe-fp-math"="true" }
2478+
attributes #2 = { nounwind }

0 commit comments

Comments
 (0)