diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp index c623f94d0de..0db5d9e772d 100644 --- a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp +++ b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp @@ -79,6 +79,17 @@ static BasicBlock *getOnlyLiveSuccessor(BasicBlock *BB) { return nullptr; } +/// Removes \p BB from all loops from [FirstLoop, LastLoop) in parent chain. +static void removeBlockFromLoops(BasicBlock *BB, Loop *FirstLoop, + Loop *LastLoop = nullptr) { + assert((!LastLoop || LastLoop->contains(FirstLoop->getHeader())) && + "First loop is supposed to be inside of last loop!"); + assert(FirstLoop->contains(BB) && "Must be a loop block!"); + for (Loop *Current = FirstLoop; Current != LastLoop; + Current = Current->getParentLoop()) + Current->removeBlockFromLoop(BB); +} + namespace { /// Helper class that can turn branches and switches with constant conditions /// into unconditional branches. @@ -371,12 +382,9 @@ private: // its parents as well). Make the fixup. if (StillReachable != OuterLoop) { LI.changeLoopFor(NewPreheader, StillReachable); - for (Loop *NotContaining = OuterLoop; NotContaining != StillReachable; - NotContaining = NotContaining->getParentLoop()) { - NotContaining->removeBlockFromLoop(NewPreheader); - for (auto *BB : L.blocks()) - NotContaining->removeBlockFromLoop(BB); - } + removeBlockFromLoops(NewPreheader, OuterLoop, StillReachable); + for (auto *BB : L.blocks()) + removeBlockFromLoops(BB, OuterLoop, StillReachable); OuterLoop->removeChildLoop(&L); if (StillReachable) StillReachable->addChildLoop(&L); |