[llvm] 0a2bde9 - [LVI] Drop requirement that modulus is constant
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 20 12:08:15 PST 2021
Author: Nikita Popov
Date: 2021-11-20T21:06:08+01:00
New Revision: 0a2bde94a06cea489c33004d66f574204c771031
URL: https://github.com/llvm/llvm-project/commit/0a2bde94a06cea489c33004d66f574204c771031
DIFF: https://github.com/llvm/llvm-project/commit/0a2bde94a06cea489c33004d66f574204c771031.diff
LOG: [LVI] Drop requirement that modulus is constant
If we're looking only at the lower bound, the actual modulus
doesn't matter. This is a leftover from when I wanted to consider
the upper bound as well, where the modulus does matter.
Added:
Modified:
llvm/lib/Analysis/LazyValueInfo.cpp
llvm/test/Transforms/CorrelatedValuePropagation/urem.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index 4d7a009402ec..5b5d48bf6fe5 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1127,8 +1127,7 @@ static ValueLatticeElement getValueFromICmpCondition(Value *Val, ICmpInst *ICI,
// If (X urem Modulus) >= C, then X >= C.
// TODO: An upper bound could be computed as well.
- const APInt *Modulus;
- if (match(LHS, m_URem(m_Specific(Val), m_APInt(Modulus))) &&
+ if (match(LHS, m_URem(m_Specific(Val), m_Value())) &&
match(RHS, m_APInt(C))) {
// Use the icmp region so we don't have to deal with
diff erent predicates.
ConstantRange CR = ConstantRange::makeExactICmpRegion(EdgePred, *C);
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/urem.ll b/llvm/test/Transforms/CorrelatedValuePropagation/urem.ll
index 0aa0971cad9d..579643e0d8a2 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/urem.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/urem.ll
@@ -163,9 +163,9 @@ define void @non_power_of_2(i24 %n) {
; (x urem 5) uge 2 implies x uge 2 on the true branch.
; We don't know anything about the lower bound on the false branch.
-define void @urem_implied_cond_uge(i8 %x) {
+define void @urem_implied_cond_uge(i8 %x, i8 %m) {
; CHECK-LABEL: @urem_implied_cond_uge(
-; CHECK-NEXT: [[U:%.*]] = urem i8 [[X:%.*]], 5
+; CHECK-NEXT: [[U:%.*]] = urem i8 [[X:%.*]], [[M:%.*]]
; CHECK-NEXT: [[C1:%.*]] = icmp uge i8 [[U]], 2
; CHECK-NEXT: br i1 [[C1]], label [[IF:%.*]], label [[ELSE:%.*]]
; CHECK: if:
@@ -187,7 +187,7 @@ define void @urem_implied_cond_uge(i8 %x) {
; CHECK-NEXT: call void @use(i1 [[C5_2]])
; CHECK-NEXT: ret void
;
- %u = urem i8 %x, 5
+ %u = urem i8 %x, %m
%c1 = icmp uge i8 %u, 2
br i1 %c1, label %if, label %else
@@ -269,9 +269,9 @@ else:
}
; (x urem 5) != 0 is the same as (x urem 5) >= 1 and implies x >= 1.
-define void @urem_implied_cond_ne_zero(i8 %x) {
+define void @urem_implied_cond_ne_zero(i8 %x, i8 %m) {
; CHECK-LABEL: @urem_implied_cond_ne_zero(
-; CHECK-NEXT: [[U:%.*]] = urem i8 [[X:%.*]], 5
+; CHECK-NEXT: [[U:%.*]] = urem i8 [[X:%.*]], [[M:%.*]]
; CHECK-NEXT: [[C1:%.*]] = icmp ne i8 [[U]], 0
; CHECK-NEXT: br i1 [[C1]], label [[IF:%.*]], label [[ELSE:%.*]]
; CHECK: if:
@@ -293,7 +293,7 @@ define void @urem_implied_cond_ne_zero(i8 %x) {
; CHECK-NEXT: call void @use(i1 [[C5_2]])
; CHECK-NEXT: ret void
;
- %u = urem i8 %x, 5
+ %u = urem i8 %x, %m
%c1 = icmp ne i8 %u, 0
br i1 %c1, label %if, label %else
@@ -322,9 +322,9 @@ else:
; (x urem 5) != 1 doesn't imply anything on the true branch. However, on the
; false branch (x urem 5) == 1 implies x >= 1.
-define void @urem_implied_cond_ne_non_zero(i8 %x) {
+define void @urem_implied_cond_ne_non_zero(i8 %x, i8 %m) {
; CHECK-LABEL: @urem_implied_cond_ne_non_zero(
-; CHECK-NEXT: [[U:%.*]] = urem i8 [[X:%.*]], 5
+; CHECK-NEXT: [[U:%.*]] = urem i8 [[X:%.*]], [[M:%.*]]
; CHECK-NEXT: [[C1:%.*]] = icmp ne i8 [[U]], 1
; CHECK-NEXT: br i1 [[C1]], label [[IF:%.*]], label [[ELSE:%.*]]
; CHECK: if:
@@ -346,7 +346,7 @@ define void @urem_implied_cond_ne_non_zero(i8 %x) {
; CHECK-NEXT: call void @use(i1 [[C5_2]])
; CHECK-NEXT: ret void
;
- %u = urem i8 %x, 5
+ %u = urem i8 %x, %m
%c1 = icmp ne i8 %u, 1
br i1 %c1, label %if, label %else
More information about the llvm-commits
mailing list