[llvm] [SimplifyCFG] Don't delete basic block if it is a partial cleanuppad (PR #157363)

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 8 21:54:56 PDT 2025


================
@@ -8340,8 +8340,9 @@ bool SimplifyCFGOpt::simplifyOnce(BasicBlock *BB) {
 
   // Remove basic blocks that have no predecessors (except the entry block)...
   // or that just have themself as a predecessor.  These are unreachable.
-  if ((pred_empty(BB) && BB != &BB->getParent()->getEntryBlock()) ||
-      BB->getSinglePredecessor() == BB) {
+  if (((pred_empty(BB) && BB != &BB->getParent()->getEntryBlock()) ||
+       BB->getSinglePredecessor() == BB) &&
+      (!BB->isEHPad() || BB->isEHPadWithReturn())) {
----------------
rnk wrote:

+1, I think if we are deleting an EHPad, where the EHPad instruction generates a token (`catchpad` / `cleanuppad`), we can iterate over the users and there should be two cases:
* `FuncletPadInst` (`within`)
* Terminators, `cleanupret` `catchret`

The terminators can be replaced with unreachable, and that should be easy. For any `FuncletPadInst` user, you can probably set the parent pad to `nullptr`.

I worry that the IR will be in an invalid state unless simplifycfg successfully cleans up the remaining dead blocks, but that's kind of the point of all of these uses. They ensure that mid-level transforms don't obscure the nesting structure.

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


More information about the llvm-commits mailing list