diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -373,10 +373,9 @@ static unsigned ComputeNumSignBits(const Value *V, unsigned Depth, const Query &Q) { Type *Ty = V->getType(); + auto *FVTy = dyn_cast(Ty); APInt DemandedElts = - Ty->isVectorTy() - ? APInt::getAllOnesValue(cast(Ty)->getNumElements()) - : APInt(1, 1); + FVTy ? APInt::getAllOnesValue(FVTy->getNumElements()) : APInt(1, 1); return ComputeNumSignBits(V, DemandedElts, Depth, Q); } @@ -2638,19 +2637,19 @@ return CLow->sle(*CHigh); } -/// For vector constants, loop over the elements and find the constant with the -/// minimum number of sign bits. Return 0 if the value is not a vector constant -/// or if any element was not analyzed; otherwise, return the count for the -/// element with the minimum number of sign bits. -static unsigned computeNumSignBitsVectorConstant(const Value *V, +/// For fixed width vector constants, loop over the elements and find the +/// constant with the minimum number of sign bits. Return 0 if the value is +/// not a vector constant or if any element was not analyzed; otherwise, +/// return the count for the element with the minimum number of sign bits. +static unsigned ComputeNumSignBitsVectorConstant(const Value *V, const APInt &DemandedElts, unsigned TyBits) { const auto *CV = dyn_cast(V); - if (!CV || !CV->getType()->isVectorTy()) + if (!CV || !isa(CV->getType())) return 0; unsigned MinSignBits = TyBits; - unsigned NumElts = cast(CV->getType())->getNumElements(); + unsigned NumElts = cast(CV->getType())->getNumElements(); for (unsigned i = 0; i != NumElts; ++i) { if (!DemandedElts[i]) continue; @@ -2680,9 +2679,9 @@ /// the other bits. We know that at least 1 bit is always equal to the sign bit /// (itself), but other cases can give us information. For example, immediately /// after an "ashr X, 2", we know that the top 3 bits are all equal to each -/// other, so we return 3. For vectors, return the number of sign bits for the -/// vector element with the minimum number of known sign bits of the demanded -/// elements in the vector specified by DemandedElts. +/// other, so we return 3. For fixed width vectors, return the number of sign +/// bits for the vector element with the minimum number of known sign bits of +/// the demanded elements in the vector specified by DemandedElts. static unsigned ComputeNumSignBitsImpl(const Value *V, const APInt &DemandedElts, unsigned Depth, const Query &Q) { @@ -2693,9 +2692,10 @@ // same behavior for poison though -- that's a FIXME today. Type *Ty = V->getType(); - assert(((Ty->isVectorTy() && cast(Ty)->getNumElements() == - DemandedElts.getBitWidth()) || - (!Ty->isVectorTy() && DemandedElts == APInt(1, 1))) && + assert(((isa(Ty) && + cast(Ty)->getNumElements() == + DemandedElts.getBitWidth()) || + (!isa(Ty) && DemandedElts == APInt(1, 1))) && "Unexpected vector size"); Type *ScalarTy = Ty->getScalarType(); @@ -2967,7 +2967,7 @@ // If we can examine all elements of a vector constant successfully, we're // done (we can't do any better than that). If not, keep trying. if (unsigned VecSignBits = - computeNumSignBitsVectorConstant(V, DemandedElts, TyBits)) + ComputeNumSignBitsVectorConstant(V, DemandedElts, TyBits)) return VecSignBits; KnownBits Known(TyBits);