[llvm] e5692a5 - [NFCI][BasicBlockUtils] MergeBlockIntoPredecessor(): improve Dominator Tree updating

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 11 13:56:47 PDT 2021


Author: Roman Lebedev
Date: 2021-04-11T23:56:23+03:00
New Revision: e5692a564a73ef63b7baaf80c2b7a62ad74e9e66

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

LOG: [NFCI][BasicBlockUtils] MergeBlockIntoPredecessor(): improve Dominator Tree updating

Same as with TryToSimplifyUncondBranchFromEmptyBlock() patch.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/BasicBlockUtils.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 5364dd9fa2d5..5690200220d4 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -228,20 +228,22 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
   // These dominator edges will be redirected from Pred.
   std::vector<DominatorTree::UpdateType> Updates;
   if (DTU) {
-    SmallPtrSet<BasicBlock *, 2> UniqueSuccessors(succ_begin(BB), succ_end(BB));
-    Updates.reserve(1 + (2 * UniqueSuccessors.size()));
+    SmallPtrSet<BasicBlock *, 2> SuccsOfBB(succ_begin(BB), succ_end(BB));
+    SmallPtrSet<BasicBlock *, 2> SuccsOfPredBB(succ_begin(PredBB),
+                                               succ_begin(PredBB));
+    Updates.reserve(Updates.size() + 2 * SuccsOfBB.size() + 1);
     // Add insert edges first. Experimentally, for the particular case of two
     // blocks that can be merged, with a single successor and single predecessor
     // respectively, it is beneficial to have all insert updates first. Deleting
     // edges first may lead to unreachable blocks, followed by inserting edges
     // making the blocks reachable again. Such DT updates lead to high compile
     // times. We add inserts before deletes here to reduce compile time.
-    for (BasicBlock *UniqueSuccessor : UniqueSuccessors)
-      // This successor of BB may already have PredBB as a predecessor.
-      if (!llvm::is_contained(successors(PredBB), UniqueSuccessor))
-        Updates.push_back({DominatorTree::Insert, PredBB, UniqueSuccessor});
-    for (BasicBlock *UniqueSuccessor : UniqueSuccessors)
-      Updates.push_back({DominatorTree::Delete, BB, UniqueSuccessor});
+    for (BasicBlock *SuccOfBB : SuccsOfBB)
+      // This successor of BB may already be a PredBB's successor.
+      if (!SuccsOfPredBB.contains(SuccOfBB))
+        Updates.push_back({DominatorTree::Insert, PredBB, SuccOfBB});
+    for (BasicBlock *SuccOfBB : SuccsOfBB)
+      Updates.push_back({DominatorTree::Delete, BB, SuccOfBB});
     Updates.push_back({DominatorTree::Delete, PredBB, BB});
   }
 


        


More information about the llvm-commits mailing list