aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/ConstantRangeTest.cpp
diff options
context:
space:
mode:
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