@@ -9897,13 +9897,20 @@ static void setLimitsForBinOp(const BinaryOperator &BO, APInt &Lower,
98979897 }
98989898}
98999899
9900- static ConstantRange getRangeForIntrinsic (const IntrinsicInst &II) {
9900+ static ConstantRange getRangeForIntrinsic (const IntrinsicInst &II,
9901+ bool UseInstrInfo) {
99019902 unsigned Width = II.getType ()->getScalarSizeInBits ();
99029903 const APInt *C;
99039904 switch (II.getIntrinsicID ()) {
9904- case Intrinsic::ctpop:
99059905 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:
99079914 // Maximum of set/clear bits is the bit width.
99089915 return ConstantRange::getNonEmpty (APInt::getZero (Width),
99099916 APInt (Width, Width) + 1 );
@@ -10094,7 +10101,7 @@ ConstantRange llvm::computeConstantRange(const Value *V, bool ForSigned,
1009410101 setLimitsForBinOp (*BO, Lower, Upper, IIQ, ForSigned);
1009510102 CR = ConstantRange::getNonEmpty (Lower, Upper);
1009610103 } else if (auto *II = dyn_cast<IntrinsicInst>(V))
10097- CR = getRangeForIntrinsic (*II);
10104+ CR = getRangeForIntrinsic (*II, UseInstrInfo );
1009810105 else if (auto *SI = dyn_cast<SelectInst>(V)) {
1009910106 ConstantRange CRTrue = computeConstantRange (
1010010107 SI->getTrueValue (), ForSigned, UseInstrInfo, AC, CtxI, DT, Depth + 1 );
0 commit comments