[Mlir-commits] [libunwind] [openmp] [lld] [clang] [mlir] [clang-tools-extra] [flang] [compiler-rt] [lldb] [llvm] [BranchFolding] Fix missing predecessors of landing-pad (PR #77608)

Phoebe Wang llvmlistbot at llvm.org
Wed Jan 10 17:45:52 PST 2024


================
@@ -1363,6 +1363,14 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
         MachineBasicBlock *Pred = *(MBB->pred_end()-1);
         Pred->ReplaceUsesOfBlockWith(MBB, &*FallThrough);
       }
+      // Add rest successors of MBB to successors of FallThrough. Those
+      // successors are not directly reachable via MBB, so it should be
+      // landing-pad.
+      for (auto SI = MBB->succ_begin(), SE = MBB->succ_end(); SI != SE; ++SI)
+        if (*SI != &*FallThrough && !FallThrough->isSuccessor(*SI)) {
+          assert((*SI)->isEHPad() && "Bad CFG");
+          FallThrough->copySuccessor(MBB, SI);
+        }
----------------
phoebewang wrote:

It's checked by `isSuccessor`, so multi call is not a problem.
One problem, no matter add here or in `ReplaceUsesOfBlockWith`, is whether these successors be removed latter? I think adding an edge to a died BB may also problematic.

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


More information about the Mlir-commits mailing list