diff options
author | HaohaiWen <haohai.wen@intel.com> | 2024-01-11 22:09:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-11 22:09:41 +0800 |
commit | f892cc36fda6d25d4f7cbf68e95b17ba0af040b8 (patch) | |
tree | 3133fbbc818fa87524ddfdb59137dfae0aabc88b /llvm/lib/CodeGen/BranchFolding.cpp | |
parent | b6f96776c5c30d0b39dcf5db9aa2f497bf99685e (diff) | |
download | llvm-f892cc36fda6d25d4f7cbf68e95b17ba0af040b8.zip llvm-f892cc36fda6d25d4f7cbf68e95b17ba0af040b8.tar.gz llvm-f892cc36fda6d25d4f7cbf68e95b17ba0af040b8.tar.bz2 |
[BranchFolding] Fix missing predecessors of landing-pad (#77608)
When removing an empty machine basic block, all of its successors should
be inherited by its fall through MBB. This keeps CFG as only have one
entry which is required by LiveDebugValues.
Reland #77441 as LiveDebugValues test.
Diffstat (limited to 'llvm/lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | llvm/lib/CodeGen/BranchFolding.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp index 0801296..599b7c7 100644 --- a/llvm/lib/CodeGen/BranchFolding.cpp +++ b/llvm/lib/CodeGen/BranchFolding.cpp @@ -1363,6 +1363,14 @@ ReoptimizeBlock: 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); + } // If MBB was the target of a jump table, update jump tables to go to the // fallthrough instead. if (MachineJumpTableInfo *MJTI = MF.getJumpTableInfo()) @@ -1624,6 +1632,15 @@ ReoptimizeBlock: } else { DidChange = true; PMBB->ReplaceUsesOfBlockWith(MBB, CurTBB); + // Add rest successors of MBB to successors of CurTBB. 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 != CurTBB && !CurTBB->isSuccessor(*SI)) { + assert((*SI)->isEHPad() && "Bad CFG"); + CurTBB->copySuccessor(MBB, SI); + } // If this change resulted in PMBB ending in a conditional // branch where both conditions go to the same destination, // change this to an unconditional branch. |