[SimplifyCFG] TryToSimplifyUncondBranchFromEmptyBlock(): switch to non-permissive DomTree updates

... which requires not deleting edges that were just deleted already,
    by not processing the same predecessor more than once.
This commit is contained in:
Roman Lebedev 2021-01-07 23:10:43 +03:00
parent b3822728fa
commit 1f9b591ee6
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
1 changed files with 7 additions and 5 deletions

View File

@ -1048,11 +1048,13 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
if (DTU) {
Updates.push_back({DominatorTree::Delete, BB, Succ});
// All predecessors of BB will be moved to Succ.
for (auto I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
Updates.push_back({DominatorTree::Delete, *I, BB});
SmallSetVector<BasicBlock *, 8> Predecessors(pred_begin(BB), pred_end(BB));
Updates.reserve(Updates.size() + 2 * Predecessors.size());
for (auto *Predecessor : Predecessors) {
Updates.push_back({DominatorTree::Delete, Predecessor, BB});
// This predecessor of BB may already have Succ as a successor.
if (!llvm::is_contained(successors(*I), Succ))
Updates.push_back({DominatorTree::Insert, *I, Succ});
if (!llvm::is_contained(successors(Predecessor), Succ))
Updates.push_back({DominatorTree::Insert, Predecessor, Succ});
}
}
@ -1109,7 +1111,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
"applying corresponding DTU updates.");
if (DTU) {
DTU->applyUpdatesPermissive(Updates);
DTU->applyUpdates(Updates);
DTU->deleteBB(BB);
} else {
BB->eraseFromParent(); // Delete the old basic block.