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); } @@ -2646,11 +2645,11 @@ 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();