[PATCH] D123230: [UnifyLoopExits] Reduce number of guard blocks

Brendon Cahoon via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 9 14:46:01 PDT 2022


bcahoon added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/UnifyLoopExits.cpp:235-242
+      for (auto Pred : predecessors(G)) {
+        auto PredLoop = LI.getLoopFor(Pred);
+        if (!ParentLoop->contains(PredLoop)) {
+          if (PredLoop)
+            LI.removeBlock(Pred);
+          ParentLoop->addBasicBlockToLoop(Pred, LI);
+        }
----------------
sameerds wrote:
> bcahoon wrote:
> > sameerds wrote:
> > > Scary stuff. Could you please add a comment? I think this is related to the test "unreachable_from_inner_loop" ... but an explanation in English will help a lot.
> > Agreed. Please let me know if this requires additional clarification.
> I am able to follow the test unreachable_from_inner_loop, but not seeing how the part about "if (PredLoop) remove pred" works. In the test, { B D F} is an inner loop, inside { A B D F G} and two guards are generated. But neither guard causes a node to move from a non-child loop to ParentLoop.
I've added a test case to show this condition. It requires at least 3 nested loops. A guard block predecessor is moved from the outermost loop to the middle loop.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123230/new/

https://reviews.llvm.org/D123230



More information about the llvm-commits mailing list