@@ -9897,13 +9897,20 @@ static void setLimitsForBinOp(const BinaryOperator &BO, APInt &Lower,
9897
9897
}
9898
9898
}
9899
9899
9900
- static ConstantRange getRangeForIntrinsic (const IntrinsicInst &II) {
9900
+ static ConstantRange getRangeForIntrinsic (const IntrinsicInst &II,
9901
+ bool UseInstrInfo) {
9901
9902
unsigned Width = II.getType ()->getScalarSizeInBits ();
9902
9903
const APInt *C;
9903
9904
switch (II.getIntrinsicID ()) {
9904
- case Intrinsic::ctpop:
9905
9905
case Intrinsic::ctlz:
9906
- case Intrinsic::cttz:
9906
+ case Intrinsic::cttz: {
9907
+ APInt Upper (Width, Width);
9908
+ if (!UseInstrInfo || !match (II.getArgOperand (1 ), m_One ()))
9909
+ Upper += 1 ;
9910
+ // Maximum of set/clear bits is the bit width.
9911
+ return ConstantRange::getNonEmpty (APInt::getZero (Width), Upper);
9912
+ }
9913
+ case Intrinsic::ctpop:
9907
9914
// Maximum of set/clear bits is the bit width.
9908
9915
return ConstantRange::getNonEmpty (APInt::getZero (Width),
9909
9916
APInt (Width, Width) + 1 );
@@ -10094,7 +10101,7 @@ ConstantRange llvm::computeConstantRange(const Value *V, bool ForSigned,
10094
10101
setLimitsForBinOp (*BO, Lower, Upper, IIQ, ForSigned);
10095
10102
CR = ConstantRange::getNonEmpty (Lower, Upper);
10096
10103
} else if (auto *II = dyn_cast<IntrinsicInst>(V))
10097
- CR = getRangeForIntrinsic (*II);
10104
+ CR = getRangeForIntrinsic (*II, UseInstrInfo );
10098
10105
else if (auto *SI = dyn_cast<SelectInst>(V)) {
10099
10106
ConstantRange CRTrue = computeConstantRange (
10100
10107
SI->getTrueValue (), ForSigned, UseInstrInfo, AC, CtxI, DT, Depth + 1 );
0 commit comments