forked from OSchip/llvm-project
[InstCombine] Use APInt bit counting methods to avoid a temporary APInt. NFC
llvm-svn: 301516
This commit is contained in:
parent
42fca6e794
commit
9474e9b6c8
|
@ -1384,17 +1384,17 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombiner &IC) {
|
||||||
|
|
||||||
// Create a mask for bits above (ctlz) or below (cttz) the first known one.
|
// Create a mask for bits above (ctlz) or below (cttz) the first known one.
|
||||||
bool IsTZ = II.getIntrinsicID() == Intrinsic::cttz;
|
bool IsTZ = II.getIntrinsicID() == Intrinsic::cttz;
|
||||||
unsigned NumMaskBits = IsTZ ? Known.One.countTrailingZeros()
|
unsigned PossibleZeros = IsTZ ? Known.One.countTrailingZeros()
|
||||||
: Known.One.countLeadingZeros();
|
: Known.One.countLeadingZeros();
|
||||||
APInt Mask = IsTZ ? APInt::getLowBitsSet(BitWidth, NumMaskBits)
|
unsigned DefiniteZeros = IsTZ ? Known.Zero.countTrailingOnes()
|
||||||
: APInt::getHighBitsSet(BitWidth, NumMaskBits);
|
: Known.Zero.countLeadingOnes();
|
||||||
|
|
||||||
// If all bits above (ctlz) or below (cttz) the first known one are known
|
// If all bits above (ctlz) or below (cttz) the first known one are known
|
||||||
// zero, this value is constant.
|
// zero, this value is constant.
|
||||||
// FIXME: This should be in InstSimplify because we're replacing an
|
// FIXME: This should be in InstSimplify because we're replacing an
|
||||||
// instruction with a constant.
|
// instruction with a constant.
|
||||||
if (Mask.isSubsetOf(Known.Zero)) {
|
if (PossibleZeros == DefiniteZeros) {
|
||||||
auto *C = ConstantInt::get(IT, APInt(BitWidth, NumMaskBits));
|
auto *C = ConstantInt::get(IT, DefiniteZeros);
|
||||||
return IC.replaceInstUsesWith(II, C);
|
return IC.replaceInstUsesWith(II, C);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue