aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorEnna1 <xumingjie.enna1@bytedance.com>2024-06-21 09:43:34 +0800
committerGitHub <noreply@github.com>2024-06-21 09:43:34 +0800
commit1fafa32f6ee844f0862954d0b2330dee26b0469f (patch)
treeac1ca5217b695f2b6cf507bd11ddb21b7bafe148 /llvm/lib/Analysis/ScalarEvolution.cpp
parent1373f7c714824f5957aa5fabf8370286f86e6b14 (diff)
downloadllvm-1fafa32f6ee844f0862954d0b2330dee26b0469f.zip
llvm-1fafa32f6ee844f0862954d0b2330dee26b0469f.tar.gz
llvm-1fafa32f6ee844f0862954d0b2330dee26b0469f.tar.bz2
[SCEV] Avoid unnecessary call to getExitingBlock() in computeExitLimit() (#96188)
In `computeExitLimit()`, we use `getExitingBlock()` to check if loop has exactly one exiting block. Since `computeExitLimit()` is only used in `computeBackedgeTakenCount()`, and `getExitingBlocks()` is called to get all exiting blocks in `computeBackedgeTakenCount()`, we can simply check if loop has exactly one exiting block by checking if the number of exiting blocks equals 1 in `computeBackedgeTakenCount()` and pass it as an argument to `computeExitLimit()`. This change helps to improve the compile time for files containing large loops.
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 08cca62..2802de6 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8780,6 +8780,7 @@ ScalarEvolution::computeBackedgeTakenCount(const Loop *L,
const SCEV *MustExitMaxBECount = nullptr;
const SCEV *MayExitMaxBECount = nullptr;
bool MustExitMaxOrZero = false;
+ bool IsOnlyExit = ExitingBlocks.size() == 1;
// Compute the ExitLimit for each loop exit. Use this to populate ExitCounts
// and compute maxBECount.
@@ -8797,7 +8798,7 @@ ScalarEvolution::computeBackedgeTakenCount(const Loop *L,
continue;
}
- ExitLimit EL = computeExitLimit(L, ExitBB, AllowPredicates);
+ ExitLimit EL = computeExitLimit(L, ExitBB, IsOnlyExit, AllowPredicates);
assert((AllowPredicates || EL.Predicates.empty()) &&
"Predicated exit limit when predicates are not allowed!");
@@ -8872,7 +8873,7 @@ ScalarEvolution::computeBackedgeTakenCount(const Loop *L,
ScalarEvolution::ExitLimit
ScalarEvolution::computeExitLimit(const Loop *L, BasicBlock *ExitingBlock,
- bool AllowPredicates) {
+ bool IsOnlyExit, bool AllowPredicates) {
assert(L->contains(ExitingBlock) && "Exit count for non-loop block?");
// If our exiting block does not dominate the latch, then its connection with
// loop's exit limit may be far from trivial.
@@ -8880,7 +8881,6 @@ ScalarEvolution::computeExitLimit(const Loop *L, BasicBlock *ExitingBlock,
if (!Latch || !DT.dominates(ExitingBlock, Latch))
return getCouldNotCompute();
- bool IsOnlyExit = (L->getExitingBlock() != nullptr);
Instruction *Term = ExitingBlock->getTerminator();
if (BranchInst *BI = dyn_cast<BranchInst>(Term)) {
assert(BI->isConditional() && "If unconditional, it can't be in loop!");
@@ -8904,8 +8904,7 @@ ScalarEvolution::computeExitLimit(const Loop *L, BasicBlock *ExitingBlock,
}
assert(Exit && "Exiting block must have at least one exit");
return computeExitLimitFromSingleExitSwitch(
- L, SI, Exit,
- /*ControlsOnlyExit=*/IsOnlyExit);
+ L, SI, Exit, /*ControlsOnlyExit=*/IsOnlyExit);
}
return getCouldNotCompute();