-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Reland][InstCombine] Fix FMF propagation in foldSelectIntoOp
#114499
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -529,9 +529,6 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal, | |
| if (!OpToFold) | ||
| return nullptr; | ||
|
|
||
| // TODO: We probably ought to revisit cases where the select and FP | ||
| // instructions have different flags and add tests to ensure the | ||
| // behaviour is correct. | ||
| FastMathFlags FMF; | ||
| if (isa<FPMathOperator>(&SI)) | ||
| FMF = SI.getFastMathFlags(); | ||
|
|
@@ -564,6 +561,14 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal, | |
| BinaryOperator *BO = | ||
| BinaryOperator::Create(TVI->getOpcode(), FalseVal, NewSel); | ||
| BO->copyIRFlags(TVI); | ||
| if (isa<FPMathOperator>(&SI)) { | ||
| // Merge poison generating flags from the select. | ||
| BO->setHasNoNaNs(BO->hasNoNaNs() && FMF.noNaNs()); | ||
| BO->setHasNoInfs(BO->hasNoInfs() && FMF.noInfs()); | ||
| // Merge no-signed-zeros flag from the select. | ||
| // Otherwise we may produce zeros with different sign. | ||
| BO->setHasNoSignedZeros(BO->hasNoSignedZeros() && FMF.noSignedZeros()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No signed zeros aren't poison generating. But I'm not sure why it's correct to preserve reassoc
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah. It is a value-mismatch issue.
Proof: We don't set |
||
| } | ||
| return BO; | ||
| }; | ||
|
|
||
|
|
||
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.
We do need better API for this intersect of value flag pattern