[llvm-branch-commits] [llvm] ed9de61 - [SimplifyCFGPass] mergeEmptyReturnBlocks(): switch to non-permissive DomTree updates
Roman Lebedev via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jan 4 14:31:52 PST 2021
Author: Roman Lebedev
Date: 2021-01-05T01:26:36+03:00
New Revision: ed9de61cc3e280f84e3f0f98a49af21c7e59c4c9
URL: https://github.com/llvm/llvm-project/commit/ed9de61cc3e280f84e3f0f98a49af21c7e59c4c9
DIFF: https://github.com/llvm/llvm-project/commit/ed9de61cc3e280f84e3f0f98a49af21c7e59c4c9.diff
LOG: [SimplifyCFGPass] mergeEmptyReturnBlocks(): switch to non-permissive DomTree updates
... which requires not inserting an edge that already exists.
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 2c3454c46b30..c0edde8648f5 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -77,7 +77,6 @@ STATISTIC(NumSimpl, "Number of blocks simplified");
/// If we have more than one empty (other than phi node) return blocks,
/// merge them together to promote recursive block merging.
-// FIXME: switch to non-permissive DomTreeUpdater::applyUpdates().
static bool mergeEmptyReturnBlocks(Function &F, DomTreeUpdater *DTU) {
bool Changed = false;
@@ -143,7 +142,10 @@ static bool mergeEmptyReturnBlocks(Function &F, DomTreeUpdater *DTU) {
if (DTU) {
for (auto *Predecessor : predecessors(&BB)) {
Updates.push_back({DominatorTree::Delete, Predecessor, &BB});
- Updates.push_back({DominatorTree::Insert, Predecessor, RetBlock});
+ // But, iff Predecessor already branches to RetBlock,
+ // don't (re-)add DomTree edge, because it already exists.
+ if (!is_contained(successors(Predecessor), RetBlock))
+ Updates.push_back({DominatorTree::Insert, Predecessor, RetBlock});
}
}
BB.replaceAllUsesWith(RetBlock);
@@ -176,7 +178,7 @@ static bool mergeEmptyReturnBlocks(Function &F, DomTreeUpdater *DTU) {
}
if (DTU) {
- DTU->applyUpdatesPermissive(Updates);
+ DTU->applyUpdates(Updates);
for (auto *BB : DeadBlocks)
DTU->deleteBB(BB);
} else {
More information about the llvm-branch-commits
mailing list