diff --git a/llvm/include/llvm/Transforms/Utils/LoopPeel.h b/llvm/include/llvm/Transforms/Utils/LoopPeel.h --- a/llvm/include/llvm/Transforms/Utils/LoopPeel.h +++ b/llvm/include/llvm/Transforms/Utils/LoopPeel.h @@ -18,7 +18,8 @@ namespace llvm { -bool canPeel(Loop *L); +// We do the profitability checks for loop peeling under CheckPeelProfitability. +bool canPeel(Loop *L, const bool CheckPeelProfitability = true); bool peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, ScalarEvolution *SE, DominatorTree &DT, AssumptionCache *AC, bool PreserveLCSSA); diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp --- a/llvm/lib/Transforms/Utils/LoopPeel.cpp +++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp @@ -75,7 +75,7 @@ static const char *PeeledCountMetaData = "llvm.loop.peeled.count"; // Check whether we are capable of peeling this loop. -bool llvm::canPeel(Loop *L) { +bool llvm::canPeel(Loop *L, const bool CheckPeelProfitability) { // Make sure the loop is in simplified form if (!L->isLoopSimplifyForm()) return false; @@ -94,6 +94,10 @@ SmallVector Exits; L->getUniqueNonLatchExitBlocks(Exits); + // All legality checks are done. + if (!CheckPeelProfitability) + return true; + // The latch must either be the only exiting block or all non-latch exit // blocks have either a deopt or unreachable terminator or compose a chain of // blocks where the last one is either deopt or unreachable terminated. Both