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

Chris Lattner lattner at cs.uiuc.edu
Tue Aug 9 19:07:43 PDT 2005



Changes in directory llvm/lib/Transforms/Scalar:

LoopSimplify.cpp updated: 1.58 -> 1.59
---
Log message:

Make loop-simplify produce better loops by turning PHI nodes like X = phi [X, Y]
into just Y.  This often occurs when it seperates loops that have collapsed loop
headers.  This implements LoopSimplify/phi-node-simplify.ll


---
Diffs of the changes:  (+16 -1)

 LoopSimplify.cpp |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/LoopSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.58 llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.59
--- llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.58	Thu Aug  4 19:56:55 2005
+++ llvm/lib/Transforms/Scalar/LoopSimplify.cpp	Tue Aug  9 21:07:32 2005
@@ -71,7 +71,7 @@
       AU.addPreserved<ImmediateDominators>();
       AU.addPreserved<DominatorTree>();
       AU.addPreserved<DominanceFrontier>();
-      AU.addPreservedID(BreakCriticalEdgesID);  // No crit edges added....
+      AU.addPreservedID(BreakCriticalEdgesID);  // No critical edges added.
     }
   private:
     bool ProcessLoop(Loop *L);
@@ -190,8 +190,23 @@
     Changed = true;
   }
 
+  // Scan over the PHI nodes in the loop header.  Since they now have only two
+  // incoming values (the loop is canonicalized), we may have simplified the PHI
+  // down to 'X = phi [X, Y]', which should be replaced with 'Y'.
+  PHINode *PN;
+  DominatorSet &DS = getAnalysis<DominatorSet>();
+  for (BasicBlock::iterator I = L->getHeader()->begin();
+       (PN = dyn_cast<PHINode>(I++)); )
+    if (Value *V = PN->hasConstantValue(true))
+      if (!isa<Instruction>(V) ||
+          DS.dominates(cast<Instruction>(V)->getParent(), L->getHeader())) {
+        PN->replaceAllUsesWith(V);
+        PN->eraseFromParent();
+      }
+
   for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
     Changed |= ProcessLoop(*I);
+
   return Changed;
 }
 






More information about the llvm-commits mailing list