[llvm] 0699da1 - [NFCI][Local] MergeBasicBlockIntoOnlyPred(): improve Dominator Tree updating
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 11 13:56:49 PDT 2021
Author: Roman Lebedev
Date: 2021-04-11T23:56:23+03:00
New Revision: 0699da1569870a4f7cf26534b87ca3c3b14caf3b
URL: https://github.com/llvm/llvm-project/commit/0699da1569870a4f7cf26534b87ca3c3b14caf3b
DIFF: https://github.com/llvm/llvm-project/commit/0699da1569870a4f7cf26534b87ca3c3b14caf3b.diff
LOG: [NFCI][Local] MergeBasicBlockIntoOnlyPred(): improve Dominator Tree updating
Same as with TryToSimplifyUncondBranchFromEmptyBlock()/MergeBlockIntoPredecessor() patch.
Added:
Modified:
llvm/lib/Transforms/Utils/Local.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 10e185956a49..e285f8aa7a20 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -738,12 +738,15 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB,
SmallVector<DominatorTree::UpdateType, 32> Updates;
if (DTU) {
- for (BasicBlock *PredPredBB : predecessors(PredBB)) {
+ SmallPtrSet<BasicBlock *, 2> PredsOfPredBB(pred_begin(PredBB),
+ pred_end(PredBB));
+ Updates.reserve(Updates.size() + 2 * PredsOfPredBB.size() + 1);
+ for (BasicBlock *PredOfPredBB : PredsOfPredBB)
// This predecessor of PredBB may already have DestBB as a successor.
- if (!llvm::is_contained(successors(PredPredBB), DestBB))
- Updates.push_back({DominatorTree::Insert, PredPredBB, DestBB});
- Updates.push_back({DominatorTree::Delete, PredPredBB, PredBB});
- }
+ if (PredOfPredBB != PredBB)
+ Updates.push_back({DominatorTree::Insert, PredOfPredBB, DestBB});
+ for (BasicBlock *PredOfPredBB : PredsOfPredBB)
+ Updates.push_back({DominatorTree::Delete, PredOfPredBB, PredBB});
Updates.push_back({DominatorTree::Delete, PredBB, DestBB});
}
More information about the llvm-commits
mailing list