@@ -8295,6 +8295,11 @@ const SCEV *ScalarEvolution::getBackedgeTakenCount(const Loop *L,
8295
8295
llvm_unreachable("Invalid ExitCountKind!");
8296
8296
}
8297
8297
8298
+ const SCEV *ScalarEvolution::getPredicatedSymbolicMaxBackedgeTakenCount(
8299
+ const Loop *L, SmallVector<const SCEVPredicate *, 4> &Preds) {
8300
+ return getPredicatedBackedgeTakenInfo(L).getSymbolicMax(L, this, &Preds);
8301
+ }
8302
+
8298
8303
bool ScalarEvolution::isBackedgeTakenCountMaxOrZero(const Loop *L) {
8299
8304
return getBackedgeTakenInfo(L).isConstantMaxOrZero(this);
8300
8305
}
@@ -8311,7 +8316,7 @@ static void PushLoopPHIs(const Loop *L,
8311
8316
Worklist.push_back(&PN);
8312
8317
}
8313
8318
8314
- const ScalarEvolution::BackedgeTakenInfo &
8319
+ ScalarEvolution::BackedgeTakenInfo &
8315
8320
ScalarEvolution::getPredicatedBackedgeTakenInfo(const Loop *L) {
8316
8321
auto &BTI = getBackedgeTakenInfo(L);
8317
8322
if (BTI.hasFullInfo())
@@ -8644,9 +8649,9 @@ ScalarEvolution::BackedgeTakenInfo::getConstantMax(ScalarEvolution *SE) const {
8644
8649
return getConstantMax();
8645
8650
}
8646
8651
8647
- const SCEV *
8648
- ScalarEvolution::BackedgeTakenInfo::getSymbolicMax( const Loop *L,
8649
- ScalarEvolution *SE ) {
8652
+ const SCEV *ScalarEvolution::BackedgeTakenInfo::getSymbolicMax(
8653
+ const Loop *L, ScalarEvolution *SE ,
8654
+ SmallVector<const SCEVPredicate *, 4> *Predicates ) {
8650
8655
if (!SymbolicMax) {
8651
8656
// Form an expression for the maximum exit count possible for this loop. We
8652
8657
// merge the max and exact information to approximate a version of
@@ -8661,6 +8666,12 @@ ScalarEvolution::BackedgeTakenInfo::getSymbolicMax(const Loop *L,
8661
8666
"We should only have known counts for exiting blocks that "
8662
8667
"dominate latch!");
8663
8668
ExitCounts.push_back(ExitCount);
8669
+ if (Predicates)
8670
+ for (const auto *P : ENT.Predicates)
8671
+ Predicates->push_back(P);
8672
+
8673
+ assert((Predicates || ENT.hasAlwaysTruePredicate()) &&
8674
+ "Predicate should be always true!");
8664
8675
}
8665
8676
}
8666
8677
if (ExitCounts.empty())
@@ -13609,6 +13620,24 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
13609
13620
P->print(OS, 4);
13610
13621
}
13611
13622
13623
+ Preds.clear();
13624
+ auto *PredSymbolicMax =
13625
+ SE->getPredicatedSymbolicMaxBackedgeTakenCount(L, Preds);
13626
+ if (SymbolicBTC != PredSymbolicMax) {
13627
+ OS << "Loop ";
13628
+ L->getHeader()->printAsOperand(OS, /*PrintType=*/false);
13629
+ OS << ": ";
13630
+ if (!isa<SCEVCouldNotCompute>(PredSymbolicMax)) {
13631
+ OS << "Predicated symbolic max backedge-taken count is ";
13632
+ PrintSCEVWithTypeHint(OS, PredSymbolicMax);
13633
+ } else
13634
+ OS << "Unpredictable predicated symbolic max backedge-taken count.";
13635
+ OS << "\n";
13636
+ OS << " Predicates:\n";
13637
+ for (const auto *P : Preds)
13638
+ P->print(OS, 4);
13639
+ }
13640
+
13612
13641
if (SE->hasLoopInvariantBackedgeTakenCount(L)) {
13613
13642
OS << "Loop ";
13614
13643
L->getHeader()->printAsOperand(OS, /*PrintType=*/false);
@@ -14822,6 +14851,17 @@ const SCEV *PredicatedScalarEvolution::getBackedgeTakenCount() {
14822
14851
return BackedgeCount;
14823
14852
}
14824
14853
14854
+ const SCEV *PredicatedScalarEvolution::getSymbolicMaxBackedgeTakenCount() {
14855
+ if (!SymbolicMaxBackedgeCount) {
14856
+ SmallVector<const SCEVPredicate *, 4> Preds;
14857
+ SymbolicMaxBackedgeCount =
14858
+ SE.getPredicatedSymbolicMaxBackedgeTakenCount(&L, Preds);
14859
+ for (const auto *P : Preds)
14860
+ addPredicate(*P);
14861
+ }
14862
+ return SymbolicMaxBackedgeCount;
14863
+ }
14864
+
14825
14865
void PredicatedScalarEvolution::addPredicate(const SCEVPredicate &Pred) {
14826
14866
if (Preds->implies(&Pred))
14827
14867
return;
0 commit comments