[SimplifyCFG] TryToSimplifyUncondBranchFromEmptyBlock(): switch to non-permissive...
authorRoman Lebedev <lebedev.ri@gmail.com>
Thu, 7 Jan 2021 20:10:43 +0000 (23:10 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Thu, 7 Jan 2021 23:15:25 +0000 (02:15 +0300)
... which requires not deleting edges that were just deleted already,
    by not processing the same predecessor more than once.

llvm/lib/Transforms/Utils/Local.cpp

index 38cfee3..7c962ed 100644 (file)
@@ -1048,11 +1048,13 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
   if (DTU) {
     Updates.push_back({DominatorTree::Delete, BB, Succ});
     // All predecessors of BB will be moved to Succ.
-    for (auto I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
-      Updates.push_back({DominatorTree::Delete, *I, BB});
+    SmallSetVector<BasicBlock *, 8> Predecessors(pred_begin(BB), pred_end(BB));
+    Updates.reserve(Updates.size() + 2 * Predecessors.size());
+    for (auto *Predecessor : Predecessors) {
+      Updates.push_back({DominatorTree::Delete, Predecessor, BB});
       // This predecessor of BB may already have Succ as a successor.
-      if (!llvm::is_contained(successors(*I), Succ))
-        Updates.push_back({DominatorTree::Insert, *I, Succ});
+      if (!llvm::is_contained(successors(Predecessor), Succ))
+        Updates.push_back({DominatorTree::Insert, Predecessor, Succ});
     }
   }
 
@@ -1109,7 +1111,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
                            "applying corresponding DTU updates.");
 
   if (DTU) {
-    DTU->applyUpdatesPermissive(Updates);
+    DTU->applyUpdates(Updates);
     DTU->deleteBB(BB);
   } else {
     BB->eraseFromParent(); // Delete the old basic block.