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

Chris Lattner lattner at cs.uiuc.edu
Sun Oct 17 14:22:43 PDT 2004



Changes in directory llvm/lib/Transforms/Scalar:

LoopSimplify.cpp updated: 1.51 -> 1.52
---
Log message:

hasConstantValue will soon return instructions that don't dominate the PHI node,
so prepare for this.


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

Index: llvm/lib/Transforms/Scalar/LoopSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.51 llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.52
--- llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.51	Mon Sep 27 21:40:37 2004
+++ llvm/lib/Transforms/Scalar/LoopSimplify.cpp	Sun Oct 17 16:22:29 2004
@@ -250,8 +250,11 @@
 
       // Can we eliminate this phi node now?
       if (Value *V = hasConstantValue(PN)) {
-        PN->replaceAllUsesWith(V);
-        BB->getInstList().erase(PN);
+        if (!isa<Instruction>(V) ||
+            getAnalysis<DominatorSet>().dominates(cast<Instruction>(V), PN)) {
+          PN->replaceAllUsesWith(V);
+          BB->getInstList().erase(PN);
+        }
       }
     }
     
@@ -426,22 +429,24 @@
 
 /// FindPHIToPartitionLoops - The first part of loop-nestification is to find a
 /// PHI node that tells us how to partition the loops.
-static PHINode *FindPHIToPartitionLoops(Loop *L) {
+static PHINode *FindPHIToPartitionLoops(Loop *L, DominatorSet &DS) {
   for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ) {
     PHINode *PN = cast<PHINode>(I);
     ++I;
-    if (Value *V = hasConstantValue(PN)) {
-      // This is a degenerate PHI already, don't modify it!
-      PN->replaceAllUsesWith(V);
-      PN->getParent()->getInstList().erase(PN);
-    } else {
-      // Scan this PHI node looking for a use of the PHI node by itself.
-      for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
-        if (PN->getIncomingValue(i) == PN &&
-            L->contains(PN->getIncomingBlock(i)))
-          // We found something tasty to remove.
-          return PN;
-    }
+    if (Value *V = hasConstantValue(PN))
+      if (!isa<Instruction>(V) || DS.dominates(cast<Instruction>(V), PN)) {
+        // This is a degenerate PHI already, don't modify it!
+        PN->replaceAllUsesWith(V);
+        PN->getParent()->getInstList().erase(PN);
+        continue;
+      }
+
+    // Scan this PHI node looking for a use of the PHI node by itself.
+    for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
+      if (PN->getIncomingValue(i) == PN &&
+          L->contains(PN->getIncomingBlock(i)))
+        // We found something tasty to remove.
+        return PN;
   }
   return 0;
 }
@@ -464,7 +469,7 @@
 /// created.
 ///
 Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
-  PHINode *PN = FindPHIToPartitionLoops(L);
+  PHINode *PN = FindPHIToPartitionLoops(L, getAnalysis<DominatorSet>());
   if (PN == 0) return 0;  // No known way to partition.
 
   // Pull out all predecessors that have varying values in the loop.  This






More information about the llvm-commits mailing list