summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/TargetLowering.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-05-06 23:48:13 +0000
committerChris Lattner <sabre@nondot.org>2006-05-06 23:48:13 +0000
commitcd4a64372823141e4c2a995d356daf7cd699e9a8 (patch)
treed5b6ceca4c441057b3c0e97a56b580c5ccf239e0 /llvm/lib/Target/TargetLowering.cpp
parent4f3de3e33c39f5652b0be7364a147a6353c5de06 (diff)
downloadbcm5719-llvm-cd4a64372823141e4c2a995d356daf7cd699e9a8.tar.gz
bcm5719-llvm-cd4a64372823141e4c2a995d356daf7cd699e9a8.zip
Use ComputeMaskedBits to determine # sign bits as a fallback. This allows us
to handle all kinds of stuff, including silly things like: sextinreg(setcc,i16) -> setcc. llvm-svn: 28155
Diffstat (limited to 'llvm/lib/Target/TargetLowering.cpp')
-rw-r--r--llvm/lib/Target/TargetLowering.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/llvm/lib/Target/TargetLowering.cpp b/llvm/lib/Target/TargetLowering.cpp
index 81e7785a847..41405408de5 100644
--- a/llvm/lib/Target/TargetLowering.cpp
+++ b/llvm/lib/Target/TargetLowering.cpp
@@ -1176,8 +1176,29 @@ unsigned TargetLowering::ComputeNumSignBits(SDOperand Op, unsigned Depth) const{
if (NumBits > 1) return NumBits;
}
- // FIXME: Should use computemaskedbits to look at the top bits.
- return 1;
+ // Finally, if we can prove that the top bits of the result are 0's or 1's,
+ // use this information.
+ uint64_t KnownZero, KnownOne;
+ uint64_t Mask = MVT::getIntVTBitMask(VT);
+ ComputeMaskedBits(Op, Mask, KnownZero, KnownOne, Depth);
+
+ uint64_t SignBit = MVT::getIntVTSignBit(VT);
+ if (KnownZero & SignBit) { // SignBit is 0
+ Mask = KnownZero;
+ } else if (KnownOne & SignBit) { // SignBit is 1;
+ Mask = KnownOne;
+ } else {
+ // Nothing known.
+ return 1;
+ }
+
+ // 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 ^= ~0ULL;
+ Mask <<= 64-VTBits;
+ // 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::min(VTBits, CountLeadingZeros_64(Mask));
}
OpenPOWER on IntegriCloud