Skip to content

Commit ef67f31

Browse files
committed
[SCEV] Compute symbolic max backedge taken count in BTI directly. (NFC)
Move symbolic max backedge taken count computation to BackedgeTakenInfo, use existing ExitNotTaken info. In preparation for #93498.
1 parent c09787b commit ef67f31

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,11 +1761,6 @@ class ScalarEvolution {
17611761
ExitLimit computeExitLimit(const Loop *L, BasicBlock *ExitingBlock,
17621762
bool AllowPredicates = false);
17631763

1764-
/// Return a symbolic upper bound for the backedge taken count of the loop.
1765-
/// This is more general than getConstantMaxBackedgeTakenCount as it returns
1766-
/// an arbitrary expression as opposed to only constants.
1767-
const SCEV *computeSymbolicMaxBackedgeTakenCount(const Loop *L);
1768-
17691764
// Helper functions for computeExitLimitFromCond to avoid exponential time
17701765
// complexity.
17711766

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8647,8 +8647,28 @@ ScalarEvolution::BackedgeTakenInfo::getConstantMax(ScalarEvolution *SE) const {
86478647
const SCEV *
86488648
ScalarEvolution::BackedgeTakenInfo::getSymbolicMax(const Loop *L,
86498649
ScalarEvolution *SE) {
8650-
if (!SymbolicMax)
8651-
SymbolicMax = SE->computeSymbolicMaxBackedgeTakenCount(L);
8650+
if (!SymbolicMax) {
8651+
// Form an expression for the maximum exit count possible for this loop. We
8652+
// merge the max and exact information to approximate a version of
8653+
// getConstantMaxBackedgeTakenCount which isn't restricted to just
8654+
// constants.
8655+
SmallVector<const SCEV *, 4> ExitCounts;
8656+
8657+
for (const auto &ENT : ExitNotTaken) {
8658+
const SCEV *ExitCount = ENT.SymbolicMaxNotTaken;
8659+
if (!isa<SCEVCouldNotCompute>(ExitCount)) {
8660+
assert(SE->DT.dominates(ENT.ExitingBlock, L->getLoopLatch()) &&
8661+
"We should only have known counts for exiting blocks that "
8662+
"dominate latch!");
8663+
ExitCounts.push_back(ExitCount);
8664+
}
8665+
}
8666+
if (ExitCounts.empty())
8667+
SymbolicMax = SE->getCouldNotCompute();
8668+
else
8669+
SymbolicMax =
8670+
SE->getUMinFromMismatchedTypes(ExitCounts, /*Sequential*/ true);
8671+
}
86528672
return SymbolicMax;
86538673
}
86548674

@@ -14964,30 +14984,6 @@ bool ScalarEvolution::matchURem(const SCEV *Expr, const SCEV *&LHS,
1496414984
return false;
1496514985
}
1496614986

14967-
const SCEV *
14968-
ScalarEvolution::computeSymbolicMaxBackedgeTakenCount(const Loop *L) {
14969-
SmallVector<BasicBlock*, 16> ExitingBlocks;
14970-
L->getExitingBlocks(ExitingBlocks);
14971-
14972-
// Form an expression for the maximum exit count possible for this loop. We
14973-
// merge the max and exact information to approximate a version of
14974-
// getConstantMaxBackedgeTakenCount which isn't restricted to just constants.
14975-
SmallVector<const SCEV*, 4> ExitCounts;
14976-
for (BasicBlock *ExitingBB : ExitingBlocks) {
14977-
const SCEV *ExitCount =
14978-
getExitCount(L, ExitingBB, ScalarEvolution::SymbolicMaximum);
14979-
if (!isa<SCEVCouldNotCompute>(ExitCount)) {
14980-
assert(DT.dominates(ExitingBB, L->getLoopLatch()) &&
14981-
"We should only have known counts for exiting blocks that "
14982-
"dominate latch!");
14983-
ExitCounts.push_back(ExitCount);
14984-
}
14985-
}
14986-
if (ExitCounts.empty())
14987-
return getCouldNotCompute();
14988-
return getUMinFromMismatchedTypes(ExitCounts, /*Sequential*/ true);
14989-
}
14990-
1499114987
/// A rewriter to replace SCEV expressions in Map with the corresponding entry
1499214988
/// in the map. It skips AddRecExpr because we cannot guarantee that the
1499314989
/// replacement is loop invariant in the loop of the AddRec.

0 commit comments

Comments
 (0)