From 85ebd541faf03a00d20ce3bdaf133aa6948c64f8 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 16 Mar 2004 06:00:15 +0000 Subject: [PATCH] Fix a regression from this patch: http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040308/013095.html Basically, this patch only updated the immediate dominatees of the header node to tell them that the preheader also dominated them. In practice, ALL dominatees of the header node are also dominated by the preheader. This fixes: LoopSimplify/2004-03-15-IncorrectDomUpdate. and PR293 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12434 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/LoopSimplify.cpp | 29 ++++++++++++--------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index 6fbf261835a..120f0297643 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -312,31 +312,28 @@ void LoopSimplify::InsertPreheaderForLoop(Loop *L) { DominatorSet &DS = getAnalysis(); // Update dominator info DominatorTree &DT = getAnalysis(); - DominatorTree::Node *HeaderDTNode = DT.getNode(Header); + + + // Update the dominator tree information. + // The immediate dominator of the preheader is the immediate dominator of + // the old header. + DominatorTree::Node *PHDomTreeNode = + DT.createNewNode(NewBB, DT.getNode(Header)->getIDom()); + + // Change the header node so that PNHode is the new immediate dominator + DT.changeImmediateDominator(DT.getNode(Header), PHDomTreeNode); { // The blocks that dominate NewBB are the blocks that dominate Header, // minus Header, plus NewBB. DominatorSet::DomSetType DomSet = DS.getDominators(Header); - DomSet.insert(NewBB); // We dominate ourself DomSet.erase(Header); // Header does not dominate us... DS.addBasicBlock(NewBB, DomSet); // The newly created basic block dominates all nodes dominated by Header. - for (DominatorTree::Node::iterator I = HeaderDTNode->begin(), - E = HeaderDTNode->end(); I != E; ++I) - DS.addDominator((*I)->getBlock(), NewBB); - } - - { // Update the dominator tree information. - // The immediate dominator of the preheader is the immediate dominator of - // the old header. - // - DominatorTree::Node *PHNode = - DT.createNewNode(NewBB, HeaderDTNode->getIDom()); - - // Change the header node so that PNHode is the new immediate dominator - DT.changeImmediateDominator(HeaderDTNode, PHNode); + for (df_iterator DFI = df_begin(PHDomTreeNode), + E = df_end(PHDomTreeNode); DFI != E; ++DFI) + DS.addDominator((*DFI)->getBlock(), NewBB); } // Update immediate dominator information if we have it...