X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTarget%2FSystemZ%2FSystemZISelLowering.cpp;h=9e75306e0e595106b7749657c2f7b644e0550743;hb=a9204bb532cb1bce50532ba385e3655300124022;hp=e0cb376d11d254a30a81abd925b16695703cbe0d;hpb=1b103763190e2b4c22ccd589e806915e3c7d96eb;p=oota-llvm.git diff --git a/lib/Target/SystemZ/SystemZISelLowering.cpp b/lib/Target/SystemZ/SystemZISelLowering.cpp index e0cb376d11d..9e75306e0e5 100644 --- a/lib/Target/SystemZ/SystemZISelLowering.cpp +++ b/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);