aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2023-01-20 16:33:39 +0000
committerFlorian Hahn <flo@fhahn.com>2023-01-20 16:33:40 +0000
commit12dd3a7b54cd19524fc29edba374d26972246744 (patch)
tree0a74291dbed882b0377aed4f735eac1df90cfcdd /llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
parentee3c6de722e77a7966764133b1b8a5cd1a1f562f (diff)
downloadllvm-12dd3a7b54cd19524fc29edba374d26972246744.zip
llvm-12dd3a7b54cd19524fc29edba374d26972246744.tar.gz
llvm-12dd3a7b54cd19524fc29edba374d26972246744.tar.bz2
Recommit "[LoopUnroll] Directly update DT instead of DTU."
This reverts commit c5ea42bcf48c8f3d3e35a6bff620b06d2a499108. Recommit the patch with a fix for loops where the exiting terminator is not a branch instruction. In that case, ExitInfos may be empty. In addition to checking if there's a single exiting block also check if there's a single ExitInfo. A test case has been added in f92b35392ed8e4631.
Diffstat (limited to 'llvm/lib/Transforms/Utils/BasicBlockUtils.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/BasicBlockUtils.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 9b35faf1..58a226f 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -179,7 +179,8 @@ bool llvm::DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI,
bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
LoopInfo *LI, MemorySSAUpdater *MSSAU,
MemoryDependenceResults *MemDep,
- bool PredecessorWithTwoSuccessors) {
+ bool PredecessorWithTwoSuccessors,
+ DominatorTree *DT) {
if (BB->hasAddressTaken())
return false;
@@ -232,10 +233,21 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
FoldSingleEntryPHINodes(BB, MemDep);
}
+ if (DT) {
+ assert(!DTU && "cannot use both DT and DTU for updates");
+ DomTreeNode *PredNode = DT->getNode(PredBB);
+ DomTreeNode *BBNode = DT->getNode(BB);
+ if (PredNode) {
+ assert(BBNode && "PredNode unreachable but BBNode reachable?");
+ for (DomTreeNode *C : to_vector(BBNode->children()))
+ C->setIDom(PredNode);
+ }
+ }
// DTU update: Collect all the edges that exit BB.
// These dominator edges will be redirected from Pred.
std::vector<DominatorTree::UpdateType> Updates;
if (DTU) {
+ assert(!DT && "cannot use both DT and DTU for updates");
// To avoid processing the same predecessor more than once.
SmallPtrSet<BasicBlock *, 8> SeenSuccs;
SmallPtrSet<BasicBlock *, 2> SuccsOfPredBB(succ_begin(PredBB),
@@ -311,6 +323,12 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU,
if (DTU)
DTU->applyUpdates(Updates);
+ if (DT) {
+ assert(succ_empty(BB) &&
+ "successors should have been transferred to PredBB");
+ DT->eraseNode(BB);
+ }
+
// Finally, erase the old block and update dominator info.
DeleteDeadBlock(BB, DTU);