Skip to content

Commit 8c2b535

Browse files
committed
[NFCI][SimplifyCFG] removeEmptyCleanup(): use DeleteDeadBlock()
This required some changes to, instead of eagerly making PHI's in the UnwindDest valid as-if the BB is already not a predecessor, to be valid while BB is still a predecessor.
1 parent bb5d613 commit 8c2b535

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4486,9 +4486,6 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
44864486
Value *SrcVal = DestPN.getIncomingValue(Idx);
44874487
PHINode *SrcPN = dyn_cast<PHINode>(SrcVal);
44884488

4489-
// Remove the entry for the block we are deleting.
4490-
DestPN.removeIncomingValue(Idx, false);
4491-
44924489
bool NeedPHITranslation = SrcPN && SrcPN->getParent() == BB;
44934490
for (auto *Pred : predecessors(BB)) {
44944491
Value *Incoming =
@@ -4516,12 +4513,15 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
45164513
if (pred != BB)
45174514
PN.addIncoming(&PN, pred);
45184515
PN.moveBefore(InsertPt);
4516+
// Also, add a dummy incoming value for the original BB itself,
4517+
// so that the PHI is well-formed until we drop said predecessor.
4518+
PN.addIncoming(UndefValue::get(PN.getType()), BB);
45194519
}
45204520
}
45214521

45224522
std::vector<DominatorTree::UpdateType> Updates;
45234523

4524-
// We use make_early_inc_range here because we may remove some predecessors.
4524+
// We use make_early_inc_range here because we will remove all predecessors.
45254525
for (BasicBlock *PredBB : llvm::make_early_inc_range(predecessors(BB))) {
45264526
if (UnwindDest == nullptr) {
45274527
if (DTU) {
@@ -4531,6 +4531,7 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
45314531
removeUnwindEdge(PredBB, DTU);
45324532
++NumInvokes;
45334533
} else {
4534+
BB->removePredecessor(PredBB);
45344535
Instruction *TI = PredBB->getTerminator();
45354536
TI->replaceUsesOfWith(BB, UnwindDest);
45364537
if (DTU) {
@@ -4540,12 +4541,10 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
45404541
}
45414542
}
45424543

4543-
if (DTU) {
4544+
if (DTU)
45444545
DTU->applyUpdates(Updates);
4545-
DTU->deleteBB(BB);
4546-
} else
4547-
// The cleanup pad is now unreachable. Zap it.
4548-
BB->eraseFromParent();
4546+
4547+
DeleteDeadBlock(BB, DTU);
45494548

45504549
return true;
45514550
}

0 commit comments

Comments
 (0)