mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-24 06:25:18 +00:00
[LoopUnrollRuntime] Avoid high-cost trip count computation.
Summary: Runtime unrolling of loops needs to emit an expression to compute the loop's runtime trip-count. Avoid runtime unrolling if this computation will be expensive. Depends on D8993. Reviewers: atrick Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D8994 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234846 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -278,7 +278,8 @@ static void CloneLoopBlocks(Loop *L, Value *NewIter, const bool UnrollProlog,
|
||||
/// ...
|
||||
/// End:
|
||||
///
|
||||
bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count, LoopInfo *LI,
|
||||
bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count,
|
||||
bool AllowExpensiveTripCount, LoopInfo *LI,
|
||||
LPPassManager *LPM) {
|
||||
// for now, only unroll loops that contain a single exit
|
||||
if (!L->getExitingBlock())
|
||||
@@ -312,6 +313,12 @@ bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count, LoopInfo *LI,
|
||||
if (isa<SCEVCouldNotCompute>(TripCountSC))
|
||||
return false;
|
||||
|
||||
BasicBlock *Header = L->getHeader();
|
||||
const DataLayout &DL = Header->getModule()->getDataLayout();
|
||||
SCEVExpander Expander(*SE, DL, "loop-unroll");
|
||||
if (!AllowExpensiveTripCount && Expander.isHighCostExpansion(TripCountSC, L))
|
||||
return false;
|
||||
|
||||
// We only handle cases when the unroll factor is a power of 2.
|
||||
// Count is the loop unroll factor, the number of extra copies added + 1.
|
||||
if (!isPowerOf2_32(Count))
|
||||
@@ -332,18 +339,15 @@ bool llvm::UnrollRuntimeLoopProlog(Loop *L, unsigned Count, LoopInfo *LI,
|
||||
auto *DT = DTWP ? &DTWP->getDomTree() : nullptr;
|
||||
|
||||
BasicBlock *PH = L->getLoopPreheader();
|
||||
BasicBlock *Header = L->getHeader();
|
||||
BasicBlock *Latch = L->getLoopLatch();
|
||||
// It helps to splits the original preheader twice, one for the end of the
|
||||
// prolog code and one for a new loop preheader
|
||||
BasicBlock *PEnd = SplitEdge(PH, Header, DT, LI);
|
||||
BasicBlock *NewPH = SplitBlock(PEnd, PEnd->getTerminator(), DT, LI);
|
||||
BranchInst *PreHeaderBR = cast<BranchInst>(PH->getTerminator());
|
||||
const DataLayout &DL = Header->getModule()->getDataLayout();
|
||||
|
||||
// Compute the number of extra iterations required, which is:
|
||||
// extra iterations = run-time trip count % (loop unroll factor + 1)
|
||||
SCEVExpander Expander(*SE, DL, "loop-unroll");
|
||||
Value *TripCount = Expander.expandCodeFor(TripCountSC, TripCountSC->getType(),
|
||||
PreHeaderBR);
|
||||
Value *BECount = Expander.expandCodeFor(BECountSC, BECountSC->getType(),
|
||||
|
Reference in New Issue
Block a user