[llvm] [JumpThreading] Remove deleted BB from Unreachable (PR #126984)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 12 20:57:59 PST 2025


kazutakahirata wrote:

> Although an unreachable BB is skipped by processBlock, its successor can still be handled by processBlock, and maybeMergeBasicBlockIntoOnlyPred may merge the two BBs and delete the unreachable BB. Then the garbage pointer is left in Unreachable set. This patch removes the invalid BB pointer from the Unreachable set.

Ugh.  I've encountered essentially the same problem elsewhere in LLVM (although I don't remember where).  Meanwhile, in the inliner, when all call sites of a given `static` function have been inlined, we add the function to the list of dead functions, and then remove those dead functions after we are done inlining.

```
  if (Unreachable.count(SinglePred) && DTU->isBBPendingDeletion(SinglePred))
    Unreachable.erase(SinglePred);
```

I have a few questions about this:

- Is this the only place where a live basic block appears to be "Unreachable"?
- If `DTU->isBBPendingDeletion(SinglePred)` above is false, are we OK?  Does somebody else remove `SinglePred` from `Unrechable` for us?
- Is it feasible to keep all basic blocks without erasing them?  I'm guessing that this might be difficult because we sometimes call external utility functions to manipulate basic blocks, and those utility functions might remove basic blocks.

Thanks!


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


More information about the llvm-commits mailing list