[llvm] c546b53 - [ValueTracking] Pass changed predicate `SignedLPred` to `isImpliedByMatchingCmp` (#124271)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 24 07:02:55 PST 2025
Author: DianQK
Date: 2025-01-24T23:02:50+08:00
New Revision: c546b5317c518987a5f45dd4c4d25321a955c758
URL: https://github.com/llvm/llvm-project/commit/c546b5317c518987a5f45dd4c4d25321a955c758
DIFF: https://github.com/llvm/llvm-project/commit/c546b5317c518987a5f45dd4c4d25321a955c758.diff
LOG: [ValueTracking] Pass changed predicate `SignedLPred` to `isImpliedByMatchingCmp` (#124271)
Fixes #124267.
Since we are using the new predicate, we should also update the
parameters of `isImpliedByMatchingCmp`.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Analysis/ValueTracking/implied-condition-samesign.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 264fedd6b66b98..eba728c7c8c360 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..9a0591245fae0e 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 @lt_sub_nsw_ult(i8 %L0, i8 %L1, i1 %V) {
+; CHECK-LABEL: define i1 @lt_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
+}
More information about the llvm-commits
mailing list