[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopSimplify.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Mar 13 16:02:01 PST 2004


Changes in directory llvm/lib/Transforms/Scalar:

LoopSimplify.cpp updated: 1.34 -> 1.35

---
Log message:

This little patch speeds up the loop used to update the dominator set analysis.
On the testcase from GCC PR12440, which has a LOT of loops (1392 of which require
preheaders to be inserted), this speeds up the loopsimplify pass from 1.931s to
0.1875s.  The loop in question goes from 1.65s -> 0.0097s, which isn't bad. All of
these times are a debug build.

This adds a dependency on DominatorTree analysis that was not there before, but
we always had dominatortree available anyway, because LICM requires both loop
simplify and DT, so this doesn't add any extra analysis in practice.



---
Diffs of the changes:  (+18 -17)

Index: llvm/lib/Transforms/Scalar/LoopSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.34 llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.35
--- llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.34	Thu Feb  5 17:20:59 2004
+++ llvm/lib/Transforms/Scalar/LoopSimplify.cpp	Sat Mar 13 16:01:26 2004
@@ -56,6 +56,7 @@
       // We need loop information to identify the loops...
       AU.addRequired<LoopInfo>();
       AU.addRequired<DominatorSet>();
+      AU.addRequired<DominatorTree>();
 
       AU.addPreserved<LoopInfo>();
       AU.addPreserved<DominatorSet>();
@@ -279,6 +280,9 @@
     ChangeExitBlock(*ParentLoops, Header, NewBB);
   
   DominatorSet &DS = getAnalysis<DominatorSet>();  // Update dominator info
+  DominatorTree &DT = getAnalysis<DominatorTree>();
+  DominatorTree::Node *HeaderDTNode = DT.getNode(Header);
+
   {
     // The blocks that dominate NewBB are the blocks that dominate Header,
     // minus Header, plus NewBB.
@@ -288,10 +292,20 @@
     DS.addBasicBlock(NewBB, DomSet);
 
     // The newly created basic block dominates all nodes dominated by Header.
-    for (Function::iterator I = Header->getParent()->begin(),
-           E = Header->getParent()->end(); I != E; ++I)
-      if (DS.dominates(Header, I))
-        DS.addDominator(I, NewBB);
+    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);
   }
   
   // Update immediate dominator information if we have it...
@@ -303,19 +317,6 @@
     ID->setImmediateDominator(Header, NewBB);
   }
   
-  // Update DominatorTree information if it is active.
-  if (DominatorTree *DT = getAnalysisToUpdate<DominatorTree>()) {
-    // The immediate dominator of the preheader is the immediate dominator of
-    // the old header.
-    //
-    DominatorTree::Node *HeaderNode = DT->getNode(Header);
-    DominatorTree::Node *PHNode = DT->createNewNode(NewBB,
-                                                    HeaderNode->getIDom());
-    
-    // Change the header node so that PNHode is the new immediate dominator
-    DT->changeImmediateDominator(HeaderNode, PHNode);
-  }
-
   // Update dominance frontier information...
   if (DominanceFrontier *DF = getAnalysisToUpdate<DominanceFrontier>()) {
     // The DF(NewBB) is just (DF(Header)-Header), because NewBB dominates





More information about the llvm-commits mailing list