The modified function was incorrectly (not unnecessarily) ignoring grandchild
loops, and this change fixes the bug. In particular, this fixes the handling of
the loop { inner, body }. The TODO in the same function is talking about the b1
self loop, which may be "unnecessarily" lost, but that is a different issue.
// not be necessary if we can retain such backedges.
if (Headers.count(Child->getHeader())) {
for (auto BB : Child->blocks()) {
+ if (LI.getLoopFor(BB) != Child)
+ continue;
LI.changeLoopFor(BB, NewLoop);
LLVM_DEBUG(dbgs() << "moved block from child: " << BB->getName()
<< "\n");
}
+ std::vector<Loop *> GrandChildLoops;
+ std::swap(GrandChildLoops, Child->getSubLoopsVector());
+ for (auto GrandChildLoop : GrandChildLoops) {
+ GrandChildLoop->setParentLoop(nullptr);
+ NewLoop->addChildLoop(GrandChildLoop);
+ }
LI.destroy(Child);
LLVM_DEBUG(dbgs() << "subsumed child loop (common header)\n");
continue;