forked from OSchip/llvm-project
[SimplifyCFG] Teach simplifyIndirectBr() to preserve DomTree
This commit is contained in:
parent
b7c463d7b8
commit
9f17dab1f4
|
@ -6148,10 +6148,13 @@ bool SimplifyCFGOpt::simplifyIndirectBr(IndirectBrInst *IBI) {
|
|||
bool Changed = false;
|
||||
|
||||
// Eliminate redundant destinations.
|
||||
std::vector<DominatorTree::UpdateType> Updates;
|
||||
SmallPtrSet<Value *, 8> Succs;
|
||||
for (unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
|
||||
BasicBlock *Dest = IBI->getDestination(i);
|
||||
if (!Dest->hasAddressTaken() || !Succs.insert(Dest).second) {
|
||||
if (!Dest->hasAddressTaken())
|
||||
Updates.push_back({DominatorTree::Delete, BB, Dest});
|
||||
Dest->removePredecessor(BB);
|
||||
IBI->removeDestination(i);
|
||||
--i;
|
||||
|
@ -6160,6 +6163,10 @@ bool SimplifyCFGOpt::simplifyIndirectBr(IndirectBrInst *IBI) {
|
|||
}
|
||||
}
|
||||
|
||||
if (DTU)
|
||||
DTU->applyUpdatesPermissive(Updates);
|
||||
Updates.clear();
|
||||
|
||||
if (IBI->getNumDestinations() == 0) {
|
||||
// If the indirectbr has no successors, change it to unreachable.
|
||||
new UnreachableInst(IBI->getContext(), IBI);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
; RUN: opt -S -simplifycfg < %s | FileCheck %s
|
||||
; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 < %s | FileCheck %s
|
||||
|
||||
; SimplifyCFG should eliminate redundant indirectbr edges.
|
||||
|
||||
|
|
Loading…
Reference in New Issue