diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index d245783ec652..cea34e16e7bf 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -694,7 +694,7 @@ void llvm::ComputeMaskedBits(Value *V, APInt &KnownZero, APInt &KnownOne, // taking conservative care to avoid excessive recursion. if (Depth < MaxDepth - 1 && !KnownZero && !KnownOne) { // Skip if every incoming value references to ourself. - if (P->hasConstantValue() == P) + if (dyn_cast_or_null(P->hasConstantValue())) break; KnownZero = APInt::getAllOnesValue(BitWidth); diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp index 5aef45925016..9af98e8a9b3d 100644 --- a/llvm/lib/VMCore/Instructions.cpp +++ b/llvm/lib/VMCore/Instructions.cpp @@ -167,6 +167,8 @@ Value *PHINode::hasConstantValue() const { // The case where the first value is this PHI. ConstantValue = getIncomingValue(i); } + if (ConstantValue == this) + return UndefValue::get(getType()); return ConstantValue; }