From d021ad9fbeb6d29c8551879f703f45e263e7a700 Mon Sep 17 00:00:00 2001 From: Serguei Katkov Date: Mon, 15 Jul 2019 09:13:11 +0000 Subject: [Loop Peeling] Fix the bug with IDom setting for exit loops It is possible that loop exit has two predecessors in a loop body. In this case after the peeling the iDom of the exit should be a clone of iDom of original exit but no a clone of a block coming to this exit. Reviewers: reames, fhahn Reviewed By: reames Subscribers: hiraditya, zzheng, llvm-commits Differential Revision: https://reviews.llvm.org/D64618 llvm-svn: 366050 --- llvm/lib/Transforms/Utils/LoopUnrollPeel.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Transforms/Utils/LoopUnrollPeel.cpp') diff --git a/llvm/lib/Transforms/Utils/LoopUnrollPeel.cpp b/llvm/lib/Transforms/Utils/LoopUnrollPeel.cpp index 6394d74f316..deb38df4420 100644 --- a/llvm/lib/Transforms/Utils/LoopUnrollPeel.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnrollPeel.cpp @@ -583,6 +583,18 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, SmallVector, 4> ExitEdges; L->getExitEdges(ExitEdges); + DenseMap ExitIDom; + if (DT) { + assert(L->hasDedicatedExits() && "No dedicated exits?"); + for (auto Edge : ExitEdges) { + if (ExitIDom.count(Edge.second)) + continue; + BasicBlock *BB = DT->getNode(Edge.second)->getIDom()->getBlock(); + assert(L->contains(BB) && "IDom is not in a loop"); + ExitIDom[Edge.second] = BB; + } + } + Function *F = Header->getParent(); // Set up all the necessary basic blocks. It is convenient to split the @@ -675,9 +687,9 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, // latter is the first cloned loop body, as original PreHeader dominates // the original loop body. if (Iter == 0) - for (auto Edge : ExitEdges) - DT->changeImmediateDominator(Edge.second, - cast(LVMap[Edge.first])); + for (auto Exit : ExitIDom) + DT->changeImmediateDominator(Exit.first, + cast(LVMap[Exit.second])); #ifdef EXPENSIVE_CHECKS assert(DT->verify(DominatorTree::VerificationLevel::Fast)); #endif @@ -719,6 +731,9 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, // We modified the loop, update SE. SE->forgetTopmostLoop(L); + // Finally DomtTree must be correct. + assert(DT->verify(DominatorTree::VerificationLevel::Fast)); + // FIXME: Incrementally update loop-simplify simplifyLoop(L, DT, LI, SE, AC, nullptr, PreserveLCSSA); -- cgit v1.2.3