[llvm] 9707b98 - [ConstantRange] Perform increment on APInt (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 07:11:09 PDT 2024
Author: Nikita Popov
Date: 2024-09-05T16:11:00+02:00
New Revision: 9707b98e572adf34ef3e71bcf159dae08e654fd8
URL: https://github.com/llvm/llvm-project/commit/9707b98e572adf34ef3e71bcf159dae08e654fd8
DIFF: https://github.com/llvm/llvm-project/commit/9707b98e572adf34ef3e71bcf159dae08e654fd8.diff
LOG: [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 https://github.com/llvm/llvm-project/pull/80309.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/IR/ConstantRange.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 8f35fd5eb52681..3a0ec99ee5ea1e 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -9596,7 +9596,7 @@ static ConstantRange getRangeForIntrinsic(const IntrinsicInst &II) {
case Intrinsic::cttz:
// Maximum of set/clear bits is the bit width.
return ConstantRange::getNonEmpty(APInt::getZero(Width),
- APInt(Width, Width + 1));
+ APInt(Width, Width) + 1);
case Intrinsic::uadd_sat:
// uadd.sat(x, C) produces [C, UINT_MAX].
if (match(II.getOperand(0), m_APInt(C)) ||
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index c389d7214defca..61a051821a5dbf 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -1952,7 +1952,7 @@ ConstantRange ConstantRange::ctlz(bool ZeroIsPoison) const {
// Zero is either safe or not in the range. The output range is composed by
// the result of countLeadingZero of the two extremes.
return getNonEmpty(APInt(getBitWidth(), getUnsignedMax().countl_zero()),
- APInt(getBitWidth(), getUnsignedMin().countl_zero() + 1));
+ APInt(getBitWidth(), getUnsignedMin().countl_zero()) + 1);
}
static ConstantRange getUnsignedCountTrailingZerosRange(const APInt &Lower,
@@ -2011,7 +2011,7 @@ ConstantRange ConstantRange::cttz(bool ZeroIsPoison) const {
}
if (isFullSet())
- return getNonEmpty(Zero, APInt(BitWidth, BitWidth + 1));
+ return getNonEmpty(Zero, APInt(BitWidth, BitWidth) + 1);
if (!isWrappedSet())
return getUnsignedCountTrailingZerosRange(Lower, Upper);
// The range is wrapped. We decompose it into two ranges, [0, Upper) and
@@ -2056,7 +2056,7 @@ ConstantRange ConstantRange::ctpop() const {
unsigned BitWidth = getBitWidth();
APInt Zero = APInt::getZero(BitWidth);
if (isFullSet())
- return getNonEmpty(Zero, APInt(BitWidth, BitWidth + 1));
+ return getNonEmpty(Zero, APInt(BitWidth, BitWidth) + 1);
if (!isWrappedSet())
return getUnsignedPopCountRange(Lower, Upper);
// The range is wrapped. We decompose it into two ranges, [0, Upper) and
More information about the llvm-commits
mailing list