diff options
author | Philip Reames <listmail@philipreames.com> | 2021-06-03 10:28:10 -0700 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2021-06-03 10:33:14 -0700 |
commit | 44d70d298acc872f37819efcb101334674a289e9 (patch) | |
tree | 5ca53c9cd7c85b89862c9b0c600841c5dc2d0ada /llvm/lib/Transforms/Utils/LoopUnroll.cpp | |
parent | 8c48d77cdfe5c286dc98b9bf06bd2939d00c4bb4 (diff) | |
download | llvm-44d70d298acc872f37819efcb101334674a289e9.zip llvm-44d70d298acc872f37819efcb101334674a289e9.tar.gz llvm-44d70d298acc872f37819efcb101334674a289e9.tar.bz2 |
[LoopUnroll] Eliminate PreserveOnlyFirst parameter [nfc]
This is a first step towards simplifying the transform interface to be less error prone. The basic idea is that querying SCEV is cheap (since it's cached) and we can just check for properties related to branch folding in the transform method instead of relying on the heuristic part to pass everything in correctly.
Differential Revision: https://reviews.llvm.org/D103584
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUnroll.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUnroll.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp index 3fdcd0d..5f7395d 100644 --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -256,8 +256,7 @@ void llvm::simplifyLoopAfterUnroll(Loop *L, bool SimplifyIVs, LoopInfo *LI, /// /// PreserveCondBr indicates whether the conditional branch of the LatchBlock /// needs to be preserved. It is needed when we use trip count upper bound to -/// fully unroll the loop. If PreserveOnlyFirst is also set then only the first -/// conditional branch needs to be preserved. +/// fully unroll the loop. /// /// Similarly, TripMultiple divides the number of times that the LatchBlock may /// execute without exiting the loop. @@ -381,6 +380,11 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, any_of(ExitBlocks, [](const BasicBlock *BB) { return isa<PHINode>(BB->begin()); }); + const unsigned MaxTripCount = SE->getSmallConstantMaxTripCount(L); + const bool MaxOrZero = SE->isBackedgeTakenCountMaxOrZero(L); + + const bool PreserveOnlyFirst = ULO.Count == MaxTripCount && MaxOrZero; + // The current loop unroll pass can unroll loops that have // (1) single latch; and // (2a) latch is unconditional; or @@ -755,7 +759,7 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI, auto WillExit = [&](unsigned i, unsigned j) -> Optional<bool> { if (CompletelyUnroll) { - if (ULO.PreserveCondBr && j && !(ULO.PreserveOnlyFirst && i != 0)) + if (ULO.PreserveCondBr && j && !(PreserveOnlyFirst && i != 0)) return None; return j == 0; } |