Skip to content

Commit a56071f

Browse files
committed
[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.
1 parent 708999e commit a56071f

File tree

2 files changed

+2
-11
lines changed

2 files changed

+2
-11
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9891,7 +9891,7 @@ const SCEV *ScalarEvolution::computeSCEVAtScope(const SCEV *V, const Loop *L) {
98919891
// Do we have a loop invariant value flowing around the backedge
98929892
// for a loop which must execute the backedge?
98939893
if (!isa<SCEVCouldNotCompute>(BackedgeTakenCount) &&
9894-
isKnownPositive(BackedgeTakenCount) &&
9894+
isKnownNonZero(BackedgeTakenCount) &&
98959895
PN->getNumIncomingValues() == 2) {
98969896

98979897
unsigned InLoopPred =

llvm/test/Transforms/IndVarSimplify/exit_value_tests.ll

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,7 @@ loopexit:
172172
define i32 @unroll_phi_select_constant_nonzero_large_btc(i32 %arg1, i32 %arg2) {
173173
; CHECK-LABEL: @unroll_phi_select_constant_nonzero_large_btc(
174174
; CHECK-NEXT: entry:
175-
; CHECK-NEXT: br label [[LOOP:%.*]]
176-
; CHECK: loop:
177-
; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LOOP]] ]
178-
; CHECK-NEXT: [[SELECTOR:%.*]] = phi i32 [ [[ARG1:%.*]], [[ENTRY]] ], [ [[ARG2:%.*]], [[LOOP]] ]
179-
; CHECK-NEXT: [[I_NEXT]] = add nuw i32 [[I]], 1
180-
; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[I]], -42
181-
; CHECK-NEXT: br i1 [[C]], label [[LOOP]], label [[LOOPEXIT:%.*]]
182-
; CHECK: loopexit:
183-
; CHECK-NEXT: [[SELECTOR_LCSSA:%.*]] = phi i32 [ [[SELECTOR]], [[LOOP]] ]
184-
; CHECK-NEXT: ret i32 [[SELECTOR_LCSSA]]
175+
; CHECK-NEXT: ret i32 [[ARG2:%.*]]
185176
;
186177
entry:
187178
br label %loop

0 commit comments

Comments
 (0)