-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[ValueTracking] Pass changed predicate SignedLPred
to isImpliedByMatchingCmp
#124271
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
Conversation
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, thanks!
@llvm/pr-subscribers-llvm-analysis Author: DianQK (DianQK) ChangesFixes #124267. Since we are using the new predicate, we should also update the parameters of Full diff: https://github.com/llvm/llvm-project/pull/124271.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 38f88850be0f18..3ffdf9d8e958ef 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -9494,7 +9494,7 @@ isImpliedCondICmps(const ICmpInst *LHS, CmpPredicate RPred, const Value *R0,
SignedLPred == ICmpInst::ICMP_SGE) &&
match(R0, m_NSWSub(m_Specific(L0), m_Specific(L1)))) {
if (match(R1, m_NonPositive()) &&
- ICmpInst::isImpliedByMatchingCmp(LPred, RPred) == false)
+ ICmpInst::isImpliedByMatchingCmp(SignedLPred, RPred) == false)
return false;
}
@@ -9504,7 +9504,7 @@ isImpliedCondICmps(const ICmpInst *LHS, CmpPredicate RPred, const Value *R0,
SignedLPred == ICmpInst::ICMP_SLE) &&
match(R0, m_NSWSub(m_Specific(L0), m_Specific(L1)))) {
if (match(R1, m_NonNegative()) &&
- ICmpInst::isImpliedByMatchingCmp(LPred, RPred) == true)
+ ICmpInst::isImpliedByMatchingCmp(SignedLPred, RPred) == true)
return true;
}
diff --git a/llvm/test/Analysis/ValueTracking/implied-condition-samesign.ll b/llvm/test/Analysis/ValueTracking/implied-condition-samesign.ll
index 0e6db403512aee..ae97a401e425d8 100644
--- a/llvm/test/Analysis/ValueTracking/implied-condition-samesign.ll
+++ b/llvm/test/Analysis/ValueTracking/implied-condition-samesign.ll
@@ -292,3 +292,51 @@ taken:
end:
ret i32 0
}
+
+define i1 @gt_sub_nsw_ult(i8 %L0, i8 %L1, i1 %V) {
+; CHECK-LABEL: define i1 @gt_sub_nsw_ult(
+; CHECK-SAME: i8 [[L0:%.*]], i8 [[L1:%.*]], i1 [[V:%.*]]) {
+; CHECK-NEXT: [[LHS:%.*]] = icmp samesign ugt i8 [[L0]], [[L1]]
+; CHECK-NEXT: br i1 [[LHS]], label %[[LHS_TRUE:.*]], label %[[LHS_FALSE:.*]]
+; CHECK: [[LHS_TRUE]]:
+; CHECK-NEXT: [[R0:%.*]] = sub nsw i8 [[L0]], [[L1]]
+; CHECK-NEXT: [[RHS:%.*]] = icmp ult i8 [[R0]], -1
+; CHECK-NEXT: ret i1 [[RHS]]
+; CHECK: [[LHS_FALSE]]:
+; CHECK-NEXT: ret i1 [[V]]
+;
+ %LHS = icmp samesign ugt i8 %L0, %L1
+ br i1 %LHS, label %LHS_true, label %LHS_false
+
+LHS_true:
+ %R0 = sub nsw i8 %L0, %L1
+ %RHS = icmp ult i8 %R0, -1
+ ret i1 %RHS
+
+LHS_false:
+ ret i1 %V
+}
+
+define i1 @ul_sub_nsw_ult(i8 %L0, i8 %L1, i1 %V) {
+; CHECK-LABEL: define i1 @ul_sub_nsw_ult(
+; CHECK-SAME: i8 [[L0:%.*]], i8 [[L1:%.*]], i1 [[V:%.*]]) {
+; CHECK-NEXT: [[LHS:%.*]] = icmp samesign ult i8 [[L0]], [[L1]]
+; CHECK-NEXT: br i1 [[LHS]], label %[[LHS_TRUE:.*]], label %[[LHS_FALSE:.*]]
+; CHECK: [[LHS_TRUE]]:
+; CHECK-NEXT: [[R0:%.*]] = sub nsw i8 [[L0]], [[L1]]
+; CHECK-NEXT: [[RHS:%.*]] = icmp ult i8 [[R0]], 1
+; CHECK-NEXT: ret i1 [[RHS]]
+; CHECK: [[LHS_FALSE]]:
+; CHECK-NEXT: ret i1 [[V]]
+;
+ %LHS = icmp samesign ult i8 %L0, %L1
+ br i1 %LHS, label %LHS_true, label %LHS_false
+
+LHS_true:
+ %R0 = sub nsw i8 %L0, %L1
+ %RHS = icmp ult i8 %R0, 1
+ ret i1 %RHS
+
+LHS_false:
+ ret i1 %V
+}
|
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, thanks!
Fixes #124267.
Since we are using the new predicate, we should also update the parameters of
isImpliedByMatchingCmp
.