[llvm] r273584 - [ValueTracking] simplify logic in ComputeNumSignBits (NFCI)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 23 10:41:59 PDT 2016
Author: spatel
Date: Thu Jun 23 12:41:59 2016
New Revision: 273584
URL: http://llvm.org/viewvc/llvm-project?rev=273584&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Analysis/ValueTracking.cpp
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=273584&r1=273583&r2=273584&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Thu Jun 23 12:41:59 2016
@@ -2153,25 +2153,18 @@ unsigned ComputeNumSignBits(Value *V, un
return VecSignBits;
APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0);
- APInt Mask;
computeKnownBits(V, KnownZero, KnownOne, Depth, Q);
- if (KnownZero.isNegative()) { // sign bit is 0
- Mask = KnownZero;
- } else if (KnownOne.isNegative()) { // sign bit is 1;
- Mask = KnownOne;
- } else {
- // Nothing known.
- return FirstAnswer;
- }
+ // If we know that the sign bit is either zero or one, determine the number of
+ // identical bits in the top of the input value.
+ if (KnownZero.isNegative())
+ return std::max(FirstAnswer, KnownZero.countLeadingOnes());
- // Okay, we know that the sign bit in Mask is set. Use CLZ to determine
- // the number of identical bits in the top of the input value.
- Mask = ~Mask;
- Mask <<= Mask.getBitWidth()-TyBits;
- // Return # leading zeros. We use 'min' here in case Val was zero before
- // shifting. We don't want to return '64' as for an i32 "0".
- return std::max(FirstAnswer, std::min(TyBits, Mask.countLeadingZeros()));
+ if (KnownOne.isNegative())
+ return std::max(FirstAnswer, KnownOne.countLeadingOnes());
+
+ // computeKnownBits gave us no extra information about the top bits.
+ return FirstAnswer;
}
/// This function computes the integer multiple of Base that equals V.
More information about the llvm-commits
mailing list