aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/ConstantRangeTest.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2022-05-16 16:04:11 +0200
committerNikita Popov <npopov@redhat.com>2022-05-16 16:12:25 +0200
commit8ab819ad90d647b96bb4b6842a742d2552ba9e9c (patch)
treeb62a5e3a62c7d63f801d09af8ffa46ab19905c1d /llvm/unittests/IR/ConstantRangeTest.cpp
parentc70259405c61b203682e2a03c4688c6d6bc89856 (diff)
downloadllvm-8ab819ad90d647b96bb4b6842a742d2552ba9e9c.zip
llvm-8ab819ad90d647b96bb4b6842a742d2552ba9e9c.tar.gz
llvm-8ab819ad90d647b96bb4b6842a742d2552ba9e9c.tar.bz2
[ConstantRange] Add toKnownBits() method
Add toKnownBits() method to mirror fromKnownBits(). We know the top bits that are constant between min and max. The return value for an empty range is chosen to be conservative.
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r--llvm/unittests/IR/ConstantRangeTest.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index 2c54b1c6..9aee84e 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -2366,6 +2366,25 @@ TEST_F(ConstantRangeTest, FromKnownBitsExhaustive) {
}
}
+TEST_F(ConstantRangeTest, ToKnownBits) {
+ unsigned Bits = 4;
+ EnumerateConstantRanges(Bits, [&](const ConstantRange &CR) {
+ KnownBits Known = CR.toKnownBits();
+ KnownBits ExpectedKnown(Bits);
+ ExpectedKnown.Zero.setAllBits();
+ ExpectedKnown.One.setAllBits();
+ ForeachNumInConstantRange(CR, [&](const APInt &N) {
+ ExpectedKnown.One &= N;
+ ExpectedKnown.Zero &= ~N;
+ });
+ // For an empty CR any result would be legal.
+ if (!CR.isEmptySet()) {
+ EXPECT_EQ(ExpectedKnown.One, Known.One);
+ EXPECT_EQ(ExpectedKnown.Zero, Known.Zero);
+ }
+ });
+}
+
TEST_F(ConstantRangeTest, Negative) {
// All elements in an empty set (of which there are none) are both negative
// and non-negative. Empty & full sets checked explicitly for clarity, but