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

Chris Lattner lattner at cs.uiuc.edu
Thu Dec 11 16:24:01 PST 2003


Changes in directory llvm/lib/Transforms/Scalar:

LICM.cpp updated: 1.49 -> 1.50

---
Log message:

Fix LICM/2003-12-11-SinkingToPHI.ll, and quite possibly all of the other known problems in the universe.


---
Diffs of the changes:  (+11 -2)

Index: llvm/lib/Transforms/Scalar/LICM.cpp
diff -u llvm/lib/Transforms/Scalar/LICM.cpp:1.49 llvm/lib/Transforms/Scalar/LICM.cpp:1.50
--- llvm/lib/Transforms/Scalar/LICM.cpp:1.49	Wed Dec 10 16:35:56 2003
+++ llvm/lib/Transforms/Scalar/LICM.cpp	Thu Dec 11 16:23:32 2003
@@ -337,9 +337,18 @@
 /// exit blocks of the loop.
 ///
 bool LICM::isNotUsedInLoop(Instruction &I) {
-  for (Value::use_iterator UI = I.use_begin(), E = I.use_end(); UI != E; ++UI)
-    if (CurLoop->contains(cast<Instruction>(*UI)->getParent()))
+  for (Value::use_iterator UI = I.use_begin(), E = I.use_end(); UI != E; ++UI) {
+    Instruction *User = cast<Instruction>(*UI);
+    if (PHINode *PN = dyn_cast<PHINode>(User)) {
+      // PHI node uses occur in predecessor blocks!
+      for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
+        if (PN->getIncomingValue(i) == &I)
+          if (CurLoop->contains(PN->getIncomingBlock(i)))
+            return false;
+    } else if (CurLoop->contains(User->getParent())) {
       return false;
+    }
+  }
   return true;
 }
 





More information about the llvm-commits mailing list