Fix bug in previous checkin
authorChris Lattner <sabre@nondot.org>
Tue, 16 Mar 2004 23:36:49 +0000 (23:36 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 16 Mar 2004 23:36:49 +0000 (23:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12458 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/TailDuplication.cpp

index 45f0543fb2972f91c52f5cff91a5fbd3a7f09290..40821e450c626dea839b59b9936c58936ea84ed0 100644 (file)
@@ -157,8 +157,13 @@ void TailDup::eliminateUnconditionalBranch(BranchInst *Branch) {
         }
       } else if (PHINode *PN = dyn_cast<PHINode>(cast<Instruction>(*UI))) {
         // If the user of this instruction is a PHI node in the current block,
-        // spill the value.
-        ShouldDemote = true;
+        // which has an entry from another block using the value, spill it.
+        for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
+          if (PN->getIncomingValue(i) == I &&
+              PN->getIncomingBlock(i) != DestBlock) {
+            ShouldDemote = true;
+            break;
+          }
       }
 
       if (ShouldDemote) {