Skip to content

Commit 0d38f21

Browse files
committed
[SCEV] Extend type hint in analysis output to all backedge kinds
This extends the work from 7755c26 to all of the different backend taken count kinds that we print for the scev analysis printer. As before, the goal is to cut down on confusion as i4 -1 is a very different (unsigned) value from i32 -1.
1 parent 3b1512c commit 0d38f21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+340
-324
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13469,6 +13469,14 @@ bool ScalarEvolution::hasLoopInvariantBackedgeTakenCount(const Loop *L) {
1346913469
return !isa<SCEVCouldNotCompute>(getBackedgeTakenCount(L));
1347013470
}
1347113471

13472+
/// When printing a top-level SCEV for trip counts, it's helpful to include
13473+
/// a type for constants which are otherwise hard to disambiguate.
13474+
static void PrintSCEVWithTypeHint(raw_ostream &OS, const SCEV* S) {
13475+
if (isa<SCEVConstant>(S))
13476+
OS << *S->getType() << " ";
13477+
OS << *S;
13478+
}
13479+
1347213480
static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
1347313481
const Loop *L) {
1347413482
// Print all inner loops first
@@ -13485,15 +13493,18 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
1348513493
OS << "<multiple exits> ";
1348613494

1348713495
auto *BTC = SE->getBackedgeTakenCount(L);
13488-
if (!isa<SCEVCouldNotCompute>(BTC))
13489-
OS << "backedge-taken count is " << *BTC << "\n";
13490-
else
13491-
OS << "Unpredictable backedge-taken count.\n";
13496+
if (!isa<SCEVCouldNotCompute>(BTC)) {
13497+
OS << "backedge-taken count is ";
13498+
PrintSCEVWithTypeHint(OS, BTC);
13499+
} else
13500+
OS << "Unpredictable backedge-taken count.";
13501+
OS << "\n";
1349213502

1349313503
if (ExitingBlocks.size() > 1)
1349413504
for (BasicBlock *ExitingBlock : ExitingBlocks) {
13495-
OS << " exit count for " << ExitingBlock->getName() << ": "
13496-
<< *SE->getExitCount(L, ExitingBlock) << "\n";
13505+
OS << " exit count for " << ExitingBlock->getName() << ": ";
13506+
PrintSCEVWithTypeHint(OS, SE->getExitCount(L, ExitingBlock));
13507+
OS << "\n";
1349713508
}
1349813509

1349913510
OS << "Loop ";
@@ -13502,8 +13513,8 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
1350213513

1350313514
auto *ConstantBTC = SE->getConstantMaxBackedgeTakenCount(L);
1350413515
if (!isa<SCEVCouldNotCompute>(ConstantBTC)) {
13505-
OS << "constant max backedge-taken count is "
13506-
<< *ConstantBTC->getType() << " " << *ConstantBTC;
13516+
OS << "constant max backedge-taken count is ";
13517+
PrintSCEVWithTypeHint(OS, ConstantBTC);
1350713518
if (SE->isBackedgeTakenCountMaxOrZero(L))
1350813519
OS << ", actual taken count either this or zero.";
1350913520
} else {
@@ -13517,19 +13528,22 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
1351713528

1351813529
auto *SymbolicBTC = SE->getSymbolicMaxBackedgeTakenCount(L);
1351913530
if (!isa<SCEVCouldNotCompute>(SymbolicBTC)) {
13520-
OS << "symbolic max backedge-taken count is " << *SymbolicBTC;
13531+
OS << "symbolic max backedge-taken count is ";
13532+
PrintSCEVWithTypeHint(OS, SymbolicBTC);
1352113533
if (SE->isBackedgeTakenCountMaxOrZero(L))
1352213534
OS << ", actual taken count either this or zero.";
1352313535
} else {
1352413536
OS << "Unpredictable symbolic max backedge-taken count. ";
1352513537
}
13526-
1352713538
OS << "\n";
13539+
1352813540
if (ExitingBlocks.size() > 1)
1352913541
for (BasicBlock *ExitingBlock : ExitingBlocks) {
13530-
OS << " symbolic max exit count for " << ExitingBlock->getName() << ": "
13531-
<< *SE->getExitCount(L, ExitingBlock, ScalarEvolution::SymbolicMaximum)
13532-
<< "\n";
13542+
OS << " symbolic max exit count for " << ExitingBlock->getName() << ": ";
13543+
auto *ExitBTC = SE->getExitCount(L, ExitingBlock,
13544+
ScalarEvolution::SymbolicMaximum);
13545+
PrintSCEVWithTypeHint(OS, ExitBTC);
13546+
OS << "\n";
1353313547
}
1353413548

1353513549
SmallVector<const SCEVPredicate *, 4> Preds;
@@ -13538,10 +13552,12 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
1353813552
OS << "Loop ";
1353913553
L->getHeader()->printAsOperand(OS, /*PrintType=*/false);
1354013554
OS << ": ";
13541-
if (!isa<SCEVCouldNotCompute>(PBT))
13542-
OS << "Predicated backedge-taken count is " << *PBT << "\n";
13543-
else
13544-
OS << "Unpredictable predicated backedge-taken count.\n";
13555+
if (!isa<SCEVCouldNotCompute>(PBT)) {
13556+
OS << "Predicated backedge-taken count is ";
13557+
PrintSCEVWithTypeHint(OS, PBT);
13558+
} else
13559+
OS << "Unpredictable predicated backedge-taken count.";
13560+
OS << "\n";
1354513561
OS << " Predicates:\n";
1354613562
for (const auto *P : Preds)
1354713563
P->print(OS, 4);

llvm/test/Analysis/ScalarEvolution/2007-07-15-NegativeStride.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
define void @loop(i32 %x) {
99
; CHECK-LABEL: 'loop'
1010
; CHECK-NEXT: Determining loop execution counts for: @loop
11-
; CHECK-NEXT: Loop %bb: backedge-taken count is 100
11+
; CHECK-NEXT: Loop %bb: backedge-taken count is i32 100
1212
; CHECK-NEXT: Loop %bb: constant max backedge-taken count is i32 100
13-
; CHECK-NEXT: Loop %bb: symbolic max backedge-taken count is 100
13+
; CHECK-NEXT: Loop %bb: symbolic max backedge-taken count is i32 100
1414
; CHECK-NEXT: Loop %bb: Trip multiple is 101
1515
;
1616
entry:

llvm/test/Analysis/ScalarEvolution/2007-09-27-LargeStepping.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
define i32 @f() {
77
; CHECK-LABEL: 'f'
88
; CHECK-NEXT: Determining loop execution counts for: @f
9-
; CHECK-NEXT: Loop %bb5: backedge-taken count is 13
9+
; CHECK-NEXT: Loop %bb5: backedge-taken count is i32 13
1010
; CHECK-NEXT: Loop %bb5: constant max backedge-taken count is i32 13
11-
; CHECK-NEXT: Loop %bb5: symbolic max backedge-taken count is 13
11+
; CHECK-NEXT: Loop %bb5: symbolic max backedge-taken count is i32 13
1212
; CHECK-NEXT: Loop %bb5: Trip multiple is 14
1313
;
1414
entry:

llvm/test/Analysis/ScalarEvolution/2008-05-25-NegativeStepToZero.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
define i32 @func_6() nounwind {
77
; CHECK-LABEL: 'func_6'
88
; CHECK-NEXT: Determining loop execution counts for: @func_6
9-
; CHECK-NEXT: Loop %bb5: backedge-taken count is 61
9+
; CHECK-NEXT: Loop %bb5: backedge-taken count is i8 61
1010
; CHECK-NEXT: Loop %bb5: constant max backedge-taken count is i8 61
11-
; CHECK-NEXT: Loop %bb5: symbolic max backedge-taken count is 61
11+
; CHECK-NEXT: Loop %bb5: symbolic max backedge-taken count is i8 61
1212
; CHECK-NEXT: Loop %bb5: Trip multiple is 62
1313
;
1414
entry:

llvm/test/Analysis/ScalarEvolution/2008-07-19-WrappingIV.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
define void @fun() {
77
; CHECK-LABEL: 'fun'
88
; CHECK-NEXT: Determining loop execution counts for: @fun
9-
; CHECK-NEXT: Loop %loop: backedge-taken count is 113
9+
; CHECK-NEXT: Loop %loop: backedge-taken count is i8 113
1010
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i8 113
11-
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is 113
11+
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is i8 113
1212
; CHECK-NEXT: Loop %loop: Trip multiple is 114
1313
;
1414
entry:

llvm/test/Analysis/ScalarEvolution/2008-12-08-FiniteSGE.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
define i32 @foo(i32 %x, i32 %y, ptr %lam, ptr %alp) nounwind {
66
; CHECK-LABEL: 'foo'
77
; CHECK-NEXT: Determining loop execution counts for: @foo
8-
; CHECK-NEXT: Loop %bb1: backedge-taken count is 255
8+
; CHECK-NEXT: Loop %bb1: backedge-taken count is i32 255
99
; CHECK-NEXT: Loop %bb1: constant max backedge-taken count is i32 255
10-
; CHECK-NEXT: Loop %bb1: symbolic max backedge-taken count is 255
10+
; CHECK-NEXT: Loop %bb1: symbolic max backedge-taken count is i32 255
1111
; CHECK-NEXT: Loop %bb1: Trip multiple is 256
1212
;
1313
bb1.thread:

llvm/test/Analysis/ScalarEvolution/2009-05-09-PointerEdgeCount.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:1
1111
define void @_Z3foov() nounwind {
1212
; CHECK-LABEL: '_Z3foov'
1313
; CHECK-NEXT: Determining loop execution counts for: @_Z3foov
14-
; CHECK-NEXT: Loop %bb1.i: backedge-taken count is 2
14+
; CHECK-NEXT: Loop %bb1.i: backedge-taken count is i64 2
1515
; CHECK-NEXT: Loop %bb1.i: constant max backedge-taken count is i64 2
16-
; CHECK-NEXT: Loop %bb1.i: symbolic max backedge-taken count is 2
16+
; CHECK-NEXT: Loop %bb1.i: symbolic max backedge-taken count is i64 2
1717
; CHECK-NEXT: Loop %bb1.i: Trip multiple is 3
1818
;
1919
entry:

llvm/test/Analysis/ScalarEvolution/SolveQuadraticEquation.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
define void @test1(i32 %N) {
99
; CHECK-LABEL: 'test1'
1010
; CHECK-NEXT: Determining loop execution counts for: @test1
11-
; CHECK-NEXT: Loop %bb3: backedge-taken count is 100
11+
; CHECK-NEXT: Loop %bb3: backedge-taken count is i32 100
1212
; CHECK-NEXT: Loop %bb3: constant max backedge-taken count is i32 100
13-
; CHECK-NEXT: Loop %bb3: symbolic max backedge-taken count is 100
13+
; CHECK-NEXT: Loop %bb3: symbolic max backedge-taken count is i32 100
1414
; CHECK-NEXT: Loop %bb3: Trip multiple is 101
1515
;
1616
entry:

llvm/test/Analysis/ScalarEvolution/addrec-computed-during-addrec-calculation.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ define void @test(ptr %p) {
2828
; CHECK-NEXT: Determining loop execution counts for: @test
2929
; CHECK-NEXT: Loop %loop2: Unpredictable backedge-taken count.
3030
; CHECK-NEXT: Loop %loop2: constant max backedge-taken count is i32 -1
31-
; CHECK-NEXT: Loop %loop2: symbolic max backedge-taken count is -1
32-
; CHECK-NEXT: Loop %loop3: backedge-taken count is false
31+
; CHECK-NEXT: Loop %loop2: symbolic max backedge-taken count is i32 -1
32+
; CHECK-NEXT: Loop %loop3: backedge-taken count is i1 false
3333
; CHECK-NEXT: Loop %loop3: constant max backedge-taken count is i1 false
34-
; CHECK-NEXT: Loop %loop3: symbolic max backedge-taken count is false
34+
; CHECK-NEXT: Loop %loop3: symbolic max backedge-taken count is i1 false
3535
; CHECK-NEXT: Loop %loop3: Trip multiple is 1
3636
; CHECK-NEXT: Loop %loop.header: <multiple exits> Unpredictable backedge-taken count.
3737
; CHECK-NEXT: Loop %loop.header: Unpredictable constant max backedge-taken count.

llvm/test/Analysis/ScalarEvolution/alloca.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ define void @alloca_icmp_null_exit_count() {
4343
; CHECK-NEXT: %and = and i1 %cmp1, %cmp2
4444
; CHECK-NEXT: --> (%cmp2 umin %cmp1) U: full-set S: full-set Exits: <<Unknown>> LoopDispositions: { %loop: Variant }
4545
; CHECK-NEXT: Determining loop execution counts for: @alloca_icmp_null_exit_count
46-
; CHECK-NEXT: Loop %loop: backedge-taken count is 2
46+
; CHECK-NEXT: Loop %loop: backedge-taken count is i64 2
4747
; CHECK-NEXT: Loop %loop: constant max backedge-taken count is i64 2
48-
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is 2
48+
; CHECK-NEXT: Loop %loop: symbolic max backedge-taken count is i64 2
4949
; CHECK-NEXT: Loop %loop: Trip multiple is 3
5050
;
5151
entry:

0 commit comments

Comments
 (0)