-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Recommit "[ConstraintElim] Simplify cmp after uadd.sat/usub.sat (#135603)" #136467
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
el-ev
merged 7 commits into
main
from
users/el-ev/04-20-_recommit_constraintelim_simplify_cmp_after_uadd.sat_usub.sat_135603_
Apr 30, 2025
Merged
Recommit "[ConstraintElim] Simplify cmp after uadd.sat/usub.sat (#135603)" #136467
el-ev
merged 7 commits into
main
from
users/el-ev/04-20-_recommit_constraintelim_simplify_cmp_after_uadd.sat_usub.sat_135603_
Apr 30, 2025
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
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-llvm-transforms Author: Iris (el-ev) ChangesFull diff: https://github.com/llvm/llvm-project/pull/136467.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 8684420b73671..9fd6b067debdf 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -1139,6 +1139,8 @@ void State::addInfoFor(BasicBlock &BB) {
// when simplifying uses of the min/max intrinsics.
[[fallthrough]];
case Intrinsic::abs:
+ case Intrinsic::uadd_sat:
+ case Intrinsic::usub_sat:
if (!isGuaranteedNotToBePoison(&I))
break;
WorkList.push_back(FactOrCheck::getInstFact(DT.getNode(&BB), &I));
@@ -1896,6 +1898,20 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT, LoopInfo &LI,
AddFact(Pred, MinMax, MinMax->getRHS());
continue;
}
+ if (auto *USatI = dyn_cast<SaturatingInst>(CB.Inst)) {
+ switch (USatI->getIntrinsicID()) {
+ default:
+ llvm_unreachable("Unexpected intrinsic.");
+ case Intrinsic::uadd_sat:
+ AddFact(ICmpInst::ICMP_UGE, USatI, USatI->getLHS());
+ AddFact(ICmpInst::ICMP_UGE, USatI, USatI->getRHS());
+ break;
+ case Intrinsic::usub_sat:
+ AddFact(ICmpInst::ICMP_ULE, USatI, USatI->getLHS());
+ break;
+ }
+ continue;
+ }
}
Value *A = nullptr, *B = nullptr;
diff --git a/llvm/test/Transforms/ConstraintElimination/uadd-usub-sat.ll b/llvm/test/Transforms/ConstraintElimination/uadd-usub-sat.ll
index 42bbe67024e58..c19a0548d78b2 100644
--- a/llvm/test/Transforms/ConstraintElimination/uadd-usub-sat.ll
+++ b/llvm/test/Transforms/ConstraintElimination/uadd-usub-sat.ll
@@ -8,9 +8,7 @@ define i1 @uadd_sat_uge(i64 noundef %a, i64 noundef %b) {
; CHECK-LABEL: define i1 @uadd_sat_uge(
; CHECK-SAME: i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) {
; CHECK-NEXT: [[ADD_SAT:%.*]] = call i64 @llvm.uadd.sat.i64(i64 [[A]], i64 [[B]])
-; CHECK-NEXT: [[CMP1:%.*]] = icmp uge i64 [[ADD_SAT]], [[A]]
-; CHECK-NEXT: [[CMP2:%.*]] = icmp uge i64 [[ADD_SAT]], [[B]]
-; CHECK-NEXT: [[CMP:%.*]] = and i1 [[CMP1]], [[CMP2]]
+; CHECK-NEXT: [[CMP:%.*]] = and i1 true, true
; CHECK-NEXT: ret i1 [[CMP]]
;
%add.sat = call i64 @llvm.uadd.sat.i64(i64 %a, i64 %b)
@@ -24,8 +22,7 @@ define i1 @usub_sat_ule_lhs(i64 noundef %a, i64 noundef %b) {
; CHECK-LABEL: define i1 @usub_sat_ule_lhs(
; CHECK-SAME: i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) {
; CHECK-NEXT: [[SUB_SAT:%.*]] = call i64 @llvm.usub.sat.i64(i64 [[A]], i64 [[B]])
-; CHECK-NEXT: [[CMP:%.*]] = icmp ule i64 [[SUB_SAT]], [[A]]
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 true
;
%sub.sat = call i64 @llvm.usub.sat.i64(i64 %a, i64 %b)
%cmp = icmp ule i64 %sub.sat, %a
|
dtcxzyw
approved these changes
Apr 21, 2025
…_check_before_adding_intrinsic_facts
…re_adding_intrinsic_facts' into users/el-ev/04-20-_recommit_constraintelim_simplify_cmp_after_uadd.sat_usub.sat_135603_
…re_adding_intrinsic_facts' into users/el-ev/04-20-_recommit_constraintelim_simplify_cmp_after_uadd.sat_usub.sat_135603_
Merge activity
|
Base automatically changed from
users/el-ev/04-18-_constraintelim_fix_poison_check_before_adding_intrinsic_facts
to
main
April 30, 2025 13:46
…implify_cmp_after_uadd.sat_usub.sat_135603_
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
IanWood1
pushed a commit
to IanWood1/llvm-project
that referenced
this pull request
May 6, 2025
GeorgeARM
pushed a commit
to GeorgeARM/llvm-project
that referenced
this pull request
May 7, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.