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

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 10 06:51:51 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);
+        }
----------------
HaohaiWen wrote:

We need to run these code before removing MBB. ReplaceUsesOfBlockWith just replace one of its users. It may run many needed to be run multi times.

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


More information about the llvm-commits mailing list