[SimplifyCFG] Teach simplifyCommonResume() to preserve DomTree

This commit is contained in:
Roman Lebedev 2020-12-19 16:18:04 +03:00
parent 76e74d9395
commit c209b88dd4
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
3 changed files with 11 additions and 5 deletions

View File

@ -4159,7 +4159,7 @@ bool SimplifyCFGOpt::simplifyCommonResume(ResumeInst *RI) {
for (pred_iterator PI = pred_begin(TrivialBB), PE = pred_end(TrivialBB);
PI != PE;) {
BasicBlock *Pred = *PI++;
removeUnwindEdge(Pred);
removeUnwindEdge(Pred, DTU);
++NumInvokes;
}
@ -4170,11 +4170,17 @@ bool SimplifyCFGOpt::simplifyCommonResume(ResumeInst *RI) {
// predecessors.
TrivialBB->getTerminator()->eraseFromParent();
new UnreachableInst(RI->getContext(), TrivialBB);
if (DTU)
DTU->applyUpdatesPermissive({{DominatorTree::Delete, TrivialBB, BB}});
}
// Delete the resume block if all its predecessors have been removed.
if (pred_empty(BB))
BB->eraseFromParent();
if (pred_empty(BB)) {
if (DTU)
DTU->deleteBB(BB);
else
BB->eraseFromParent();
}
return !TrivialUnwindBlocks.empty();
}

View File

@ -1,4 +1,4 @@
; RUN: opt < %s -simplifycfg -S | FileCheck %s
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
;; Test case for bug 25299, contributed by David Majnemer.

View File

@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -simplifycfg -S | FileCheck %s
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
declare void @llvm.lifetime.start.p0i8(i64, i8*)
declare void @llvm.lifetime.end.p0i8(i64, i8*)