@@ -13469,6 +13469,14 @@ bool ScalarEvolution::hasLoopInvariantBackedgeTakenCount(const Loop *L) {
13469
13469
return !isa<SCEVCouldNotCompute>(getBackedgeTakenCount(L));
13470
13470
}
13471
13471
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
+
13472
13480
static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
13473
13481
const Loop *L) {
13474
13482
// Print all inner loops first
@@ -13485,15 +13493,18 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
13485
13493
OS << "<multiple exits> ";
13486
13494
13487
13495
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";
13492
13502
13493
13503
if (ExitingBlocks.size() > 1)
13494
13504
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";
13497
13508
}
13498
13509
13499
13510
OS << "Loop ";
@@ -13502,8 +13513,8 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
13502
13513
13503
13514
auto *ConstantBTC = SE->getConstantMaxBackedgeTakenCount(L);
13504
13515
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) ;
13507
13518
if (SE->isBackedgeTakenCountMaxOrZero(L))
13508
13519
OS << ", actual taken count either this or zero.";
13509
13520
} else {
@@ -13517,19 +13528,22 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
13517
13528
13518
13529
auto *SymbolicBTC = SE->getSymbolicMaxBackedgeTakenCount(L);
13519
13530
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);
13521
13533
if (SE->isBackedgeTakenCountMaxOrZero(L))
13522
13534
OS << ", actual taken count either this or zero.";
13523
13535
} else {
13524
13536
OS << "Unpredictable symbolic max backedge-taken count. ";
13525
13537
}
13526
-
13527
13538
OS << "\n";
13539
+
13528
13540
if (ExitingBlocks.size() > 1)
13529
13541
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";
13533
13547
}
13534
13548
13535
13549
SmallVector<const SCEVPredicate *, 4> Preds;
@@ -13538,10 +13552,12 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
13538
13552
OS << "Loop ";
13539
13553
L->getHeader()->printAsOperand(OS, /*PrintType=*/false);
13540
13554
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";
13545
13561
OS << " Predicates:\n";
13546
13562
for (const auto *P : Preds)
13547
13563
P->print(OS, 4);
0 commit comments