From d1fd57765b78eaad11acad79d17b4703b67a9d71 Mon Sep 17 00:00:00 2001 From: Vikram TV Date: Sat, 11 Jun 2016 16:41:10 +0000 Subject: [PATCH] Delay dominator updation while cloning loop. Summary: Dominator updation fails for a loop inserted with a new basicblock. A block required by DT to set the IDom might not have been cloned yet. This is because there is no predefined ordering of loop blocks (except for the header block which should be the first block in the list). The patch first creates DT nodes for the cloned blocks and then separately updates the DT in a follow-on loop. Reviewers: anemet, dberlin Subscribers: dberlin, llvm-commits Differential Revision: http://reviews.llvm.org/D20899 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272479 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/CloneFunction.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp index b64fdbd7b1a..6ff05fe3e59 100644 --- a/lib/Transforms/Utils/CloneFunction.cpp +++ b/lib/Transforms/Utils/CloneFunction.cpp @@ -688,13 +688,19 @@ Loop *llvm::cloneLoopWithPreheader(BasicBlock *Before, BasicBlock *LoopDomBB, // Update LoopInfo. NewLoop->addBasicBlockToLoop(NewBB, *LI); - // Update DominatorTree. - BasicBlock *IDomBB = DT->getNode(BB)->getIDom()->getBlock(); - DT->addNewBlock(NewBB, cast(VMap[IDomBB])); + // Add DominatorTree node. After seeing all blocks, update to correct IDom. + DT->addNewBlock(NewBB, NewPH); Blocks.push_back(NewBB); } + for (BasicBlock *BB : OrigLoop->getBlocks()) { + // Update DominatorTree. + BasicBlock *IDomBB = DT->getNode(BB)->getIDom()->getBlock(); + DT->changeImmediateDominator(cast(VMap[BB]), + cast(VMap[IDomBB])); + } + // Move them physically from the end of the block list. F->getBasicBlockList().splice(Before->getIterator(), F->getBasicBlockList(), NewPH); -- 2.50.1