fix a potential overflow issue Eli pointed out.
authorChris Lattner <sabre@nondot.org>
Sat, 23 Jan 2010 23:31:46 +0000 (23:31 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 23 Jan 2010 23:31:46 +0000 (23:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94336 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineShifts.cpp

index 9dd60dd4a25ec9f08588806f0d4da4ea0b0b567b..836bda36937c215aef7f0c154369b6d6959ec96d 100644 (file)
@@ -394,16 +394,16 @@ Instruction *InstCombiner::visitLShr(BinaryOperator &I) {
   
   if (ConstantInt *Op1C = dyn_cast<ConstantInt>(Op1))
     if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op0)) {
+      unsigned BitWidth = Op0->getType()->getScalarSizeInBits();
       // ctlz.i32(x)>>5  --> zext(x == 0)
       // cttz.i32(x)>>5  --> zext(x == 0)
       // ctpop.i32(x)>>5 --> zext(x == -1)
       if ((II->getIntrinsicID() == Intrinsic::ctlz ||
            II->getIntrinsicID() == Intrinsic::cttz ||
            II->getIntrinsicID() == Intrinsic::ctpop) &&
-          (1ULL << Op1C->getZExtValue()) ==
-            Op0->getType()->getScalarSizeInBits()) {
+          isPowerOf2_32(BitWidth) && Log2_32(BitWidth) == Op1C->getZExtValue()){
         bool isCtPop = II->getIntrinsicID() == Intrinsic::ctpop;
-        Constant *RHS = ConstantInt::getSigned(Op0->getType(), isCtPop ? -1 : 0);
+        Constant *RHS = ConstantInt::getSigned(Op0->getType(), isCtPop ? -1:0);
         Value *Cmp = Builder->CreateICmpEQ(II->getOperand(1), RHS);
         return new ZExtInst(Cmp, II->getType());
       }