[llvm] [IR] Avoid self-referencing values caused by PHI node removal (PR #129501)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 5 07:24:44 PST 2025


================
@@ -335,15 +335,19 @@ bool JumpThreadingPass::runImpl(Function &F_, FunctionAnalysisManager *FAM_,
       if (&BB == &F->getEntryBlock() || DTU->isBBPendingDeletion(&BB))
         continue;
 
-      if (pred_empty(&BB)) {
+      if (SmallVector<BasicBlock *, 32> Unreachable =
+              unreachableFromBB(&BB, DTU.get());
+          !Unreachable.empty()) {
         // When processBlock makes BB unreachable it doesn't bother to fix up
         // the instructions in it. We must remove BB to prevent invalid IR.
-        LLVM_DEBUG(dbgs() << "  JT: Deleting dead block '" << BB.getName()
-                          << "' with terminator: " << *BB.getTerminator()
-                          << '\n');
-        LoopHeaders.erase(&BB);
-        LVI->eraseBlock(&BB);
-        DeleteDeadBlock(&BB, DTU.get());
+        for (BasicBlock *UBB : Unreachable) {
+          LLVM_DEBUG(dbgs()
+                     << "  JT: Deleting dead block '" << UBB->getName()
----------------
arsenm wrote:

Should use getNameOrAsOperand 

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


More information about the llvm-commits mailing list