Fix LICM/2003-12-11-SinkingToPHI.ll, and quite possibly all of the other known proble...
authorChris Lattner <sabre@nondot.org>
Thu, 11 Dec 2003 22:23:32 +0000 (22:23 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 11 Dec 2003 22:23:32 +0000 (22:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10409 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LICM.cpp

index 0d8a848cc0d76444992bf7af8904c86f7577ba50..3365e64af055ad725643cd6938945da6a3d749d4 100644 (file)
@@ -337,9 +337,18 @@ bool LICM::canSinkOrHoistInst(Instruction &I) {
 /// 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;
 }