diff options
| author | Igor Kudrin <ikudrin@accesssoftek.com> | 2022-04-26 18:43:56 +0400 |
|---|---|---|
| committer | Igor Kudrin <ikudrin@accesssoftek.com> | 2022-04-26 18:43:56 +0400 |
| commit | c71890e158df43d2aa4fbdbfb7adf6791d4cb66b (patch) | |
| tree | 8e71ac9dc9a1670c80607dc9183aaeaefbee93ce /llvm/lib/Transforms/Utils/LoopPeel.cpp | |
| parent | c89433d7fa10f9a3fe3858ac455ece5913092107 (diff) | |
| download | llvm-c71890e158df43d2aa4fbdbfb7adf6791d4cb66b.zip llvm-c71890e158df43d2aa4fbdbfb7adf6791d4cb66b.tar.gz llvm-c71890e158df43d2aa4fbdbfb7adf6791d4cb66b.tar.bz2 | |
[LoopPeel][NFC] Exit early if there is no room for peeling
Differential Revision: https://reviews.llvm.org/D123864
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopPeel.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Utils/LoopPeel.cpp | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp index 609e10c..23df7a0 100644 --- a/llvm/lib/Transforms/Utils/LoopPeel.cpp +++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp @@ -386,6 +386,10 @@ void llvm::computePeelCount(Loop *L, unsigned LoopSize, if (!PP.AllowPeeling) return; + // Check that we can peel at least one iteration. + if (2 * LoopSize > Threshold) + return; + unsigned AlreadyPeeled = 0; if (auto Peeled = getOptionalIntLoopAttribute(L, PeeledCountMetaData)) AlreadyPeeled = *Peeled; @@ -398,47 +402,45 @@ void llvm::computePeelCount(Loop *L, unsigned LoopSize, // 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 // 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. - SmallDenseMap<PHINode *, Optional<unsigned> > IterationsToInvariance; - // Now go through all Phis to calculate their the number of iterations they - // need to become invariants. - // Start the max computation with the PP.PeelCount value set by the target - // in TTI.getPeelingPreferences or by the flag -unroll-peel-count. - unsigned DesiredPeelCount = TargetPeelCount; - BasicBlock *BackEdge = L->getLoopLatch(); - assert(BackEdge && "Loop is not in simplified form?"); - for (auto BI = L->getHeader()->begin(); isa<PHINode>(&*BI); ++BI) { - PHINode *Phi = cast<PHINode>(&*BI); - auto ToInvariance = calculateIterationsToInvariance( - Phi, L, BackEdge, IterationsToInvariance); - if (ToInvariance) - DesiredPeelCount = std::max(DesiredPeelCount, *ToInvariance); - } - // Pay respect to limitations implied by loop size and the max peel count. - unsigned MaxPeelCount = UnrollPeelMaxCount; - MaxPeelCount = std::min(MaxPeelCount, Threshold / LoopSize - 1); - - DesiredPeelCount = std::max(DesiredPeelCount, - countToEliminateCompares(*L, MaxPeelCount, SE)); - - if (DesiredPeelCount == 0) - DesiredPeelCount = peelToTurnInvariantLoadsDerefencebale(*L, DT); - - if (DesiredPeelCount > 0) { - DesiredPeelCount = std::min(DesiredPeelCount, MaxPeelCount); - // Consider max peel count limitation. - assert(DesiredPeelCount > 0 && "Wrong loop size estimation?"); - if (DesiredPeelCount + AlreadyPeeled <= UnrollPeelMaxCount) { - LLVM_DEBUG(dbgs() << "Peel " << DesiredPeelCount - << " iteration(s) to turn" - << " some Phis into invariants.\n"); - PP.PeelCount = DesiredPeelCount; - PP.PeelProfiledIterations = false; - return; - } + // Store the pre-calculated values here. + SmallDenseMap<PHINode *, Optional<unsigned>> IterationsToInvariance; + // Now go through all Phis to calculate their the number of iterations they + // need to become invariants. + // Start the max computation with the PP.PeelCount value set by the target + // in TTI.getPeelingPreferences or by the flag -unroll-peel-count. + unsigned DesiredPeelCount = TargetPeelCount; + BasicBlock *BackEdge = L->getLoopLatch(); + assert(BackEdge && "Loop is not in simplified form?"); + for (auto BI = L->getHeader()->begin(); isa<PHINode>(&*BI); ++BI) { + PHINode *Phi = cast<PHINode>(&*BI); + auto ToInvariance = calculateIterationsToInvariance(Phi, L, BackEdge, + IterationsToInvariance); + if (ToInvariance) + DesiredPeelCount = std::max(DesiredPeelCount, *ToInvariance); + } + + // Pay respect to limitations implied by loop size and the max peel count. + unsigned MaxPeelCount = UnrollPeelMaxCount; + MaxPeelCount = std::min(MaxPeelCount, Threshold / LoopSize - 1); + + DesiredPeelCount = std::max(DesiredPeelCount, + countToEliminateCompares(*L, MaxPeelCount, SE)); + + if (DesiredPeelCount == 0) + DesiredPeelCount = peelToTurnInvariantLoadsDerefencebale(*L, DT); + + if (DesiredPeelCount > 0) { + DesiredPeelCount = std::min(DesiredPeelCount, MaxPeelCount); + // Consider max peel count limitation. + assert(DesiredPeelCount > 0 && "Wrong loop size estimation?"); + if (DesiredPeelCount + AlreadyPeeled <= UnrollPeelMaxCount) { + LLVM_DEBUG(dbgs() << "Peel " << DesiredPeelCount + << " iteration(s) to turn" + << " some Phis into invariants.\n"); + PP.PeelCount = DesiredPeelCount; + PP.PeelProfiledIterations = false; + return; } } |
