Now that hasConstantValue has been made simpler, it may return the
authorDuncan Sands <baldrick@free.fr>
Wed, 17 Nov 2010 10:23:23 +0000 (10:23 +0000)
committerDuncan Sands <baldrick@free.fr>
Wed, 17 Nov 2010 10:23:23 +0000 (10:23 +0000)
phi node itself if it occurs in an unreachable basic block.  Protect
against this.  Hopefully this will fix some more buildbots.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119493 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/Lint.cpp
lib/VMCore/BasicBlock.cpp

index e5e7cd38576fc56f6133c507f3e3b66e989bd006..0cdb4b1a1c91bf62d6ec413959ac72fcf6c11329 100644 (file)
@@ -583,7 +583,8 @@ Value *Lint::findValueImpl(Value *V, bool OffsetOk,
     }
   } else if (PHINode *PN = dyn_cast<PHINode>(V)) {
     if (Value *W = PN->hasConstantValue())
-      return findValueImpl(W, OffsetOk, Visited);
+      if (W != V)
+        return findValueImpl(W, OffsetOk, Visited);
   } else if (CastInst *CI = dyn_cast<CastInst>(V)) {
     if (CI->isNoopCast(TD ? TD->getIntPtrType(V->getContext()) :
                             Type::getInt64Ty(V->getContext())))
index 8ad53736c993f9c3c79e2737d1186bc8f50df76f..955a0285b2602056a68ea8dbee0eaa0b5d0e08a5 100644 (file)
@@ -248,10 +248,11 @@ void BasicBlock::removePredecessor(BasicBlock *Pred,
       // If all incoming values to the Phi are the same, we can replace the Phi
       // with that value.
       Value* PNV = 0;
-      if (!DontDeleteUselessPHIs && (PNV = PN->hasConstantValue())) {
-        PN->replaceAllUsesWith(PNV);
-        PN->eraseFromParent();
-      }
+      if (!DontDeleteUselessPHIs && (PNV = PN->hasConstantValue()))
+        if (PNV != PN) {
+          PN->replaceAllUsesWith(PNV);
+          PN->eraseFromParent();
+        }
     }
   }
 }