diff options
author | 2021-04-11 23:25:40 +0300 | |
---|---|---|
committer | 2021-04-11 23:56:23 +0300 | |
commit | 13fca9d8161e3a203dce6d7647763a07d39bed3f (patch) | |
tree | 8047aa34dce2811e7eefa5a807ed600738e2c6f9 | |
parent | [NFCI][Local] MergeBasicBlockIntoOnlyPred(): improve Dominator Tree updating (diff) | |
download | llvm-project-13fca9d8161e3a203dce6d7647763a07d39bed3f.tar.gz llvm-project-13fca9d8161e3a203dce6d7647763a07d39bed3f.tar.bz2 llvm-project-13fca9d8161e3a203dce6d7647763a07d39bed3f.zip |
[NFCI][SimplifyCFG] mergeEmptyReturnBlocks(): improve Dominator Tree updating
Same as with previous patches.
-rw-r--r-- | llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
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); |