-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SelectionDAGBuilder] Propagate fast-math flags to fpext #167574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SelectionDAGBuilder] Propagate fast-math flags to fpext #167574
Conversation
|
@llvm/pr-subscribers-backend-powerpc @llvm/pr-subscribers-llvm-selectiondag Author: Mikołaj Piróg (mikolaj-pirog) ChangesAs in title. Without this, fpext behaves in selectionDAG as always having no fmf flags. Full diff: https://github.com/llvm/llvm-project/pull/167574.diff 1 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 9baf72b266aa7..16f555b16a621 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -3976,7 +3976,10 @@ void SelectionDAGBuilder::visitFPExt(const User &I) {
SDValue N = getValue(I.getOperand(0));
EVT DestVT = DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
I.getType());
- setValue(&I, DAG.getNode(ISD::FP_EXTEND, getCurSDLoc(), DestVT, N));
+ SDNodeFlags Flags;
+ if (auto *TruncInst = dyn_cast<FPMathOperator>(&I))
+ Flags.copyFMF(*TruncInst);
+ setValue(&I, DAG.getNode(ISD::FP_EXTEND, getCurSDLoc(), DestVT, N, Flags));
}
void SelectionDAGBuilder::visitFPToUI(const User &I) {
|
|
I'm seeing no testing failures on this one, meaning no code path checks in meaningful way fmf on fpext nodes. I run into this issue while working on strengthening fmf semantics |
arsenm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be testable? fpext flags are new, I'd assume that would have covered this?
I don't think we have explicit testing for this stuff (i.e. if flags propagate correctly on DAG construction), I couldn't find an easy to test it either. I believe other flags get naturally tested if they work with tests for respective transformations. Would writing a unittest for it be an overkill? I've filled a PR that requires this fixes, so that could be repurposed as a test for it |
The brute force way would be use -stop-after=finalize-isel and check the MIR, but it would be better to have a transform dependent on the flags
That one's big and not obviously related to fpext, I'd rather test it here. Is there some other context the flag will do something? |
Some combines peek through FP_EXTEND to perform fmf rewrite, but none checks if FP_EXTEND has any flags. I could add this check to one of the combines and update the tests. |
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
The FPEXT in fdiv from other PR is a good candidate for testing this -- I've included checking arcp for FPEXT node here. One test caught the difference -- would that suffice for testing? |
| I.getType()); | ||
| setValue(&I, DAG.getNode(ISD::FP_EXTEND, getCurSDLoc(), DestVT, N)); | ||
| SDNodeFlags Flags; | ||
| if (auto *TruncInst = dyn_cast<FPMathOperator>(&I)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TruncInst is confusing here (I guess it has been copied from somewhere). You could perhaps all it Operator or FPExtInst or something, but it seems like FPOp is a common variable name when dyn_cast-ing to a FPMathOperator. So I would suggest FPOp.
As in title. Without this, fpext behaves in selectionDAG as always having no fast-math flags.