mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-25 21:18:19 +00:00
optimize cttz and ctlz when we can prove something about the
leading/trailing bits. Patch by Alastair Lynn! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92706 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -3144,7 +3144,40 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
||||
II->getOperand(1));
|
||||
}
|
||||
break;
|
||||
|
||||
case Intrinsic::cttz: {
|
||||
// If all bits below the first known one are known zero,
|
||||
// this value is constant.
|
||||
const IntegerType *IT = cast<IntegerType>(II->getOperand(1)->getType());
|
||||
uint32_t BitWidth = IT->getBitWidth();
|
||||
APInt KnownZero(BitWidth, 0);
|
||||
APInt KnownOne(BitWidth, 0);
|
||||
ComputeMaskedBits(II->getOperand(1), APInt::getAllOnesValue(BitWidth),
|
||||
KnownZero, KnownOne);
|
||||
unsigned TrailingZeros = KnownOne.countTrailingZeros();
|
||||
APInt Mask(APInt::getLowBitsSet(BitWidth, TrailingZeros));
|
||||
if ((Mask & KnownZero) == Mask)
|
||||
return ReplaceInstUsesWith(CI, ConstantInt::get(IT,
|
||||
APInt(BitWidth, TrailingZeros)));
|
||||
|
||||
}
|
||||
break;
|
||||
case Intrinsic::ctlz: {
|
||||
// If all bits above the first known one are known zero,
|
||||
// this value is constant.
|
||||
const IntegerType *IT = cast<IntegerType>(II->getOperand(1)->getType());
|
||||
uint32_t BitWidth = IT->getBitWidth();
|
||||
APInt KnownZero(BitWidth, 0);
|
||||
APInt KnownOne(BitWidth, 0);
|
||||
ComputeMaskedBits(II->getOperand(1), APInt::getAllOnesValue(BitWidth),
|
||||
KnownZero, KnownOne);
|
||||
unsigned LeadingZeros = KnownOne.countLeadingZeros();
|
||||
APInt Mask(APInt::getHighBitsSet(BitWidth, LeadingZeros));
|
||||
if ((Mask & KnownZero) == Mask)
|
||||
return ReplaceInstUsesWith(CI, ConstantInt::get(IT,
|
||||
APInt(BitWidth, LeadingZeros)));
|
||||
|
||||
}
|
||||
break;
|
||||
case Intrinsic::uadd_with_overflow: {
|
||||
Value *LHS = II->getOperand(1), *RHS = II->getOperand(2);
|
||||
const IntegerType *IT = cast<IntegerType>(II->getOperand(1)->getType());
|
||||
|
||||
Reference in New Issue
Block a user