Skip to content

Commit c354c6b

Browse files
committed
[SCEV] Add function to compute minium of countable exits.
This patch introduces getBackedgeTakenCountForCountableExits and a predicated version to compute the minimum of the countable exits. The intended use for this is loop access analysis for loops with uncountable exits. When analyzing dependences and computing runtime checks, we need the smallest upper bound on the number of iterations. In terms of memory safety, it shouldn't matter if any uncomputable exits leave the loop, as long as we prove that there are no dependences given the minimum of the countable exits. The same should apply also for generating runtime checks.
1 parent 0f08ef1 commit c354c6b

15 files changed

+85
-8
lines changed

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,16 @@ class ScalarEvolution {
912912
return getBackedgeTakenCount(L, SymbolicMaximum);
913913
}
914914

915+
/// When successful, return the minimum of the exit counts for all countable exits, ignoring uncountable exits. This is an upper bound on the number of iterations of the loop.
916+
const SCEV *getBackedgeTakenCountForCountableExits(const Loop *L);
917+
918+
/// Similar to getBackedgeTakenCountForCountableExits, except it will add a set of
919+
/// SCEV predicates to Predicates that are required to be true in order for
920+
/// the answer to be correct. Predicates can be checked with run-time
921+
/// checks and can be used to perform loop versioning.
922+
const SCEV *getPredicatedBackedgeTakenCountForCountableExits(
923+
const Loop *L, SmallVector<const SCEVPredicate *, 4> &Predicates);
924+
915925
/// Return true if the backedge taken count is either the value returned by
916926
/// getConstantMaxBackedgeTakenCount or zero.
917927
bool isBackedgeTakenCountMaxOrZero(const Loop *L);
@@ -1531,8 +1541,9 @@ class ScalarEvolution {
15311541
/// If we allowed SCEV predicates to be generated when populating this
15321542
/// vector, this information can contain them and therefore a
15331543
/// SCEVPredicate argument should be added to getExact.
1534-
const SCEV *getExact(const Loop *L, ScalarEvolution *SE,
1535-
SmallVector<const SCEVPredicate *, 4> *Predicates = nullptr) const;
1544+
const SCEV *
1545+
getExact(const Loop *L, ScalarEvolution *SE, bool SkipUncountable = false,
1546+
SmallVector<const SCEVPredicate *, 4> *Predicates = nullptr) const;
15361547

15371548
/// Return the number of times this loop exit may fall through to the back
15381549
/// edge, or SCEVCouldNotCompute. The loop is guaranteed not to exit via
@@ -2316,6 +2327,9 @@ class PredicatedScalarEvolution {
23162327
/// Get the (predicated) backedge count for the analyzed loop.
23172328
const SCEV *getBackedgeTakenCount();
23182329

2330+
// Get the (predicated) minimum of the exit counts for all countable exits, ignoring uncountable exits.
2331+
const SCEV *getBackedgeTakenCountForCountableExits();
2332+
23192333
/// Adds a new predicate.
23202334
void addPredicate(const SCEVPredicate &Pred);
23212335

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8279,7 +8279,17 @@ const SCEV *ScalarEvolution::getExitCount(const Loop *L,
82798279
const SCEV *
82808280
ScalarEvolution::getPredicatedBackedgeTakenCount(const Loop *L,
82818281
SmallVector<const SCEVPredicate *, 4> &Preds) {
8282-
return getPredicatedBackedgeTakenInfo(L).getExact(L, this, &Preds);
8282+
return getPredicatedBackedgeTakenInfo(L).getExact(L, this, false, &Preds);
8283+
}
8284+
8285+
const SCEV *
8286+
ScalarEvolution::getBackedgeTakenCountForCountableExits(const Loop *L) {
8287+
return getBackedgeTakenInfo(L).getExact(L, this, true);
8288+
}
8289+
8290+
const SCEV *ScalarEvolution::getPredicatedBackedgeTakenCountForCountableExits(
8291+
const Loop *L, SmallVector<const SCEVPredicate *, 4> &Preds) {
8292+
return getPredicatedBackedgeTakenInfo(L).getExact(L, this, true, &Preds);
82838293
}
82848294

82858295
const SCEV *ScalarEvolution::getBackedgeTakenCount(const Loop *L,
@@ -8561,23 +8571,34 @@ void ScalarEvolution::forgetBlockAndLoopDispositions(Value *V) {
85618571
/// is never skipped. This is a valid assumption as long as the loop exits via
85628572
/// that test. For precise results, it is the caller's responsibility to specify
85638573
/// the relevant loop exiting block using getExact(ExitingBlock, SE).
8564-
const SCEV *
8565-
ScalarEvolution::BackedgeTakenInfo::getExact(const Loop *L, ScalarEvolution *SE,
8566-
SmallVector<const SCEVPredicate *, 4> *Preds) const {
8574+
const SCEV *ScalarEvolution::BackedgeTakenInfo::getExact(
8575+
const Loop *L, ScalarEvolution *SE, bool SkipUncountable,
8576+
SmallVector<const SCEVPredicate *, 4> *Preds) const {
85678577
// If any exits were not computable, the loop is not computable.
8568-
if (!isComplete() || ExitNotTaken.empty())
8578+
if ((!SkipUncountable && !isComplete()) || ExitNotTaken.empty())
85698579
return SE->getCouldNotCompute();
85708580

85718581
const BasicBlock *Latch = L->getLoopLatch();
85728582
// All exiting blocks we have collected must dominate the only backedge.
85738583
if (!Latch)
85748584
return SE->getCouldNotCompute();
85758585

8586+
if (SkipUncountable) {
8587+
SmallVector<BasicBlock *, 8> ExitingBlocks;
8588+
L->getExitingBlocks(ExitingBlocks);
8589+
if (any_of(ExitingBlocks, [SE, Latch](BasicBlock *Exiting) {
8590+
return !SE->DT.dominates(Exiting, Latch);
8591+
}))
8592+
return SE->getCouldNotCompute();
8593+
}
8594+
85768595
// All exiting blocks we have gathered dominate loop's latch, so exact trip
85778596
// count is simply a minimum out of all these calculated exit counts.
85788597
SmallVector<const SCEV *, 2> Ops;
85798598
for (const auto &ENT : ExitNotTaken) {
85808599
const SCEV *BECount = ENT.ExactNotTaken;
8600+
if (SkipUncountable && BECount == SE->getCouldNotCompute())
8601+
return SE->getCouldNotCompute();
85818602
assert(BECount != SE->getCouldNotCompute() && "Bad exit SCEV!");
85828603
assert(SE->DT.dominates(ENT.ExitingBlock, Latch) &&
85838604
"We should only have known counts for exiting blocks that dominate "
@@ -13522,8 +13543,15 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
1352213543
if (!isa<SCEVCouldNotCompute>(BTC)) {
1352313544
OS << "backedge-taken count is ";
1352413545
PrintSCEVWithTypeHint(OS, BTC);
13525-
} else
13546+
} else {
1352613547
OS << "Unpredictable backedge-taken count.";
13548+
SmallVector<const SCEVPredicate *, 4> Predicates;
13549+
auto *BTC = SE->getBackedgeTakenCountForCountableExits(L);
13550+
if (!isa<SCEVCouldNotCompute>(BTC)) {
13551+
OS << "\nbackedge-taken count for computable exits is ";
13552+
PrintSCEVWithTypeHint(OS, BTC);
13553+
}
13554+
}
1352713555
OS << "\n";
1352813556

1352913557
if (ExitingBlocks.size() > 1)
@@ -14802,6 +14830,16 @@ const SCEV *PredicatedScalarEvolution::getBackedgeTakenCount() {
1480214830
return BackedgeCount;
1480314831
}
1480414832

14833+
const SCEV *
14834+
PredicatedScalarEvolution::getBackedgeTakenCountForCountableExits() {
14835+
SmallVector<const SCEVPredicate *, 4> Preds;
14836+
auto *BackedgeCount =
14837+
SE.getPredicatedBackedgeTakenCountForCountableExits(&L, Preds);
14838+
for (const auto *P : Preds)
14839+
addPredicate(*P);
14840+
return BackedgeCount;
14841+
}
14842+
1480514843
void PredicatedScalarEvolution::addPredicate(const SCEVPredicate &Pred) {
1480614844
if (Preds->implies(&Pred))
1480714845
return;

llvm/test/Analysis/ScalarEvolution/becount-invalidation.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ define void @test(ptr %arg) {
2828
; CHECK-NEXT: --> %ptr2.next U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop.header: Variant, %loop2.header: Invariant }
2929
; CHECK-NEXT: Determining loop execution counts for: @test
3030
; CHECK-NEXT: Loop %loop2.header: <multiple exits> Unpredictable backedge-taken count.
31+
; CHECK-NEXT: backedge-taken count for computable exits is i1 false
3132
; CHECK-NEXT: exit count for loop2.header: ***COULDNOTCOMPUTE***
3233
; CHECK-NEXT: exit count for loop2.latch: i1 false
3334
; CHECK-NEXT: Loop %loop2.header: constant max backedge-taken count is i1 false

llvm/test/Analysis/ScalarEvolution/exit-count-non-strict.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ define void @ule_from_zero_no_nuw(i32 %M, i32 %N) {
9292
; CHECK-LABEL: 'ule_from_zero_no_nuw'
9393
; CHECK-NEXT: Determining loop execution counts for: @ule_from_zero_no_nuw
9494
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
95+
; CHECK-NEXT: backedge-taken count for computable exits is %N
9596
; CHECK-NEXT: exit count for loop: ***COULDNOTCOMPUTE***
9697
; CHECK-NEXT: exit count for latch: %N
9798
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i32 -1
@@ -210,6 +211,7 @@ define void @sle_from_int_min_no_nsw(i32 %M, i32 %N) {
210211
; CHECK-LABEL: 'sle_from_int_min_no_nsw'
211212
; CHECK-NEXT: Determining loop execution counts for: @sle_from_int_min_no_nsw
212213
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
214+
; CHECK-NEXT: backedge-taken count for computable exits is (-2147483648 + %N)
213215
; CHECK-NEXT: exit count for loop: ***COULDNOTCOMPUTE***
214216
; CHECK-NEXT: exit count for latch: (-2147483648 + %N)
215217
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i32 -1

llvm/test/Analysis/ScalarEvolution/exponential-behavior.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ define void @f(i32 %n, ptr %ptr) {
66
; CHECK-LABEL: 'f'
77
; CHECK-NEXT: Determining loop execution counts for: @f
88
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
9+
; CHECK-NEXT: backedge-taken count for computable exits is i32 0
910
; CHECK-NEXT: exit count for loop: i32 0
1011
; CHECK-NEXT: exit count for be: ***COULDNOTCOMPUTE***
1112
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i32 0

llvm/test/Analysis/ScalarEvolution/flags-from-poison.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ define void @test-add-not-header3(ptr %input, i32 %offset, i32 %numIterations,
529529
; CHECK-NEXT: --> %cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
530530
; CHECK-NEXT: Determining loop execution counts for: @test-add-not-header3
531531
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
532+
; CHECK-NEXT: backedge-taken count for computable exits is (-1 + %numIterations)
532533
; CHECK-NEXT: exit count for loop: ***COULDNOTCOMPUTE***
533534
; CHECK-NEXT: exit count for loop2: (-1 + %numIterations)
534535
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i32 -1
@@ -1546,6 +1547,7 @@ define void @test-sext-sub(ptr %input, i32 %sub, i32 %numIterations) {
15461547
; CHECK-NEXT: --> {1,+,1}<nuw><%loop> U: [1,0) S: [1,0) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
15471548
; CHECK-NEXT: Determining loop execution counts for: @test-sext-sub
15481549
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
1550+
; CHECK-NEXT: backedge-taken count for computable exits is (-1 + %numIterations)
15491551
; CHECK-NEXT: exit count for loop: ***COULDNOTCOMPUTE***
15501552
; CHECK-NEXT: exit count for cont: (-1 + %numIterations)
15511553
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i32 -1

llvm/test/Analysis/ScalarEvolution/incorrect-exit-count.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,23 @@ define dso_local i32 @f() {
5858
; CHECK-NEXT: --> {2,+,-1}<nsw><%outer.loop> U: [0,3) S: [0,3) Exits: <<Unknown>> LoopDispositions: { %outer.loop: Computable, %for.cond6: Invariant, %inner.loop: Invariant }
5959
; CHECK-NEXT: Determining loop execution counts for: @f
6060
; CHECK-NEXT: Loop %for.cond6: <multiple exits> Unpredictable backedge-taken count.
61+
; CHECK-NEXT: backedge-taken count for computable exits is i32 0
6162
; CHECK-NEXT: exit count for for.cond6: i32 0
6263
; CHECK-NEXT: exit count for for.end: ***COULDNOTCOMPUTE***
6364
; CHECK-NEXT: Loop %for.cond6: constant max backedge-taken count is i32 0
6465
; CHECK-NEXT: Loop %for.cond6: symbolic max backedge-taken count is i32 0
6566
; CHECK-NEXT: symbolic max exit count for for.cond6: i32 0
6667
; CHECK-NEXT: symbolic max exit count for for.end: ***COULDNOTCOMPUTE***
6768
; CHECK-NEXT: Loop %inner.loop: <multiple exits> Unpredictable backedge-taken count.
69+
; CHECK-NEXT: backedge-taken count for computable exits is i32 0
6870
; CHECK-NEXT: exit count for inner.loop: i32 0
6971
; CHECK-NEXT: exit count for for.end.3: ***COULDNOTCOMPUTE***
7072
; CHECK-NEXT: Loop %inner.loop: constant max backedge-taken count is i32 0
7173
; CHECK-NEXT: Loop %inner.loop: symbolic max backedge-taken count is i32 0
7274
; CHECK-NEXT: symbolic max exit count for inner.loop: i32 0
7375
; CHECK-NEXT: symbolic max exit count for for.end.3: ***COULDNOTCOMPUTE***
7476
; CHECK-NEXT: Loop %outer.loop: <multiple exits> Unpredictable backedge-taken count.
77+
; CHECK-NEXT: backedge-taken count for computable exits is i32 2
7578
; CHECK-NEXT: exit count for for.cond6: ***COULDNOTCOMPUTE***
7679
; CHECK-NEXT: exit count for inner.loop: ***COULDNOTCOMPUTE***
7780
; CHECK-NEXT: exit count for for.inc13.3: i32 2

llvm/test/Analysis/ScalarEvolution/max-trip-count.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ define i32 @main() nounwind {
5353
; CHECK-LABEL: 'main'
5454
; CHECK-NEXT: Determining loop execution counts for: @main
5555
; CHECK-NEXT: Loop %for.cond: <multiple exits> Unpredictable backedge-taken count.
56+
; CHECK-NEXT: backedge-taken count for computable exits is i32 5
5657
; CHECK-NEXT: exit count for for.cond: i32 5
5758
; CHECK-NEXT: exit count for for.body: ***COULDNOTCOMPUTE***
5859
; CHECK-NEXT: Loop %for.cond: constant max backedge-taken count is i32 5
@@ -125,6 +126,7 @@ define i32 @pr19799() {
125126
; CHECK-LABEL: 'pr19799'
126127
; CHECK-NEXT: Determining loop execution counts for: @pr19799
127128
; CHECK-NEXT: Loop %for.body.i: <multiple exits> Unpredictable backedge-taken count.
129+
; CHECK-NEXT: backedge-taken count for computable exits is i32 1
128130
; CHECK-NEXT: exit count for for.body.i: ***COULDNOTCOMPUTE***
129131
; CHECK-NEXT: exit count for for.cond.i: i32 1
130132
; CHECK-NEXT: Loop %for.body.i: constant max backedge-taken count is i32 1
@@ -158,6 +160,7 @@ define i32 @pr18886() {
158160
; CHECK-LABEL: 'pr18886'
159161
; CHECK-NEXT: Determining loop execution counts for: @pr18886
160162
; CHECK-NEXT: Loop %for.body: <multiple exits> Unpredictable backedge-taken count.
163+
; CHECK-NEXT: backedge-taken count for computable exits is i64 3
161164
; CHECK-NEXT: exit count for for.body: ***COULDNOTCOMPUTE***
162165
; CHECK-NEXT: exit count for for.cond: i64 3
163166
; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is i64 3
@@ -571,6 +574,7 @@ define void @max_overflow_me(i8 %n) mustprogress {
571574
; CHECK-LABEL: 'max_overflow_me'
572575
; CHECK-NEXT: Determining loop execution counts for: @max_overflow_me
573576
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
577+
; CHECK-NEXT: backedge-taken count for computable exits is i8 1
574578
; CHECK-NEXT: exit count for loop: i8 1
575579
; CHECK-NEXT: exit count for latch: ***COULDNOTCOMPUTE***
576580
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i8 1

llvm/test/Analysis/ScalarEvolution/ne-overflow.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ define void @test_other_exit(i32 %N) mustprogress {
207207
; CHECK-LABEL: 'test_other_exit'
208208
; CHECK-NEXT: Determining loop execution counts for: @test_other_exit
209209
; CHECK-NEXT: Loop %for.body: <multiple exits> Unpredictable backedge-taken count.
210+
; CHECK-NEXT: backedge-taken count for computable exits is i32 9
210211
; CHECK-NEXT: exit count for for.body: i32 9
211212
; CHECK-NEXT: exit count for for.latch: ***COULDNOTCOMPUTE***
212213
; CHECK-NEXT: Loop %for.body: constant max backedge-taken count is i32 9

llvm/test/Analysis/ScalarEvolution/no-wrap-symbolic-becount.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ define i32 @test_01(i32 %start, ptr %p, ptr %q) {
2424
; CHECK-NEXT: --> {(-1 + (zext i32 %start to i64))<nsw>,+,-1}<nsw><%loop> U: [-4294967296,4294967295) S: [-1,4294967295) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
2525
; CHECK-NEXT: Determining loop execution counts for: @test_01
2626
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
27+
; CHECK-NEXT: backedge-taken count for computable exits is (zext i32 %start to i64)
2728
; CHECK-NEXT: exit count for loop: (zext i32 %start to i64)
2829
; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
2930
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i64 4294967295

llvm/test/Analysis/ScalarEvolution/outer_phi.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ define i32 @test_01(i32 %a, i32 %b) {
1818
; CHECK-NEXT: --> %outer.loop.cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %outer: Variant, %inner: Invariant }
1919
; CHECK-NEXT: Determining loop execution counts for: @test_01
2020
; CHECK-NEXT: Loop %inner: <multiple exits> Unpredictable backedge-taken count.
21+
; CHECK-NEXT: backedge-taken count for computable exits is %b
2122
; CHECK-NEXT: exit count for inner: %b
2223
; CHECK-NEXT: exit count for inner.backedge: ***COULDNOTCOMPUTE***
2324
; CHECK-NEXT: Loop %inner: constant max backedge-taken count is i32 2147483647
@@ -80,6 +81,7 @@ define i32 @test_02(i32 %a, i32 %b) {
8081
; CHECK-NEXT: --> %outer.loop.cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %outer: Variant, %inner: Invariant }
8182
; CHECK-NEXT: Determining loop execution counts for: @test_02
8283
; CHECK-NEXT: Loop %inner: <multiple exits> Unpredictable backedge-taken count.
84+
; CHECK-NEXT: backedge-taken count for computable exits is ((-1 * %outer.iv) + (%b smax %outer.iv))
8385
; CHECK-NEXT: exit count for inner: ((-1 * %outer.iv) + (%b smax %outer.iv))
8486
; CHECK-NEXT: exit count for inner.backedge: ***COULDNOTCOMPUTE***
8587
; CHECK-NEXT: Loop %inner: constant max backedge-taken count is i32 -1

llvm/test/Analysis/ScalarEvolution/pr48225.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ define void @test_and(i1 %boolcond) {
2222
; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%loop> U: [1,4) S: [1,4) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
2323
; CHECK-NEXT: Determining loop execution counts for: @test_and
2424
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
25+
; CHECK-NEXT: backedge-taken count for computable exits is i32 2
2526
; CHECK-NEXT: exit count for loop: i32 2
2627
; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
2728
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i32 2
@@ -71,6 +72,7 @@ define void @test_or(i1 %boolcond) {
7172
; CHECK-NEXT: --> {1,+,1}<nuw><nsw><%loop> U: [1,4) S: [1,4) Exits: <<Unknown>> LoopDispositions: { %loop: Computable }
7273
; CHECK-NEXT: Determining loop execution counts for: @test_or
7374
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
75+
; CHECK-NEXT: backedge-taken count for computable exits is i32 2
7476
; CHECK-NEXT: exit count for loop: i32 2
7577
; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
7678
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i32 2

llvm/test/Analysis/ScalarEvolution/ptrtoint.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ define void @ptrtoint_of_integer(ptr %arg, i64 %arg1, i1 %arg2) local_unnamed_ad
550550
; X64-NEXT: --> {2,+,1}<nw><%bb8> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb8: Computable }
551551
; X64-NEXT: Determining loop execution counts for: @ptrtoint_of_integer
552552
; X64-NEXT: Loop %bb8: <multiple exits> Unpredictable backedge-taken count.
553+
; X64-NEXT: backedge-taken count for computable exits is (-2 + (-1 * %arg1) + (ptrtoint ptr %arg to i64))
553554
; X64-NEXT: exit count for bb8: ***COULDNOTCOMPUTE***
554555
; X64-NEXT: exit count for bb10: (-2 + (-1 * %arg1) + (ptrtoint ptr %arg to i64))
555556
; X64-NEXT: Loop %bb8: constant max backedge-taken count is i64 -1
@@ -569,6 +570,7 @@ define void @ptrtoint_of_integer(ptr %arg, i64 %arg1, i1 %arg2) local_unnamed_ad
569570
; X32-NEXT: --> {2,+,1}<nw><%bb8> U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %bb8: Computable }
570571
; X32-NEXT: Determining loop execution counts for: @ptrtoint_of_integer
571572
; X32-NEXT: Loop %bb8: <multiple exits> Unpredictable backedge-taken count.
573+
; X32-NEXT: backedge-taken count for computable exits is (-2 + (zext i32 (ptrtoint ptr %arg to i32) to i64) + (-1 * %arg1))
572574
; X32-NEXT: exit count for bb8: ***COULDNOTCOMPUTE***
573575
; X32-NEXT: exit count for bb10: (-2 + (zext i32 (ptrtoint ptr %arg to i32) to i64) + (-1 * %arg1))
574576
; X32-NEXT: Loop %bb8: constant max backedge-taken count is i64 -1

llvm/test/Analysis/ScalarEvolution/symbolic_max_exit_count.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ define i32 @test_simple_case(i32 %start, i32 %len) {
1616
; CHECK-NEXT: --> %loop_cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
1717
; CHECK-NEXT: Determining loop execution counts for: @test_simple_case
1818
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
19+
; CHECK-NEXT: backedge-taken count for computable exits is %start
1920
; CHECK-NEXT: exit count for loop: %start
2021
; CHECK-NEXT: exit count for range_check_block: ***COULDNOTCOMPUTE***
2122
; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
@@ -233,6 +234,7 @@ define i32 @test_mixup_constant_symbolic(i32 %end, i32 %len) {
233234
; CHECK-NEXT: --> %loop_cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
234235
; CHECK-NEXT: Determining loop execution counts for: @test_mixup_constant_symbolic
235236
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
237+
; CHECK-NEXT: backedge-taken count for computable exits is (1000 umin %end)
236238
; CHECK-NEXT: exit count for loop: %end
237239
; CHECK-NEXT: exit count for range_check_block: i32 1000
238240
; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
@@ -282,6 +284,7 @@ define i32 @test_mixup_constant_symbolic_merged(i32 %end, i32 %len) {
282284
; CHECK-NEXT: --> %loop_cond U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
283285
; CHECK-NEXT: Determining loop execution counts for: @test_mixup_constant_symbolic_merged
284286
; CHECK-NEXT: Loop %loop: <multiple exits> Unpredictable backedge-taken count.
287+
; CHECK-NEXT: backedge-taken count for computable exits is (1000 umin %end)
285288
; CHECK-NEXT: exit count for loop: (1000 umin %end)
286289
; CHECK-NEXT: exit count for backedge: ***COULDNOTCOMPUTE***
287290
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i32 1000

0 commit comments

Comments
 (0)