1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

[LoopUnrollRuntime] NFC: Add some debugging trace messages for why loop wasn't unrolled.

llvm-svn: 307705
This commit is contained in:
Anna Thomas 2017-07-11 20:44:37 +00:00
parent db38bdb5c8
commit fdf710e920

View File

@ -471,21 +471,31 @@ bool llvm::UnrollRuntimeLoopRemainder(Loop *L, unsigned Count,
LoopInfo *LI, ScalarEvolution *SE, LoopInfo *LI, ScalarEvolution *SE,
DominatorTree *DT, bool PreserveLCSSA) { DominatorTree *DT, bool PreserveLCSSA) {
bool hasMultipleExitingBlocks = !L->getExitingBlock(); bool hasMultipleExitingBlocks = !L->getExitingBlock();
DEBUG(dbgs() << "Trying runtime unrolling on Loop: \n");
DEBUG(L->dump());
// Support only single exiting block unless UnrollRuntimeMultiExit is true. // Support only single exiting block unless UnrollRuntimeMultiExit is true.
if (!UnrollRuntimeMultiExit && hasMultipleExitingBlocks) if (!UnrollRuntimeMultiExit && hasMultipleExitingBlocks) {
DEBUG(
dbgs()
<< "Multiple exiting blocks and UnrollRuntimeMultiExit not enabled!\n");
return false; return false;
}
// Make sure the loop is in canonical form. // Make sure the loop is in canonical form.
if (!L->isLoopSimplifyForm()) if (!L->isLoopSimplifyForm()) {
DEBUG(dbgs() << "Not in simplify form!\n");
return false; return false;
}
// Guaranteed by LoopSimplifyForm. // Guaranteed by LoopSimplifyForm.
BasicBlock *Latch = L->getLoopLatch(); BasicBlock *Latch = L->getLoopLatch();
BasicBlock *Header = L->getHeader(); BasicBlock *Header = L->getHeader();
BasicBlock *LatchExit = L->getUniqueExitBlock(); // successor out of loop BasicBlock *LatchExit = L->getUniqueExitBlock(); // successor out of loop
if (!LatchExit && !UnrollRuntimeMultiExit) if (!LatchExit && !UnrollRuntimeMultiExit) {
DEBUG(dbgs() << "No unique exit block and UnrollRuntimeMultiExit not enabled\n");
return false; return false;
}
// These are exit blocks other than the target of the latch exiting block. // These are exit blocks other than the target of the latch exiting block.
SmallVector<BasicBlock *, 4> OtherExits; SmallVector<BasicBlock *, 4> OtherExits;
BranchInst *LatchBR = cast<BranchInst>(Latch->getTerminator()); BranchInst *LatchBR = cast<BranchInst>(Latch->getTerminator());
@ -515,8 +525,11 @@ bool llvm::UnrollRuntimeLoopRemainder(Loop *L, unsigned Count,
// TODO: Support multiple exiting blocks jumping to the `LatchExit` when // TODO: Support multiple exiting blocks jumping to the `LatchExit` when
// UnrollRuntimeMultiExit is true. This will need updating the logic in // UnrollRuntimeMultiExit is true. This will need updating the logic in
// connectEpilog. // connectEpilog.
if (!LatchExit->getSinglePredecessor()) if (!LatchExit->getSinglePredecessor()) {
DEBUG(dbgs() << "Bailout for multi-exit handling when latch exit has >1 "
"predecessor.\n");
return false; return false;
}
// FIXME: We bail out of multi-exit unrolling when epilog loop is generated // FIXME: We bail out of multi-exit unrolling when epilog loop is generated
// and L is an inner loop. This is because in presence of multiple exits, the // and L is an inner loop. This is because in presence of multiple exits, the
// outer loop is incorrect: we do not add the EpilogPreheader and exit to the // outer loop is incorrect: we do not add the EpilogPreheader and exit to the
@ -537,29 +550,38 @@ bool llvm::UnrollRuntimeLoopRemainder(Loop *L, unsigned Count,
// exiting blocks). // exiting blocks).
const SCEV *BECountSC = SE->getExitCount(L, Latch); const SCEV *BECountSC = SE->getExitCount(L, Latch);
if (isa<SCEVCouldNotCompute>(BECountSC) || if (isa<SCEVCouldNotCompute>(BECountSC) ||
!BECountSC->getType()->isIntegerTy()) !BECountSC->getType()->isIntegerTy()) {
DEBUG(dbgs() << "Could not compute exit block SCEV\n");
return false; return false;
}
unsigned BEWidth = cast<IntegerType>(BECountSC->getType())->getBitWidth(); unsigned BEWidth = cast<IntegerType>(BECountSC->getType())->getBitWidth();
// Add 1 since the backedge count doesn't include the first loop iteration. // Add 1 since the backedge count doesn't include the first loop iteration.
const SCEV *TripCountSC = const SCEV *TripCountSC =
SE->getAddExpr(BECountSC, SE->getConstant(BECountSC->getType(), 1)); SE->getAddExpr(BECountSC, SE->getConstant(BECountSC->getType(), 1));
if (isa<SCEVCouldNotCompute>(TripCountSC)) if (isa<SCEVCouldNotCompute>(TripCountSC)) {
DEBUG(dbgs() << "Could not compute trip count SCEV.\n");
return false; return false;
}
BasicBlock *PreHeader = L->getLoopPreheader(); BasicBlock *PreHeader = L->getLoopPreheader();
BranchInst *PreHeaderBR = cast<BranchInst>(PreHeader->getTerminator()); BranchInst *PreHeaderBR = cast<BranchInst>(PreHeader->getTerminator());
const DataLayout &DL = Header->getModule()->getDataLayout(); const DataLayout &DL = Header->getModule()->getDataLayout();
SCEVExpander Expander(*SE, DL, "loop-unroll"); SCEVExpander Expander(*SE, DL, "loop-unroll");
if (!AllowExpensiveTripCount && if (!AllowExpensiveTripCount &&
Expander.isHighCostExpansion(TripCountSC, L, PreHeaderBR)) Expander.isHighCostExpansion(TripCountSC, L, PreHeaderBR)) {
DEBUG(dbgs() << "High cost for expanding trip count scev!\n");
return false; return false;
}
// This constraint lets us deal with an overflowing trip count easily; see the // This constraint lets us deal with an overflowing trip count easily; see the
// comment on ModVal below. // comment on ModVal below.
if (Log2_32(Count) > BEWidth) if (Log2_32(Count) > BEWidth) {
DEBUG(dbgs()
<< "Count failed constraint on overflow trip count calculation.\n");
return false; return false;
}
// Loop structure is the following: // Loop structure is the following:
// //