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

Phoebe Wang via flang-commits flang-commits at lists.llvm.org
Thu Jan 11 00:52:24 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:

This doesn't answer the questions. My questions are:

- Why can't put the code in `ReplaceUsesOfBlockWith`? The `isSuccessor` can make sure the same BB won't add again;
- Is it possible the added BB might be removed latter. We don't have a mechanism to remove the dead successors. Would it be a problem if we keep an edge to dead BBs?

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


More information about the flang-commits mailing list