-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InstCombine] Relax guard against FP min/max in select fold #143144
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FCmp's equality and commutativity predicates do not work with min/max semantics Closes llvm#142711
@llvm/pr-subscribers-llvm-transforms Author: Acthink Yang (Acthink-Yang) ChangesFCmp's equality and commutativity predicates do not work with min/max semantics Closes #142711 Full diff: https://github.com/llvm/llvm-project/pull/143144.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 439a86d951a83..c85abd9b26d61 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1729,7 +1729,8 @@ Instruction *InstCombinerImpl::FoldOpIntoSelect(Instruction &Op, SelectInst *SI,
if (auto *CI = dyn_cast<FCmpInst>(SI->getCondition())) {
if (CI->hasOneUse()) {
Value *Op0 = CI->getOperand(0), *Op1 = CI->getOperand(1);
- if ((TV == Op0 && FV == Op1) || (FV == Op0 && TV == Op1))
+ if (((TV == Op0 && FV == Op1) || (FV == Op0 && TV == Op1)) &&
+ !CI->isEquality() && !CI->isCommutative())
return nullptr;
}
}
diff --git a/llvm/test/Transforms/InstCombine/fcmp-select.ll b/llvm/test/Transforms/InstCombine/fcmp-select.ll
index 408bc1cdc268f..bf08fbfc27302 100644
--- a/llvm/test/Transforms/InstCombine/fcmp-select.ll
+++ b/llvm/test/Transforms/InstCombine/fcmp-select.ll
@@ -268,3 +268,14 @@ define i1 @test_fcmp_select_var_const_unordered(double %x, double %y) {
%cmp2 = fcmp ugt double %sel, 0x3E80000000000000
ret i1 %cmp2
}
+
+define i1 @test_fcmp_ord_select_fcmp_oeq_var_const(double %x) {
+; CHECK-LABEL: @test_fcmp_ord_select_fcmp_oeq_var_const(
+; CHECK-NEXT: [[CMP1:%.*]] = fcmp oeq double [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: ret i1 [[CMP1]]
+;
+ %cmp1 = fcmp ord double %x, 0.000000e+00
+ %sel = select i1 %cmp1, double %x, double 0.000000e+00
+ %cmp2 = fcmp oeq double %sel, 1.000000e+00
+ ret i1 %cmp2
+}
|
dtcxzyw
reviewed
Jun 6, 2025
Co-authored-by: Yingwei Zheng <[email protected]>
This was referenced Jun 6, 2025
dtcxzyw
approved these changes
Jun 6, 2025
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.
LGTM w/ a nit.
nikic
reviewed
Jun 6, 2025
Co-authored-by: Yingwei Zheng <[email protected]>
rorth
pushed a commit
to rorth/llvm-project
that referenced
this pull request
Jun 11, 2025
) FCmp's commutativity predicates do not work with min/max semantics Closes llvm#142711
DhruvSrivastavaX
pushed a commit
to DhruvSrivastavaX/lldb-for-aix
that referenced
this pull request
Jun 12, 2025
) FCmp's commutativity predicates do not work with min/max semantics Closes llvm#142711
tomtor
pushed a commit
to tomtor/llvm-project
that referenced
this pull request
Jun 14, 2025
) FCmp's commutativity predicates do not work with min/max semantics Closes llvm#142711
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
llvm:instcombine
Covers the InstCombine, InstSimplify and AggressiveInstCombine passes
llvm:transforms
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
FCmp's commutativity predicates do not work with min/max semantics
Closes #142711