Skip to content

Commit 21836f4

Browse files
authored
[SelectionDAG] Remove UnsafeFPMath in LegalizeDAG (#146316)
These global flags hinder further improvements like [[RFC] Honor pragmas with -ffp-contract=fast](https://discourse.llvm.org/t/rfc-honor-pragmas-with-ffp-contract-fast) and pass concurrency support. Remove them incrementally.
1 parent 5223317 commit 21836f4

File tree

4 files changed

+2317
-141
lines changed

4 files changed

+2317
-141
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3853,7 +3853,7 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
38533853
break;
38543854
case ISD::FP_TO_FP16:
38553855
LLVM_DEBUG(dbgs() << "Legalizing FP_TO_FP16\n");
3856-
if (!TLI.useSoftFloat() && TM.Options.UnsafeFPMath) {
3856+
if (Node->getFlags().hasApproximateFuncs() && !TLI.useSoftFloat()) {
38573857
SDValue Op = Node->getOperand(0);
38583858
MVT SVT = Op.getSimpleValueType();
38593859
if ((SVT == MVT::f64 || SVT == MVT::f80) &&

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3923,11 +3923,15 @@ void SelectionDAGBuilder::visitFPTrunc(const User &I) {
39233923
// FPTrunc is never a no-op cast, no need to check
39243924
SDValue N = getValue(I.getOperand(0));
39253925
SDLoc dl = getCurSDLoc();
3926+
SDNodeFlags Flags;
3927+
if (auto *TruncInst = dyn_cast<FPMathOperator>(&I))
3928+
Flags.copyFMF(*TruncInst);
39263929
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
39273930
EVT DestVT = TLI.getValueType(DAG.getDataLayout(), I.getType());
39283931
setValue(&I, DAG.getNode(ISD::FP_ROUND, dl, DestVT, N,
39293932
DAG.getTargetConstant(
3930-
0, dl, TLI.getPointerTy(DAG.getDataLayout()))));
3933+
0, dl, TLI.getPointerTy(DAG.getDataLayout())),
3934+
Flags));
39313935
}
39323936

39333937
void SelectionDAGBuilder::visitFPExt(const User &I) {

0 commit comments

Comments
 (0)