[llvm] 13fca9d - [NFCI][SimplifyCFG] mergeEmptyReturnBlocks(): improve Dominator Tree updating
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 11 13:56:50 PDT 2021
Author: Roman Lebedev
Date: 2021-04-11T23:56:23+03:00
New Revision: 13fca9d8161e3a203dce6d7647763a07d39bed3f
URL: https://github.com/llvm/llvm-project/commit/13fca9d8161e3a203dce6d7647763a07d39bed3f
DIFF: https://github.com/llvm/llvm-project/commit/13fca9d8161e3a203dce6d7647763a07d39bed3f.diff
LOG: [NFCI][SimplifyCFG] mergeEmptyReturnBlocks(): improve Dominator Tree updating
Same as with previous patches.
Added:
Modified:
llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
index 38e7109ead57..f0702e00e380 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -142,13 +142,17 @@ static bool mergeEmptyReturnBlocks(Function &F, DomTreeUpdater *DTU) {
cast<ReturnInst>(RetBlock->getTerminator())->getOperand(0)) {
// All predecessors of BB should now branch to RetBlock instead.
if (DTU) {
- for (auto *Predecessor : predecessors(&BB)) {
+ SmallPtrSet<BasicBlock *, 2> PredsOfBB(pred_begin(&BB), pred_end(&BB));
+ SmallPtrSet<BasicBlock *, 2> PredsOfRetBlock(pred_begin(RetBlock),
+ pred_end(RetBlock));
+ Updates.reserve(Updates.size() + 2 * PredsOfBB.size());
+ for (auto *Predecessor : PredsOfBB)
// But, iff Predecessor already branches to RetBlock,
// don't (re-)add DomTree edge, because it already exists.
- if (!is_contained(successors(Predecessor), RetBlock))
+ if (!PredsOfRetBlock.contains(Predecessor))
Updates.push_back({DominatorTree::Insert, Predecessor, RetBlock});
+ for (auto *Predecessor : PredsOfBB)
Updates.push_back({DominatorTree::Delete, Predecessor, &BB});
- }
}
BB.replaceAllUsesWith(RetBlock);
DeadBlocks.emplace_back(&BB);
More information about the llvm-commits
mailing list