[llvm-branch-commits] [llvm] 22dba70 - [AC] Handle (X+C1)<C2 assumes (PR48408)

Nikita Popov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Dec 13 12:04:44 PST 2020


Author: Nikita Popov
Date: 2020-12-13T21:00:32+01:00
New Revision: 22dba707b0fbf778466baef718cc536700b99df3

URL: https://github.com/llvm/llvm-project/commit/22dba707b0fbf778466baef718cc536700b99df3
DIFF: https://github.com/llvm/llvm-project/commit/22dba707b0fbf778466baef718cc536700b99df3.diff

LOG: [AC] Handle (X+C1)<C2 assumes (PR48408)

InstCombine canonicalizes X>C && X<C' style comparisons into
(X+C1)<C2. This type of expression is recognized by some analyses
like LVI, but currently not when used inside assumptions, because
AssumptionCache does not track affected values for it.

Added: 
    

Modified: 
    llvm/lib/Analysis/AssumptionCache.cpp
    llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/AssumptionCache.cpp b/llvm/lib/Analysis/AssumptionCache.cpp
index fdde5eac16b7..cb94f716bdb3 100644
--- a/llvm/lib/Analysis/AssumptionCache.cpp
+++ b/llvm/lib/Analysis/AssumptionCache.cpp
@@ -115,6 +115,14 @@ findAffectedValues(CallInst *CI,
       AddAffectedFromEq(A);
       AddAffectedFromEq(B);
     }
+
+    Value *X;
+    // Handle (A + C1) u< C2, which is the canonical form of A > C3 && A < C4,
+    // and recognized by LVI at least.
+    if (Pred == ICmpInst::ICMP_ULT &&
+        match(A, m_Add(m_Value(X), m_ConstantInt())) &&
+        match(B, m_ConstantInt()))
+      AddAffected(X);
   }
 }
 

diff  --git a/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll b/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
index 71cdbefc8942..b1e3bd334d91 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
@@ -577,9 +577,8 @@ define i1 @test_assume_cmp_with_offset(i64 %idx) {
 ; CHECK-NEXT:    [[IDX_OFF1:%.*]] = add i64 [[IDX:%.*]], -5
 ; CHECK-NEXT:    [[CMP1:%.*]] = icmp ult i64 [[IDX_OFF1]], 3
 ; CHECK-NEXT:    tail call void @llvm.assume(i1 [[CMP1]])
-; CHECK-NEXT:    [[IDX_OFF2:%.*]] = add i64 [[IDX]], -1
-; CHECK-NEXT:    [[CMP2:%.*]] = icmp ult i64 [[IDX_OFF2]], 10
-; CHECK-NEXT:    ret i1 [[CMP2]]
+; CHECK-NEXT:    [[IDX_OFF2:%.*]] = add nsw i64 [[IDX]], -1
+; CHECK-NEXT:    ret i1 true
 ;
   %idx.off1 = add i64 %idx, -5
   %cmp1 = icmp ult i64 %idx.off1, 3


        


More information about the llvm-branch-commits mailing list