Skip to content

Commit 83f72af

Browse files
nikicakiramenai
authored andcommitted
[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 llvm/llvm-project#80309.
1 parent dc3357d commit 83f72af

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
@@ -9518,7 +9518,7 @@ static ConstantRange getRangeForIntrinsic(const IntrinsicInst &II) {
95189518
case Intrinsic::cttz:
95199519
// Maximum of set/clear bits is the bit width.
95209520
return ConstantRange::getNonEmpty(APInt::getZero(Width),
9521-
APInt(Width, Width + 1));
9521+
APInt(Width, Width) + 1);
95229522
case Intrinsic::uadd_sat:
95239523
// uadd.sat(x, C) produces [C, UINT_MAX].
95249524
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
@@ -1836,7 +1836,7 @@ ConstantRange ConstantRange::ctlz(bool ZeroIsPoison) const {
18361836
// Zero is either safe or not in the range. The output range is composed by
18371837
// the result of countLeadingZero of the two extremes.
18381838
return getNonEmpty(APInt(getBitWidth(), getUnsignedMax().countl_zero()),
1839-
APInt(getBitWidth(), getUnsignedMin().countl_zero() + 1));
1839+
APInt(getBitWidth(), getUnsignedMin().countl_zero()) + 1);
18401840
}
18411841

18421842
static ConstantRange getUnsignedCountTrailingZerosRange(const APInt &Lower,
@@ -1895,7 +1895,7 @@ ConstantRange ConstantRange::cttz(bool ZeroIsPoison) const {
18951895
}
18961896

18971897
if (isFullSet())
1898-
return getNonEmpty(Zero, APInt(BitWidth, BitWidth + 1));
1898+
return getNonEmpty(Zero, APInt(BitWidth, BitWidth) + 1);
18991899
if (!isWrappedSet())
19001900
return getUnsignedCountTrailingZerosRange(Lower, Upper);
19011901
// The range is wrapped. We decompose it into two ranges, [0, Upper) and
@@ -1940,7 +1940,7 @@ ConstantRange ConstantRange::ctpop() const {
19401940
unsigned BitWidth = getBitWidth();
19411941
APInt Zero = APInt::getZero(BitWidth);
19421942
if (isFullSet())
1943-
return getNonEmpty(Zero, APInt(BitWidth, BitWidth + 1));
1943+
return getNonEmpty(Zero, APInt(BitWidth, BitWidth) + 1);
19441944
if (!isWrappedSet())
19451945
return getUnsignedPopCountRange(Lower, Upper);
19461946
// The range is wrapped. We decompose it into two ranges, [0, Upper) and

0 commit comments

Comments
 (0)