diff options
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUnroll.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUnroll.cpp | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp index f7590acc..b3658fb 100644 --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -301,11 +301,6 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, if (ULO.TripMultiple != 1) LLVM_DEBUG(dbgs() << " Trip Multiple = " << ULO.TripMultiple << "\n"); - // Effectively "DCE" unrolled iterations that are beyond the tripcount - // and will never be executed. - if (ULO.TripCount != 0 && ULO.Count > ULO.TripCount) - ULO.Count = ULO.TripCount; - // Don't enter the unroll code if there is nothing to do. if (ULO.TripCount == 0 && ULO.Count < 2) { LLVM_DEBUG(dbgs() << "Won't unroll; almost nothing to do\n"); @@ -316,17 +311,6 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, assert(ULO.TripMultiple > 0); assert(ULO.TripCount == 0 || ULO.TripCount % ULO.TripMultiple == 0); - // Are we eliminating the loop control altogether? Note that we can know - // we're eliminating the backedge without knowing exactly which iteration - // of the unrolled body exits. - const bool CompletelyUnroll = ULO.Count == ULO.TripCount; - - // We assume a run-time trip count if the compiler cannot - // figure out the loop trip count and the unroll-runtime - // flag is specified. - bool RuntimeTripCount = - (ULO.TripCount == 0 && ULO.Count > 0 && ULO.AllowRuntime); - // All these values should be taken only after peeling because they might have // changed. BasicBlock *Preheader = L->getLoopPreheader(); @@ -336,6 +320,27 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, L->getExitBlocks(ExitBlocks); std::vector<BasicBlock *> OriginalLoopBlocks = L->getBlocks(); + const unsigned MaxTripCount = SE->getSmallConstantMaxTripCount(L); + const bool MaxOrZero = SE->isBackedgeTakenCountMaxOrZero(L); + + // Effectively "DCE" unrolled iterations that are beyond the max tripcount + // and will never be executed. + if (MaxTripCount && ULO.Count > MaxTripCount) + ULO.Count = MaxTripCount; + + // Are we eliminating the loop control altogether? Note that we can know + // we're eliminating the backedge without knowing exactly which iteration + // of the unrolled body exits. + const bool CompletelyUnroll = ULO.Count == MaxTripCount; + + const bool PreserveOnlyFirst = CompletelyUnroll && MaxOrZero; + + // We assume a run-time trip count if the compiler cannot + // figure out the loop trip count and the unroll-runtime + // flag is specified. + bool RuntimeTripCount = + !CompletelyUnroll && ULO.TripCount == 0 && ULO.AllowRuntime; + // Go through all exits of L and see if there are any phi-nodes there. We just // conservatively assume that they're inserted to preserve LCSSA form, which // means that complete unrolling might break this form. We need to either fix @@ -347,11 +352,6 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, any_of(ExitBlocks, [](const BasicBlock *BB) { return isa<PHINode>(BB->begin()); }); - const unsigned MaxTripCount = SE->getSmallConstantMaxTripCount(L); - const bool MaxOrZero = SE->isBackedgeTakenCountMaxOrZero(L); - - const bool PreserveOnlyFirst = ULO.Count == MaxTripCount && MaxOrZero; - // The current loop unroll pass can unroll loops that have // (1) single latch; and // (2a) latch is unconditional; or @@ -728,8 +728,6 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, // Complete (but possibly inexact) unrolling if (j == 0) return true; - if (MaxTripCount && j >= MaxTripCount) - return false; // Warning: ExactTripCount is the trip count of the exiting // block which ends in ExitingBI, not neccessarily the loop. if (ExactTripCount && j != ExactTripCount) |