Skip to content

Conversation

@mikolaj-pirog
Copy link
Member

@mikolaj-pirog mikolaj-pirog commented Nov 11, 2025

As in title. Without this, fpext behaves in selectionDAG as always having no fast-math flags.

@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Nov 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 11, 2025

@llvm/pr-subscribers-backend-powerpc

@llvm/pr-subscribers-llvm-selectiondag

Author: Mikołaj Piróg (mikolaj-pirog)

Changes

As 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:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+4-1)
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) {

@mikolaj-pirog
Copy link
Member Author

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

Copy link
Contributor

@arsenm arsenm left a 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?

@mikolaj-pirog
Copy link
Member Author

mikolaj-pirog commented Nov 11, 2025

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

@arsenm
Copy link
Contributor

arsenm commented Nov 12, 2025

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?

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

I've filled a PR that requires this fixes, so that could be repurposed as a test for it

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?

@mikolaj-pirog
Copy link
Member Author

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?

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

I've filled a PR that requires this fixes, so that could be repurposed as a test for it

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. DAGCombiner::isContractableFMUL is one of these combines.

@github-actions
Copy link

github-actions bot commented Nov 13, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@mikolaj-pirog
Copy link
Member Author

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?

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

I've filled a PR that requires this fixes, so that could be repurposed as a test for it

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?

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?

@mikolaj-pirog mikolaj-pirog requested a review from arsenm November 13, 2025 13:41
@arsenm arsenm merged commit e7b41df into llvm:main Nov 15, 2025
10 checks passed
I.getType());
setValue(&I, DAG.getNode(ISD::FP_EXTEND, getCurSDLoc(), DestVT, N));
SDNodeFlags Flags;
if (auto *TruncInst = dyn_cast<FPMathOperator>(&I))
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:PowerPC llvm:SelectionDAG SelectionDAGISel as well

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants