[ValueTracking] simplify logic in ComputeNumSignBits (NFCI)
This was noted in http://reviews.llvm.org/D21610 . The previous code predated the use of APInt ( http://reviews.llvm.org/rL47654 ), so it had to account for the fixed width of uint64_t. Now that we're using the variable width APInt, we can remove some complexity. llvm-svn: 273584
This commit is contained in:
parent
ef3358d579
commit
e053621071
|
@ -2153,25 +2153,18 @@ unsigned ComputeNumSignBits(Value *V, unsigned Depth, const Query &Q) {
|
||||||
return VecSignBits;
|
return VecSignBits;
|
||||||
|
|
||||||
APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0);
|
APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0);
|
||||||
APInt Mask;
|
|
||||||
computeKnownBits(V, KnownZero, KnownOne, Depth, Q);
|
computeKnownBits(V, KnownZero, KnownOne, Depth, Q);
|
||||||
|
|
||||||
if (KnownZero.isNegative()) { // sign bit is 0
|
// If we know that the sign bit is either zero or one, determine the number of
|
||||||
Mask = KnownZero;
|
// identical bits in the top of the input value.
|
||||||
} else if (KnownOne.isNegative()) { // sign bit is 1;
|
if (KnownZero.isNegative())
|
||||||
Mask = KnownOne;
|
return std::max(FirstAnswer, KnownZero.countLeadingOnes());
|
||||||
} else {
|
|
||||||
// Nothing known.
|
|
||||||
return FirstAnswer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Okay, we know that the sign bit in Mask is set. Use CLZ to determine
|
if (KnownOne.isNegative())
|
||||||
// the number of identical bits in the top of the input value.
|
return std::max(FirstAnswer, KnownOne.countLeadingOnes());
|
||||||
Mask = ~Mask;
|
|
||||||
Mask <<= Mask.getBitWidth()-TyBits;
|
// computeKnownBits gave us no extra information about the top bits.
|
||||||
// Return # leading zeros. We use 'min' here in case Val was zero before
|
return FirstAnswer;
|
||||||
// shifting. We don't want to return '64' as for an i32 "0".
|
|
||||||
return std::max(FirstAnswer, std::min(TyBits, Mask.countLeadingZeros()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function computes the integer multiple of Base that equals V.
|
/// This function computes the integer multiple of Base that equals V.
|
||||||
|
|
Loading…
Reference in New Issue