[llvm] 242961f - [llvm][fix-irreducible] ensure that loop subtree under child is correctly reconnected to new loop

Tim Northover via llvm-commits llvm-commits at lists.llvm.org
Wed May 18 02:45:56 PDT 2022


Author: Sun Ziping
Date: 2022-05-18T10:45:52+01:00
New Revision: 242961f23b4abaca999611fd364e93a8d2186371

URL: https://github.com/llvm/llvm-project/commit/242961f23b4abaca999611fd364e93a8d2186371
DIFF: https://github.com/llvm/llvm-project/commit/242961f23b4abaca999611fd364e93a8d2186371.diff

LOG: [llvm][fix-irreducible] ensure that loop subtree under child is correctly reconnected to new loop

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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/FixIrreducible.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/FixIrreducible.cpp b/llvm/lib/Transforms/Utils/FixIrreducible.cpp
index e0ebf11da872..24539bd231c6 100644
--- a/llvm/lib/Transforms/Utils/FixIrreducible.cpp
+++ b/llvm/lib/Transforms/Utils/FixIrreducible.cpp
@@ -138,10 +138,18 @@ static void reconnectChildLoops(LoopInfo &LI, Loop *ParentLoop, Loop *NewLoop,
     // 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;


        


More information about the llvm-commits mailing list