forked from OSchip/llvm-project
[SimplifyCFG] Teach removeEmptyCleanup() to preserve DomTree
This commit is contained in:
parent
4be8707e64
commit
76e74d9395
llvm
|
@ -4205,7 +4205,7 @@ bool SimplifyCFGOpt::simplifySingleResume(ResumeInst *RI) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool removeEmptyCleanup(CleanupReturnInst *RI) {
|
static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
|
||||||
// If this is a trivial cleanup pad that executes no instructions, it can be
|
// If this is a trivial cleanup pad that executes no instructions, it can be
|
||||||
// eliminated. If the cleanup pad continues to the caller, any predecessor
|
// eliminated. If the cleanup pad continues to the caller, any predecessor
|
||||||
// that is an EH pad will be updated to continue to the caller and any
|
// that is an EH pad will be updated to continue to the caller and any
|
||||||
|
@ -4312,20 +4312,32 @@ static bool removeEmptyCleanup(CleanupReturnInst *RI) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<DominatorTree::UpdateType> Updates;
|
||||||
|
|
||||||
for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE;) {
|
for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE;) {
|
||||||
// The iterator must be updated here because we are removing this pred.
|
// The iterator must be updated here because we are removing this pred.
|
||||||
BasicBlock *PredBB = *PI++;
|
BasicBlock *PredBB = *PI++;
|
||||||
if (UnwindDest == nullptr) {
|
if (UnwindDest == nullptr) {
|
||||||
removeUnwindEdge(PredBB);
|
if (DTU)
|
||||||
|
DTU->applyUpdatesPermissive(Updates);
|
||||||
|
Updates.clear();
|
||||||
|
removeUnwindEdge(PredBB, DTU);
|
||||||
++NumInvokes;
|
++NumInvokes;
|
||||||
} else {
|
} else {
|
||||||
Instruction *TI = PredBB->getTerminator();
|
Instruction *TI = PredBB->getTerminator();
|
||||||
TI->replaceUsesOfWith(BB, UnwindDest);
|
TI->replaceUsesOfWith(BB, UnwindDest);
|
||||||
|
Updates.push_back({DominatorTree::Delete, PredBB, BB});
|
||||||
|
Updates.push_back({DominatorTree::Insert, PredBB, UnwindDest});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The cleanup pad is now unreachable. Zap it.
|
if (DTU) {
|
||||||
BB->eraseFromParent();
|
DTU->applyUpdatesPermissive(Updates);
|
||||||
|
DTU->deleteBB(BB);
|
||||||
|
} else
|
||||||
|
// The cleanup pad is now unreachable. Zap it.
|
||||||
|
BB->eraseFromParent();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4372,7 +4384,7 @@ bool SimplifyCFGOpt::simplifyCleanupReturn(CleanupReturnInst *RI) {
|
||||||
if (mergeCleanupPad(RI))
|
if (mergeCleanupPad(RI))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (removeEmptyCleanup(RI))
|
if (removeEmptyCleanup(RI, DTU))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
; Tests that the dynamic allocation and deallocation of the coroutine frame is
|
; Tests that the dynamic allocation and deallocation of the coroutine frame is
|
||||||
; elided and any tail calls referencing the coroutine frame has the tail
|
; elided and any tail calls referencing the coroutine frame has the tail
|
||||||
; call attribute removed.
|
; call attribute removed.
|
||||||
; RUN: opt < %s -S -inline -coro-elide -instsimplify -simplifycfg | FileCheck %s
|
; RUN: opt < %s -S -inline -coro-elide -instsimplify -simplifycfg -simplifycfg-require-and-preserve-domtree=1 | FileCheck %s
|
||||||
; RUN: opt < %s -S \
|
; RUN: opt < %s -S \
|
||||||
; RUN: -passes='cgscc(inline,function(coro-elide,instsimplify,simplify-cfg))' \
|
; RUN: -passes='cgscc(inline,function(coro-elide,instsimplify,simplify-cfg))' \
|
||||||
; RUN: -aa-pipeline='basic-aa' | FileCheck %s
|
; RUN: -aa-pipeline='basic-aa' | FileCheck %s
|
||||||
|
|
Loading…
Reference in New Issue