[PATCH] D131827: [LoopSimplify][NFC] Replace depth-first order process as depth_first accessor.

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 15 08:12:09 PDT 2022


reames requested changes to this revision.
reames added inline comments.
This revision now requires changes to proceed.


================
Comment at: llvm/lib/Transforms/Utils/LoopSimplify.cpp:731
   SmallVector<Loop *, 4> Worklist;
-  Worklist.push_back(L);
-
-  // Walk the worklist from front to back, pushing newly found sub loops onto
-  // the back. This will let us process loops from back to front in depth-first
-  // order. We can use this simple process because loops form a tree.
-  for (unsigned Idx = 0; Idx != Worklist.size(); ++Idx) {
-    Loop *L2 = Worklist[Idx];
-    Worklist.append(L2->begin(), L2->end());
-  }
+  for_each(depth_first(L),
+           [&Worklist](Loop *SubLoop) { Worklist.push_back(SubLoop); });
----------------
This looks wrong.  The original loop was pushing elements in inverse depth first order (i.e. from the root down) so that it could walk backwards through that order to get dfs.  You seem to be visiting each item in dfs, and adding them to worklist, and then still visiting them in inverse order.  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131827



More information about the llvm-commits mailing list