[llvm] [MSSAUpdater] Replace recursion with worklist and cap it. (PR #150543)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 25 01:06:30 PDT 2025


================
@@ -230,9 +223,61 @@ MemoryAccess *MemorySSAUpdater::tryRemoveTrivialPhi(MemoryPhi *Phi,
     removeMemoryAccess(Phi);
   }
 
-  // We should only end up recursing in case we replaced something, in which
-  // case, we may have made other Phis trivial.
-  return recursePhi(Same);
+  // Continue traversal in a DFS worklist approach, in case we might find
+  // other trivial Phis.
+  if (!Same)
+    return nullptr;
+
+  TrackingVH<MemoryAccess> Result(Same);
----------------
nikic wrote:

I think the key issue in this code is not really that we can visit many users (which should be ok as they are only visited if an actual simplification occurs), but that we use TrackingVH for ... everything here, which is going to be very expensive.

Can we avoid it by using a visited set so that we don't have to worry about revisiting a phi that has been erased in a different iteration?

https://github.com/llvm/llvm-project/pull/150543


More information about the llvm-commits mailing list