[llvm] a8604e3 - [SimplifyCFG] simplifyIndirectBr(): switch to non-permissive DomTree updates

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 4 14:26:58 PST 2021


Author: Roman Lebedev
Date: 2021-01-05T01:26:36+03:00
New Revision: a8604e3d5b7112da11508f100805d65a4eddeb33

URL: https://github.com/llvm/llvm-project/commit/a8604e3d5b7112da11508f100805d65a4eddeb33
DIFF: https://github.com/llvm/llvm-project/commit/a8604e3d5b7112da11508f100805d65a4eddeb33.diff

LOG: [SimplifyCFG] simplifyIndirectBr(): switch to non-permissive DomTree updates

... which requires not deleting an edge that just got deleted.

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 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.


        


More information about the llvm-commits mailing list