Fix a regression from this patch:
authorChris Lattner <sabre@nondot.org>
Tue, 16 Mar 2004 06:00:15 +0000 (06:00 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 16 Mar 2004 06:00:15 +0000 (06:00 +0000)
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

index 6fbf261835a9e00e5ae41616b97d5e0a95518219..120f0297643a7d1ff5132a35f03263fb71a3d9ec 100644 (file)
@@ -312,31 +312,28 @@ void LoopSimplify::InsertPreheaderForLoop(Loop *L) {
   
   DominatorSet &DS = getAnalysis<DominatorSet>();  // Update dominator info
   DominatorTree &DT = getAnalysis<DominatorTree>();
-  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<DominatorTree::Node*> DFI = df_begin(PHDomTreeNode),
+           E = df_end(PHDomTreeNode); DFI != E; ++DFI)
+      DS.addDominator((*DFI)->getBlock(), NewBB);
   }
   
   // Update immediate dominator information if we have it...