aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantRange.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-01-09 16:29:37 +0100
committerNikita Popov <npopov@redhat.com>2023-01-09 16:34:09 +0100
commitfd07583ca439494891662d5db58895f63e904cc5 (patch)
tree0aafc96e60c11420acf8b7dee36174d00213709c /llvm/lib/IR/ConstantRange.cpp
parent835cf3ca6bee4b866488e08db1a2fd158a3ad086 (diff)
downloadllvm-fd07583ca439494891662d5db58895f63e904cc5.zip
llvm-fd07583ca439494891662d5db58895f63e904cc5.tar.gz
llvm-fd07583ca439494891662d5db58895f63e904cc5.tar.bz2
[ConstantRange] Fix single bit abs range (PR59887)
For a full range input, we would produce an empty range instead of a full range. The change to the SMin.isNonNegative() branch is an optimality fix, because we should account for the potentially discarded SMin value in the IntMinIsPoison case. Change TestUnaryOpExhaustive to test both 4 and 1 bits, to both cover this specific case in unit tests, and make sure all other unary operations deal with 1-bit inputs correctly. Fixes https://github.com/llvm/llvm-project/issues/59887.
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 2f0d3d1..0dbccaa 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -1656,15 +1656,15 @@ ConstantRange ConstantRange::abs(bool IntMinIsPoison) const {
// All non-negative.
if (SMin.isNonNegative())
- return *this;
+ return ConstantRange(SMin, SMax + 1);
// All negative.
if (SMax.isNegative())
return ConstantRange(-SMax, -SMin + 1);
// Range crosses zero.
- return ConstantRange(APInt::getZero(getBitWidth()),
- APIntOps::umax(-SMin, SMax) + 1);
+ return ConstantRange::getNonEmpty(APInt::getZero(getBitWidth()),
+ APIntOps::umax(-SMin, SMax) + 1);
}
ConstantRange::OverflowResult ConstantRange::unsignedAddMayOverflow(