From a8604e3d5b7112da11508f100805d65a4eddeb33 Mon Sep 17 00:00:00 2001 From: Roman Lebedev <lebedev.ri@gmail.com> Date: Mon, 4 Jan 2021 23:13:07 +0300 Subject: [PATCH] [SimplifyCFG] simplifyIndirectBr(): switch to non-permissive DomTree updates ... which requires not deleting an edge that just got deleted. --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 567b2e02b71c..60fa8a876b53 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -6218,19 +6218,18 @@ bool SimplifyCFGOpt::simplifySwitch(SwitchInst *SI, IRBuilder<> &Builder) { return false; } -// FIXME: switch to non-permissive DomTreeUpdater::applyUpdates(). bool SimplifyCFGOpt::simplifyIndirectBr(IndirectBrInst *IBI) { BasicBlock *BB = IBI->getParent(); bool Changed = false; // Eliminate redundant destinations. - std::vector<DominatorTree::UpdateType> Updates; SmallPtrSet<Value *, 8> Succs; + SmallSetVector<BasicBlock *, 8> RemovedSuccs; 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}); + RemovedSuccs.insert(Dest); Dest->removePredecessor(BB); IBI->removeDestination(i); --i; @@ -6239,9 +6238,13 @@ bool SimplifyCFGOpt::simplifyIndirectBr(IndirectBrInst *IBI) { } } - if (DTU) - DTU->applyUpdatesPermissive(Updates); - Updates.clear(); + if (DTU) { + std::vector<DominatorTree::UpdateType> Updates; + Updates.reserve(RemovedSuccs.size()); + for (auto *RemovedSucc : RemovedSuccs) + Updates.push_back({DominatorTree::Delete, BB, RemovedSucc}); + DTU->applyUpdates(Updates); + } if (IBI->getNumDestinations() == 0) { // If the indirectbr has no successors, change it to unreachable.