[llvm] a56071f - [SCEV] Don't require positive BTC when non-zero is sufficient

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 9 05:42:21 PDT 2023


Author: Nikita Popov
Date: 2023-10-09T14:42:09+02:00
New Revision: a56071ffb7f647a41e4b24ff4c2e70d6c63f40b7

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

LOG: [SCEV] Don't require positive BTC when non-zero is sufficient

The only thing we care about here is that we don't exit on the
first iteration. Whether the BTC is large enough to overflow the
signed integer space is not relevant.

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp
    llvm/test/Transforms/IndVarSimplify/exit_value_tests.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 7c234fa309a0c29..ffa6cd746b25d47 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -9891,7 +9891,7 @@ const SCEV *ScalarEvolution::computeSCEVAtScope(const SCEV *V, const Loop *L) {
         // Do we have a loop invariant value flowing around the backedge
         // for a loop which must execute the backedge?
         if (!isa<SCEVCouldNotCompute>(BackedgeTakenCount) &&
-            isKnownPositive(BackedgeTakenCount) &&
+            isKnownNonZero(BackedgeTakenCount) &&
             PN->getNumIncomingValues() == 2) {
 
           unsigned InLoopPred =

diff  --git a/llvm/test/Transforms/IndVarSimplify/exit_value_tests.ll b/llvm/test/Transforms/IndVarSimplify/exit_value_tests.ll
index 32a02c6aa9e6efe..66a4cbbb23b0113 100644
--- a/llvm/test/Transforms/IndVarSimplify/exit_value_tests.ll
+++ b/llvm/test/Transforms/IndVarSimplify/exit_value_tests.ll
@@ -172,16 +172,7 @@ loopexit:
 define i32 @unroll_phi_select_constant_nonzero_large_btc(i32 %arg1, i32 %arg2) {
 ; CHECK-LABEL: @unroll_phi_select_constant_nonzero_large_btc(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    br label [[LOOP:%.*]]
-; CHECK:       loop:
-; CHECK-NEXT:    [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
-; CHECK-NEXT:    [[SELECTOR:%.*]] = phi i32 [ [[ARG1:%.*]], [[ENTRY]] ], [ [[ARG2:%.*]], [[LOOP]] ]
-; CHECK-NEXT:    [[I_NEXT]] = add nuw i32 [[I]], 1
-; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[I]], -42
-; CHECK-NEXT:    br i1 [[C]], label [[LOOP]], label [[LOOPEXIT:%.*]]
-; CHECK:       loopexit:
-; CHECK-NEXT:    [[SELECTOR_LCSSA:%.*]] = phi i32 [ [[SELECTOR]], [[LOOP]] ]
-; CHECK-NEXT:    ret i32 [[SELECTOR_LCSSA]]
+; CHECK-NEXT:    ret i32 [[ARG2:%.*]]
 ;
 entry:
   br label %loop


        


More information about the llvm-commits mailing list