[llvm-commits] [llvm] r94336 - /llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
Chris Lattner
sabre at nondot.org
Sat Jan 23 15:31:46 PST 2010
Author: lattner
Date: Sat Jan 23 17:31:46 2010
New Revision: 94336
URL: http://llvm.org/viewvc/llvm-project?rev=94336&view=rev
Log:
fix a potential overflow issue Eli pointed out.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp?rev=94336&r1=94335&r2=94336&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineShifts.cpp Sat Jan 23 17:31:46 2010
@@ -394,16 +394,16 @@
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());
}
More information about the llvm-commits
mailing list