aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/LoopPeel.cpp
diff options
context:
space:
mode:
authorAlina Sbirlea <asbirlea@google.com>2022-10-24 15:23:16 -0700
committerAlina Sbirlea <asbirlea@google.com>2022-10-25 12:19:14 -0700
commitd1b19da854fde9077a53400fabff486dc6dba022 (patch)
tree4b6f8c309f138530f331a7bc1a308684d1150a38 /llvm/lib/Transforms/Utils/LoopPeel.cpp
parent4981a186b3aa5fbe207dce4902d4dce504974f3f (diff)
downloadllvm-d1b19da854fde9077a53400fabff486dc6dba022.zip
llvm-d1b19da854fde9077a53400fabff486dc6dba022.tar.gz
llvm-d1b19da854fde9077a53400fabff486dc6dba022.tar.bz2
[LoopPeeling] Add flag to disable support for peeling loops with non-latch exits
Add a flag to allow disabling the changes in https://reviews.llvm.org/D134803. Differential Revision: https://reviews.llvm.org/D136643
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopPeel.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopPeel.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp
index d4f14df..b7e3eb2 100644
--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp
+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp
@@ -72,12 +72,32 @@ static cl::opt<unsigned> UnrollForcePeelCount(
"unroll-force-peel-count", cl::init(0), cl::Hidden,
cl::desc("Force a peel count regardless of profiling information."));
+static cl::opt<bool> DisableAdvancedPeeling(
+ "disable-advanced-peeling", cl::init(false), cl::Hidden,
+ cl::desc(
+ "Disable advance peeling. Issues for convergent targets (D134803)."));
+
static const char *PeeledCountMetaData = "llvm.loop.peeled.count";
// Check whether we are capable of peeling this loop.
bool llvm::canPeel(Loop *L) {
// Make sure the loop is in simplified form
- return L->isLoopSimplifyForm();
+ if (!L->isLoopSimplifyForm())
+ return false;
+ if (!DisableAdvancedPeeling)
+ return true;
+
+ SmallVector<BasicBlock *, 4> Exits;
+ L->getUniqueNonLatchExitBlocks(Exits);
+ // 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
+ // deopt and unreachable terminators are a strong indication they are not
+ // taken. Note that this is a profitability check, not a legality check. Also
+ // note that LoopPeeling currently can only update the branch weights of latch
+ // blocks and branch weights to blocks with deopt or unreachable do not need
+ // updating.
+ return llvm::all_of(Exits, IsBlockFollowedByDeoptOrUnreachable);
}
// This function calculates the number of iterations after which the given Phi