mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-23 14:30:50 +00:00
fix a potential overflow issue Eli pointed out.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94336 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
44540740ae
commit
f7d0d163c5
@ -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());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user