case Instruction::And:
if (ConstantExpr::getAnd(N, Mask) == Mask) {
// If the AndRHS is a power of two minus one (0+1+), this is simple.
- if ((Mask->getValue() & Mask->getValue()+1) == 0)
+ if ((Mask->getValue().countLeadingZeros() +
+ Mask->getValue().countPopulation()) ==
+ Mask->getValue().getBitWidth())
break;
// Otherwise, if Mask is 0+1+0+, and if B is known to have the low 0+
if (isRunOfOnes(Mask, MB, ME)) { // begin/end bit of run, inclusive
uint32_t BitWidth = cast<IntegerType>(RHS->getType())->getBitWidth();
APInt Mask(APInt::getAllOnesValue(BitWidth));
- Mask = APIntOps::lshr(Mask, BitWidth-MB+1);
+ Mask = Mask.lshr(BitWidth-MB+1);
if (MaskedValueIsZero(RHS, Mask))
break;
}
case Instruction::Or:
case Instruction::Xor:
// If the AndRHS is a power of two minus one (0+1+), and N&Mask == 0
- if ((Mask->getValue() & Mask->getValue()+1) == 0 &&
- ConstantExpr::getAnd(N, Mask)->isNullValue())
+ if ((Mask->getValue().countLeadingZeros() +
+ Mask->getValue().countPopulation()) == Mask->getValue().getBitWidth()
+ && ConstantExpr::getAnd(N, Mask)->isNullValue())
break;
return 0;
}
// operation.
//
if (isValid && !isLeftShift && I.getOpcode() == Instruction::AShr) {
- APInt Val(Op0C->getValue());
- isValid = ((Val & APInt::getSignBit(TypeBits)) != 0) == highBitSet;
+ isValid = ((Op0C->getValue() & APInt::getSignBit(TypeBits)) != 0) ==
+ highBitSet;
}
if (isValid) {
if (ShiftOp && isa<ConstantInt>(ShiftOp->getOperand(1))) {
ConstantInt *ShiftAmt1C = cast<ConstantInt>(ShiftOp->getOperand(1));
- // shift amount always <= 32 bits
+ // These shift amounts are always <= 32 bits.
unsigned ShiftAmt1 = (unsigned)ShiftAmt1C->getZExtValue();
unsigned ShiftAmt2 = (unsigned)Op1->getZExtValue();
assert(ShiftAmt2 != 0 && "Should have been simplified earlier");
BinaryOperator::createAShr(X, ConstantInt::get(Ty, AmtSum));
InsertNewInstBefore(Shift, I);
- APInt Mask(APInt::getAllOnesValue(TypeBits).lshr(ShiftAmt2));
+ APInt Mask(Ty->getMask().lshr(ShiftAmt2));
return BinaryOperator::createAnd(Shift, ConstantInt::get(Mask));
}
if (ShiftAmt1 == ShiftAmt2) {
// If we have ((X >>? C) << C), turn this into X & (-1 << C).
if (I.getOpcode() == Instruction::Shl) {
- APInt Mask(APInt::getAllOnesValue(TypeBits).shl(ShiftAmt1));
+ APInt Mask(Ty->getMask().shl(ShiftAmt1));
return BinaryOperator::createAnd(X, ConstantInt::get(Mask));
}
// If we have ((X << C) >>u C), turn this into X & (-1 >>u C).
if (I.getOpcode() == Instruction::LShr) {
- APInt Mask(APInt::getAllOnesValue(TypeBits).lshr(ShiftAmt1));
+ APInt Mask(Ty->getMask().lshr(ShiftAmt1));
return BinaryOperator::createAnd(X, ConstantInt::get(Mask));
}
// We can simplify ((X << C) >>s C) into a trunc + sext.
case 16 : SExtType = Type::Int16Ty; break;
case 32 : SExtType = Type::Int32Ty; break;
case 64 : SExtType = Type::Int64Ty; break;
- case 128: SExtType = IntegerType::get(128); break;
default: break;
}
if (SExtType) {
BinaryOperator::createShl(X, ConstantInt::get(Ty, ShiftDiff));
InsertNewInstBefore(Shift, I);
- APInt Mask(APInt::getAllOnesValue(TypeBits).shl(ShiftAmt2));
+ APInt Mask(Ty->getMask().shl(ShiftAmt2));
return BinaryOperator::createAnd(Shift, ConstantInt::get(Mask));
}
BinaryOperator::createLShr(X, ConstantInt::get(Ty, ShiftDiff));
InsertNewInstBefore(Shift, I);
- APInt Mask(APInt::getAllOnesValue(TypeBits).lshr(ShiftAmt2));
+ APInt Mask(Ty->getMask().lshr(ShiftAmt2));
return BinaryOperator::createAnd(Shift, ConstantInt::get(Mask));
}
ConstantInt::get(Ty, ShiftDiff));
InsertNewInstBefore(Shift, I);
- APInt Mask(APInt::getAllOnesValue(TypeBits).shl(ShiftAmt2));
+ APInt Mask(Ty->getMask().shl(ShiftAmt2));
return BinaryOperator::createAnd(Shift, ConstantInt::get(Mask));
}
BinaryOperator::createShl(X, ConstantInt::get(Ty, ShiftDiff));
InsertNewInstBefore(Shift, I);
- APInt Mask(APInt::getAllOnesValue(TypeBits).lshr(ShiftAmt2));
+ APInt Mask(Ty->getMask().lshr(ShiftAmt2));
return BinaryOperator::createAnd(Shift, ConstantInt::get(Mask));
}