1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

[SimplifyCFG] Teach simplifyIndirectBr() to preserve DomTree

This commit is contained in:
Roman Lebedev 2020-12-31 22:46:42 +03:00
parent 1a02f5b4c8
commit 67634ca7a8
2 changed files with 8 additions and 1 deletions

View File

@ -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);

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
; SimplifyCFG should eliminate redundant indirectbr edges.