aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2021-04-11 23:08:19 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2021-04-11 23:56:23 +0300
commite5692a564a73ef63b7baaf80c2b7a62ad74e9e66 (patch)
tree56400b1d869eee29412d27e9661503f9f1b921de
parent[NFCI][Local] TryToSimplifyUncondBranchFromEmptyBlock(): improve Dominator Tr... (diff)
downloadllvm-project-e5692a564a73ef63b7baaf80c2b7a62ad74e9e66.tar.gz
llvm-project-e5692a564a73ef63b7baaf80c2b7a62ad74e9e66.tar.bz2
llvm-project-e5692a564a73ef63b7baaf80c2b7a62ad74e9e66.zip
[NFCI][BasicBlockUtils] MergeBlockIntoPredecessor(): improve Dominator Tree updating
Same as with TryToSimplifyUncondBranchFromEmptyBlock() patch.
-rw-r--r--llvm/lib/Transforms/Utils/BasicBlockUtils.cpp18
1 files changed, 10 insertions, 8 deletions
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});
}