From 06dfbb50d70eea4ae38d655842626a0b9b224d5c Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Wed, 31 Jan 2018 22:54:37 +0000 Subject: Utils: Fix DomTree update for entry block If SplitBlockPredecessors was used on a function entry block, it wouldn't update the dominator tree. llvm-svn: 323928 --- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index 9d3593913fa..46df4f920e7 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -319,8 +319,15 @@ static void UpdateAnalysisInformation(BasicBlock *OldBB, BasicBlock *NewBB, DominatorTree *DT, LoopInfo *LI, bool PreserveLCSSA, bool &HasLoopExit) { // Update dominator tree if available. - if (DT) - DT->splitBlock(NewBB); + if (DT) { + if (OldBB == DT->getRootNode()->getBlock()) { + assert(NewBB == &NewBB->getParent()->getEntryBlock()); + DT->setNewRoot(NewBB); + } else { + // Split block expects NewBB to have a non-empty set of predecessors. + DT->splitBlock(NewBB); + } + } // The rest of the logic is only relevant for updating the loop structures. if (!LI) @@ -504,7 +511,6 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB, // Insert dummy values as the incoming value. for (BasicBlock::iterator I = BB->begin(); isa(I); ++I) cast(I)->addIncoming(UndefValue::get(I->getType()), NewBB); - return NewBB; } // Update DominatorTree, LoopInfo, and LCCSA analysis information. @@ -512,8 +518,11 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB, UpdateAnalysisInformation(BB, NewBB, Preds, DT, LI, PreserveLCSSA, HasLoopExit); - // Update the PHI nodes in BB with the values coming from NewBB. - UpdatePHINodes(BB, NewBB, Preds, BI, HasLoopExit); + if (!Preds.empty()) { + // Update the PHI nodes in BB with the values coming from NewBB. + UpdatePHINodes(BB, NewBB, Preds, BI, HasLoopExit); + } + return NewBB; } -- cgit v1.2.3