aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantRange.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-09-05 16:02:50 +0200
committerNikita Popov <npopov@redhat.com>2024-09-05 16:11:00 +0200
commit9707b98e572adf34ef3e71bcf159dae08e654fd8 (patch)
tree56af2b71762e23c1ae52d2bb8a8a4f7a39de37c1 /llvm/lib/IR/ConstantRange.cpp
parent233ed51cf53d590d3f52d5becff95317dbf73657 (diff)
downloadllvm-9707b98e572adf34ef3e71bcf159dae08e654fd8.zip
llvm-9707b98e572adf34ef3e71bcf159dae08e654fd8.tar.gz
llvm-9707b98e572adf34ef3e71bcf159dae08e654fd8.tar.bz2
[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.
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r--llvm/lib/IR/ConstantRange.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index c389d72..61a0518 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