Skip to content

Commit 9707b98

Browse files
committed
[ConstantRange] Perform increment on APInt (NFC)
This handles the edge case where BitWidth is 1 and doing the increment gets a value that's not valid in that width, while we just want wrap-around. Split out of #80309.
1 parent 233ed51 commit 9707b98

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9596,7 +9596,7 @@ static ConstantRange getRangeForIntrinsic(const IntrinsicInst &II) {
95969596
case Intrinsic::cttz:
95979597
// Maximum of set/clear bits is the bit width.
95989598
return ConstantRange::getNonEmpty(APInt::getZero(Width),
9599-
APInt(Width, Width + 1));
9599+
APInt(Width, Width) + 1);
96009600
case Intrinsic::uadd_sat:
96019601
// uadd.sat(x, C) produces [C, UINT_MAX].
96029602
if (match(II.getOperand(0), m_APInt(C)) ||

llvm/lib/IR/ConstantRange.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ ConstantRange ConstantRange::ctlz(bool ZeroIsPoison) const {
19521952
// Zero is either safe or not in the range. The output range is composed by
19531953
// the result of countLeadingZero of the two extremes.
19541954
return getNonEmpty(APInt(getBitWidth(), getUnsignedMax().countl_zero()),
1955-
APInt(getBitWidth(), getUnsignedMin().countl_zero() + 1));
1955+
APInt(getBitWidth(), getUnsignedMin().countl_zero()) + 1);
19561956
}
19571957

19581958
static ConstantRange getUnsignedCountTrailingZerosRange(const APInt &Lower,
@@ -2011,7 +2011,7 @@ ConstantRange ConstantRange::cttz(bool ZeroIsPoison) const {
20112011
}
20122012

20132013
if (isFullSet())
2014-
return getNonEmpty(Zero, APInt(BitWidth, BitWidth + 1));
2014+
return getNonEmpty(Zero, APInt(BitWidth, BitWidth) + 1);
20152015
if (!isWrappedSet())
20162016
return getUnsignedCountTrailingZerosRange(Lower, Upper);
20172017
// The range is wrapped. We decompose it into two ranges, [0, Upper) and
@@ -2056,7 +2056,7 @@ ConstantRange ConstantRange::ctpop() const {
20562056
unsigned BitWidth = getBitWidth();
20572057
APInt Zero = APInt::getZero(BitWidth);
20582058
if (isFullSet())
2059-
return getNonEmpty(Zero, APInt(BitWidth, BitWidth + 1));
2059+
return getNonEmpty(Zero, APInt(BitWidth, BitWidth) + 1);
20602060
if (!isWrappedSet())
20612061
return getUnsignedPopCountRange(Lower, Upper);
20622062
// The range is wrapped. We decompose it into two ranges, [0, Upper) and

0 commit comments

Comments
 (0)