forked from OSchip/llvm-project
[SimplifyCFG] Teach TryToMergeLandingPad() to preserve DomTree
This commit is contained in:
parent
6a1617d67c
commit
262ff9c23e
|
@ -6082,7 +6082,7 @@ bool SimplifyCFGOpt::simplifyIndirectBr(IndirectBrInst *IBI) {
|
|||
/// block when the inputs in the phi are the same for the two blocks being
|
||||
/// merged. In some cases, this could result in removal of the PHI entirely.
|
||||
static bool TryToMergeLandingPad(LandingPadInst *LPad, BranchInst *BI,
|
||||
BasicBlock *BB) {
|
||||
BasicBlock *BB, DomTreeUpdater *DTU) {
|
||||
auto Succ = BB->getUniqueSuccessor();
|
||||
assert(Succ);
|
||||
// If there's a phi in the successor block, we'd likely have to introduce
|
||||
|
@ -6103,6 +6103,8 @@ static bool TryToMergeLandingPad(LandingPadInst *LPad, BranchInst *BI,
|
|||
if (!BI2 || !BI2->isIdenticalTo(BI))
|
||||
continue;
|
||||
|
||||
std::vector<DominatorTree::UpdateType> Updates;
|
||||
|
||||
// We've found an identical block. Update our predecessors to take that
|
||||
// path instead and make ourselves dead.
|
||||
SmallPtrSet<BasicBlock *, 16> Preds;
|
||||
|
@ -6112,6 +6114,8 @@ static bool TryToMergeLandingPad(LandingPadInst *LPad, BranchInst *BI,
|
|||
assert(II->getNormalDest() != BB && II->getUnwindDest() == BB &&
|
||||
"unexpected successor");
|
||||
II->setUnwindDest(OtherPred);
|
||||
Updates.push_back({DominatorTree::Delete, Pred, BB});
|
||||
Updates.push_back({DominatorTree::Insert, Pred, OtherPred});
|
||||
}
|
||||
|
||||
// The debug info in OtherPred doesn't cover the merged control flow that
|
||||
|
@ -6127,11 +6131,14 @@ static bool TryToMergeLandingPad(LandingPadInst *LPad, BranchInst *BI,
|
|||
Succs.insert(succ_begin(BB), succ_end(BB));
|
||||
for (BasicBlock *Succ : Succs) {
|
||||
Succ->removePredecessor(BB);
|
||||
Updates.push_back({DominatorTree::Delete, BB, Succ});
|
||||
}
|
||||
|
||||
IRBuilder<> Builder(BI);
|
||||
Builder.CreateUnreachable();
|
||||
BI->eraseFromParent();
|
||||
if (DTU)
|
||||
DTU->applyUpdatesPermissive(Updates);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -6179,7 +6186,7 @@ bool SimplifyCFGOpt::simplifyUncondBranch(BranchInst *BI,
|
|||
if (LandingPadInst *LPad = dyn_cast<LandingPadInst>(I)) {
|
||||
for (++I; isa<DbgInfoIntrinsic>(I); ++I)
|
||||
;
|
||||
if (I->isTerminator() && TryToMergeLandingPad(LPad, BI, BB))
|
||||
if (I->isTerminator() && TryToMergeLandingPad(LPad, BI, BB, DTU))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
|
||||
|
||||
declare i32 @__gxx_personality_v0(...)
|
||||
|
|
Loading…
Reference in New Issue