[LoopPeel][NFC] Exit early if there is no room for peeling

Differential Revision: https://reviews.llvm.org/D123864
This commit is contained in:
Igor Kudrin 2022-04-26 18:43:56 +04:00
parent c89433d7fa
commit c71890e158
1 changed files with 39 additions and 37 deletions

View File

@ -386,6 +386,10 @@ void llvm::computePeelCount(Loop *L, unsigned LoopSize,
if (!PP.AllowPeeling) if (!PP.AllowPeeling)
return; return;
// Check that we can peel at least one iteration.
if (2 * LoopSize > Threshold)
return;
unsigned AlreadyPeeled = 0; unsigned AlreadyPeeled = 0;
if (auto Peeled = getOptionalIntLoopAttribute(L, PeeledCountMetaData)) if (auto Peeled = getOptionalIntLoopAttribute(L, PeeledCountMetaData))
AlreadyPeeled = *Peeled; AlreadyPeeled = *Peeled;
@ -398,8 +402,7 @@ void llvm::computePeelCount(Loop *L, unsigned LoopSize,
// which every Phi is guaranteed to become an invariant, and try to peel the // which every Phi is guaranteed to become an invariant, and try to peel the
// maximum number of iterations among these values, thus turning all those // maximum number of iterations among these values, thus turning all those
// Phis into invariants. // Phis into invariants.
// First, check that we can peel at least one iteration.
if (2 * LoopSize <= Threshold && UnrollPeelMaxCount > 0) {
// Store the pre-calculated values here. // Store the pre-calculated values here.
SmallDenseMap<PHINode *, Optional<unsigned>> IterationsToInvariance; SmallDenseMap<PHINode *, Optional<unsigned>> IterationsToInvariance;
// Now go through all Phis to calculate their the number of iterations they // Now go through all Phis to calculate their the number of iterations they
@ -411,8 +414,8 @@ void llvm::computePeelCount(Loop *L, unsigned LoopSize,
assert(BackEdge && "Loop is not in simplified form?"); assert(BackEdge && "Loop is not in simplified form?");
for (auto BI = L->getHeader()->begin(); isa<PHINode>(&*BI); ++BI) { for (auto BI = L->getHeader()->begin(); isa<PHINode>(&*BI); ++BI) {
PHINode *Phi = cast<PHINode>(&*BI); PHINode *Phi = cast<PHINode>(&*BI);
auto ToInvariance = calculateIterationsToInvariance( auto ToInvariance = calculateIterationsToInvariance(Phi, L, BackEdge,
Phi, L, BackEdge, IterationsToInvariance); IterationsToInvariance);
if (ToInvariance) if (ToInvariance)
DesiredPeelCount = std::max(DesiredPeelCount, *ToInvariance); DesiredPeelCount = std::max(DesiredPeelCount, *ToInvariance);
} }
@ -440,7 +443,6 @@ void llvm::computePeelCount(Loop *L, unsigned LoopSize,
return; return;
} }
} }
}
// Bail if we know the statically calculated trip count. // Bail if we know the statically calculated trip count.
// In this case we rather prefer partial unrolling. // In this case we rather prefer partial unrolling.