From fdf710e920a197c3727e56b4e4aa23808d7a5098 Mon Sep 17 00:00:00 2001 From: Anna Thomas Date: Tue, 11 Jul 2017 20:44:37 +0000 Subject: [PATCH] [LoopUnrollRuntime] NFC: Add some debugging trace messages for why loop wasn't unrolled. llvm-svn: 307705 --- lib/Transforms/Utils/LoopUnrollRuntime.cpp | 38 +++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/Transforms/Utils/LoopUnrollRuntime.cpp b/lib/Transforms/Utils/LoopUnrollRuntime.cpp index 2b432426b24..9fbc00fbb01 100644 --- a/lib/Transforms/Utils/LoopUnrollRuntime.cpp +++ b/lib/Transforms/Utils/LoopUnrollRuntime.cpp @@ -471,21 +471,31 @@ bool llvm::UnrollRuntimeLoopRemainder(Loop *L, unsigned Count, LoopInfo *LI, ScalarEvolution *SE, DominatorTree *DT, bool PreserveLCSSA) { bool hasMultipleExitingBlocks = !L->getExitingBlock(); + DEBUG(dbgs() << "Trying runtime unrolling on Loop: \n"); + DEBUG(L->dump()); // 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; + } // Make sure the loop is in canonical form. - if (!L->isLoopSimplifyForm()) + if (!L->isLoopSimplifyForm()) { + DEBUG(dbgs() << "Not in simplify form!\n"); return false; + } // Guaranteed by LoopSimplifyForm. BasicBlock *Latch = L->getLoopLatch(); BasicBlock *Header = L->getHeader(); 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; + } // These are exit blocks other than the target of the latch exiting block. SmallVector OtherExits; BranchInst *LatchBR = cast(Latch->getTerminator()); @@ -515,8 +525,11 @@ bool llvm::UnrollRuntimeLoopRemainder(Loop *L, unsigned Count, // TODO: Support multiple exiting blocks jumping to the `LatchExit` when // UnrollRuntimeMultiExit is true. This will need updating the logic in // connectEpilog. - if (!LatchExit->getSinglePredecessor()) + if (!LatchExit->getSinglePredecessor()) { + DEBUG(dbgs() << "Bailout for multi-exit handling when latch exit has >1 " + "predecessor.\n"); return false; + } // 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 // 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). const SCEV *BECountSC = SE->getExitCount(L, Latch); if (isa(BECountSC) || - !BECountSC->getType()->isIntegerTy()) + !BECountSC->getType()->isIntegerTy()) { + DEBUG(dbgs() << "Could not compute exit block SCEV\n"); return false; + } unsigned BEWidth = cast(BECountSC->getType())->getBitWidth(); // Add 1 since the backedge count doesn't include the first loop iteration. const SCEV *TripCountSC = SE->getAddExpr(BECountSC, SE->getConstant(BECountSC->getType(), 1)); - if (isa(TripCountSC)) + if (isa(TripCountSC)) { + DEBUG(dbgs() << "Could not compute trip count SCEV.\n"); return false; + } BasicBlock *PreHeader = L->getLoopPreheader(); BranchInst *PreHeaderBR = cast(PreHeader->getTerminator()); const DataLayout &DL = Header->getModule()->getDataLayout(); SCEVExpander Expander(*SE, DL, "loop-unroll"); if (!AllowExpensiveTripCount && - Expander.isHighCostExpansion(TripCountSC, L, PreHeaderBR)) + Expander.isHighCostExpansion(TripCountSC, L, PreHeaderBR)) { + DEBUG(dbgs() << "High cost for expanding trip count scev!\n"); return false; + } // This constraint lets us deal with an overflowing trip count easily; see the // 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; + } // Loop structure is the following: //