diff options
| author | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2015-03-31 19:28:50 +0000 |
|---|---|---|
| committer | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2015-03-31 19:28:50 +0000 |
| commit | 050527b4ac63e378697191e494f8f96638b534df (patch) | |
| tree | ff170c1f3aba0a4d848da47ce30e0dc3996d65cf | |
| parent | 537287041bdff4e384d31f9258aab1452405c73d (diff) | |
| download | bcm5719-llvm-050527b4ac63e378697191e494f8f96638b534df.tar.gz bcm5719-llvm-050527b4ac63e378697191e494f8f96638b534df.zip | |
[SystemZ] Address review comments for r233689
Change lowerCTPOP to:
- Gracefully handle a known-zero input value
- Simplify computation of significant bit size
Thanks to Jay Foad for the review!
llvm-svn: 233736
| -rw-r--r-- | llvm/lib/Target/SystemZ/SystemZISelLowering.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp index e0cb376d11d..9e75306e0e5 100644 --- a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp +++ b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp @@ -2319,12 +2319,13 @@ SDValue SystemZTargetLowering::lowerCTPOP(SDValue Op, Op = Op.getOperand(0); APInt KnownZero, KnownOne; DAG.computeKnownBits(Op, KnownZero, KnownOne); - uint64_t Mask = ~KnownZero.getZExtValue(); + unsigned NumSignificantBits = (~KnownZero).getActiveBits(); + if (NumSignificantBits == 0) + return DAG.getConstant(0, VT); // Skip known-zero high parts of the operand. - int64_t BitSize = OrigBitSize; - while ((Mask & ((((uint64_t)1 << (BitSize / 2)) - 1) << (BitSize / 2))) == 0) - BitSize = BitSize / 2; + int64_t BitSize = (int64_t)1 << Log2_32_Ceil(NumSignificantBits); + BitSize = std::min(BitSize, OrigBitSize); // The POPCNT instruction counts the number of bits in each byte. Op = DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64, Op); |

