Author: Roman Lebedev Date: 2021-01-06T01:52:36+03:00 New Revision: f98535686e3c1fa76986337639df1636282692c9
URL: https://github.com/llvm/llvm-project/commit/f98535686e3c1fa76986337639df1636282692c9 DIFF: https://github.com/llvm/llvm-project/commit/f98535686e3c1fa76986337639df1636282692c9.diff LOG: [SimplifyCFG] simplifyUnreachable(): switch to non-permissive DomTree updates ... which requires not removing a DomTree edge if the switch's default still points at that destination, because it can't be removed; ... and not processing the same predecessor more than once. Added: Modified: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Removed: ################################################################################ diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 9f808278d899..d01d9512212c 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -4616,7 +4616,6 @@ bool SimplifyCFGOpt::simplifyReturn(ReturnInst *RI, IRBuilder<> &Builder) { return false; } -// FIXME: switch to non-permissive DomTreeUpdater::applyUpdates(). bool SimplifyCFGOpt::simplifyUnreachable(UnreachableInst *UI) { BasicBlock *BB = UI->getParent(); @@ -4678,7 +4677,7 @@ bool SimplifyCFGOpt::simplifyUnreachable(UnreachableInst *UI) { std::vector<DominatorTree::UpdateType> Updates; - SmallVector<BasicBlock *, 8> Preds(predecessors(BB)); + SmallSetVector<BasicBlock *, 8> Preds(pred_begin(BB), pred_end(BB)); for (unsigned i = 0, e = Preds.size(); i != e; ++i) { auto *Predecessor = Preds[i]; Instruction *TI = Predecessor->getTerminator(); @@ -4718,7 +4717,9 @@ bool SimplifyCFGOpt::simplifyUnreachable(UnreachableInst *UI) { e = SU->case_end(); Changed = true; } - Updates.push_back({DominatorTree::Delete, Predecessor, BB}); + // Note that the default destination can't be removed! + if (SI->getDefaultDest() != BB) + Updates.push_back({DominatorTree::Delete, Predecessor, BB}); } else if (auto *II = dyn_cast<InvokeInst>(TI)) { if (II->getUnwindDest() == BB) { if (DTU) @@ -4785,7 +4786,7 @@ bool SimplifyCFGOpt::simplifyUnreachable(UnreachableInst *UI) { } if (DTU) - DTU->applyUpdatesPermissive(Updates); + DTU->applyUpdates(Updates); // If this block is now dead, remove it. if (pred_empty(BB) && BB != &BB->getParent()->getEntryBlock()) { _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits