[llvm] [JumpThreading] Fix lifetime markers when alloca requires SSA renaming (PR #188147)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 31 04:16:31 PDT 2026


================
@@ -2004,6 +2000,33 @@ void JumpThreadingPass::updateSSA(BasicBlock *BB, BasicBlock *NewBB,
       continue;
     LLVM_DEBUG(dbgs() << "JT: Renaming non-local uses of: " << I << "\n");
 
+    if (isa<AllocaInst>(&I)) {
+      // If any lifetime marker for the alloca is no longer dominated by the
+      // alloca after jump threading, remove all lifetime markers. This avoids
+      // inserting PHI nodes for lifetime markers, which is invalid.
+      DominatorTree &DT = DTU->getDomTree();
+      bool HasNonDominatedLifetimeMarker = false;
+      SmallVector<Instruction *> LifetimeMarkers;
+      for (User *U : I.users()) {
+        auto *UserI = cast<Instruction>(U);
+        if (UserI->isLifetimeStartOrEnd()) {
+          if (!DT.dominates(&I, UserI))
+            HasNonDominatedLifetimeMarker = true;
+          LifetimeMarkers.push_back(UserI);
+        }
+      }
+      if (HasNonDominatedLifetimeMarker) {
+        // Remove all uses of lifetime markers from UsesToRename before
+        // erasing them. This prevents SSAUpdater from attempting to
+        // rewrite uses of instructions that have been deleted.
----------------
nikic wrote:

Might make more sense to move this code before UsersToRename is collected in the first place?

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


More information about the llvm-commits mailing list