Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0d38f21

Browse files
committedMar 6, 2024
[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:

0 commit comments

Comments
 (0)
Please sign in to comment.