diff options
author | Florian Hahn <flo@fhahn.com> | 2025-05-25 19:21:31 +0100 |
---|---|---|
committer | Florian Hahn <flo@fhahn.com> | 2025-05-25 19:21:49 +0100 |
commit | 364d80e5c52db2b001dc2807fb78b4e0df397f55 (patch) | |
tree | c101be296568d0ee26377ec6c93cbfb15e1ba154 /llvm/lib/Transforms/Utils/LoopPeel.cpp | |
parent | 19f00c0570582e93140642cbb62e5b820722c8f1 (diff) | |
download | llvm-364d80e5c52db2b001dc2807fb78b4e0df397f55.zip llvm-364d80e5c52db2b001dc2807fb78b4e0df397f55.tar.gz llvm-364d80e5c52db2b001dc2807fb78b4e0df397f55.tar.bz2 |
[LoopPeel] Make sure bound in exit condition is loop invariant.
Follow-up to post-commit comment for
(https://github.com/llvm/llvm-project/pull/139551.
This should effectively be NFC, given the other existing restrictions.
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopPeel.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopPeel.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp index 52ce7af..f348d24 100644 --- a/llvm/lib/Transforms/Utils/LoopPeel.cpp +++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp @@ -330,10 +330,6 @@ static unsigned peelToTurnInvariantLoadsDerefencebale(Loop &L, bool llvm::canPeelLastIteration(const Loop &L, ScalarEvolution &SE) { const SCEV *BTC = SE.getBackedgeTakenCount(&L); - Value *Inc; - CmpPredicate Pred; - BasicBlock *Succ1; - BasicBlock *Succ2; // The loop must execute at least 2 iterations to guarantee that peeled // iteration executes. // TODO: Add checks during codegen. @@ -347,12 +343,18 @@ bool llvm::canPeelLastIteration(const Loop &L, ScalarEvolution &SE) { // * the exit condition must be a NE/EQ compare of an induction with step // of 1 and must only be used by the exiting branch. BasicBlock *Latch = L.getLoopLatch(); + Value *Inc; + Value *Bound; + CmpPredicate Pred; + BasicBlock *Succ1; + BasicBlock *Succ2; return Latch && Latch == L.getExitingBlock() && match(Latch->getTerminator(), - m_Br(m_OneUse(m_ICmp(Pred, m_Value(Inc), m_Value())), + m_Br(m_OneUse(m_ICmp(Pred, m_Value(Inc), m_Value(Bound))), m_BasicBlock(Succ1), m_BasicBlock(Succ2))) && ((Pred == CmpInst::ICMP_EQ && Succ2 == L.getHeader()) || (Pred == CmpInst::ICMP_NE && Succ1 == L.getHeader())) && + SE.isLoopInvariant(SE.getSCEV(Bound), &L) && match(SE.getSCEV(Inc), m_scev_AffineAddRec(m_SCEV(), m_scev_One(), m_SpecificLoop(&L))); } |