diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-03-27 19:12:09 +0000 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-03-27 19:12:09 +0000 |
commit | 7b4e9a1c7a24ea6b6892dc66ea6c62d3396df066 (patch) | |
tree | f4f2628cba96d93d046e941c2fe3d2abed239809 /llvm/unittests/IR/ConstantRangeTest.cpp | |
parent | b7e213808c12967dbf9286d9d566a88a23cd20c3 (diff) | |
download | bcm5719-llvm-7b4e9a1c7a24ea6b6892dc66ea6c62d3396df066.tar.gz bcm5719-llvm-7b4e9a1c7a24ea6b6892dc66ea6c62d3396df066.zip |
[ConstantRange] Add isWrappedSet() and isUpperSignWrapped()
Split off from D59749. This adds isWrappedSet() and
isUpperSignWrapped() set with the same behavior as isSignWrappedSet()
and isUpperWrapped() for the respectively other domain.
The methods isWrappedSet() and isSignWrappedSet() will not consider
ranges of the form [X, Max] == [X, 0) and [X, SignedMax] == [X, SignedMin)
to be wrapping, while isUpperWrapped() and isUpperSignWrapped() will.
Also replace the checks in getUnsignedMin() and friends with method
calls that implement the same logic.
llvm-svn: 357112
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r-- | llvm/unittests/IR/ConstantRangeTest.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp index 0455df5fa5e..2cde17f291c 100644 --- a/llvm/unittests/IR/ConstantRangeTest.cpp +++ b/llvm/unittests/IR/ConstantRangeTest.cpp @@ -35,7 +35,7 @@ TEST_F(ConstantRangeTest, Basics) { EXPECT_TRUE(Full.isFullSet()); EXPECT_FALSE(Full.isEmptySet()); EXPECT_TRUE(Full.inverse().isEmptySet()); - EXPECT_FALSE(Full.isUpperWrapped()); + EXPECT_FALSE(Full.isWrappedSet()); EXPECT_TRUE(Full.contains(APInt(16, 0x0))); EXPECT_TRUE(Full.contains(APInt(16, 0x9))); EXPECT_TRUE(Full.contains(APInt(16, 0xa))); @@ -45,7 +45,7 @@ TEST_F(ConstantRangeTest, Basics) { EXPECT_FALSE(Empty.isFullSet()); EXPECT_TRUE(Empty.isEmptySet()); EXPECT_TRUE(Empty.inverse().isFullSet()); - EXPECT_FALSE(Empty.isUpperWrapped()); + EXPECT_FALSE(Empty.isWrappedSet()); EXPECT_FALSE(Empty.contains(APInt(16, 0x0))); EXPECT_FALSE(Empty.contains(APInt(16, 0x9))); EXPECT_FALSE(Empty.contains(APInt(16, 0xa))); @@ -54,7 +54,7 @@ TEST_F(ConstantRangeTest, Basics) { EXPECT_FALSE(One.isFullSet()); EXPECT_FALSE(One.isEmptySet()); - EXPECT_FALSE(One.isUpperWrapped()); + EXPECT_FALSE(One.isWrappedSet()); EXPECT_FALSE(One.contains(APInt(16, 0x0))); EXPECT_FALSE(One.contains(APInt(16, 0x9))); EXPECT_TRUE(One.contains(APInt(16, 0xa))); @@ -64,7 +64,7 @@ TEST_F(ConstantRangeTest, Basics) { EXPECT_FALSE(Some.isFullSet()); EXPECT_FALSE(Some.isEmptySet()); - EXPECT_FALSE(Some.isUpperWrapped()); + EXPECT_FALSE(Some.isWrappedSet()); EXPECT_FALSE(Some.contains(APInt(16, 0x0))); EXPECT_FALSE(Some.contains(APInt(16, 0x9))); EXPECT_TRUE(Some.contains(APInt(16, 0xa))); @@ -73,7 +73,7 @@ TEST_F(ConstantRangeTest, Basics) { EXPECT_FALSE(Wrap.isFullSet()); EXPECT_FALSE(Wrap.isEmptySet()); - EXPECT_TRUE(Wrap.isUpperWrapped()); + EXPECT_TRUE(Wrap.isWrappedSet()); EXPECT_TRUE(Wrap.contains(APInt(16, 0x0))); EXPECT_TRUE(Wrap.contains(APInt(16, 0x9))); EXPECT_FALSE(Wrap.contains(APInt(16, 0xa))); @@ -176,6 +176,29 @@ TEST_F(ConstantRangeTest, SignWrapped) { EXPECT_FALSE(ConstantRange(APInt(8, 250), APInt(8, 251)).isSignWrappedSet()); } +TEST_F(ConstantRangeTest, UpperWrapped) { + // The behavior here is the same as for isWrappedSet() / isSignWrappedSet(). + EXPECT_FALSE(Full.isUpperWrapped()); + EXPECT_FALSE(Empty.isUpperWrapped()); + EXPECT_FALSE(One.isUpperWrapped()); + EXPECT_FALSE(Some.isUpperWrapped()); + EXPECT_TRUE(Wrap.isUpperWrapped()); + EXPECT_FALSE(Full.isUpperSignWrapped()); + EXPECT_FALSE(Empty.isUpperSignWrapped()); + EXPECT_FALSE(One.isUpperSignWrapped()); + EXPECT_FALSE(Some.isUpperSignWrapped()); + EXPECT_TRUE(Wrap.isUpperSignWrapped()); + + // The behavior differs if Upper is the Min/SignedMin value. + ConstantRange CR1(APInt(8, 42), APInt::getMinValue(8)); + EXPECT_FALSE(CR1.isWrappedSet()); + EXPECT_TRUE(CR1.isUpperWrapped()); + + ConstantRange CR2(APInt(8, 42), APInt::getSignedMinValue(8)); + EXPECT_FALSE(CR2.isSignWrappedSet()); + EXPECT_TRUE(CR2.isUpperSignWrapped()); +} + TEST_F(ConstantRangeTest, Trunc) { ConstantRange TFull = Full.truncate(10); ConstantRange TEmpty = Empty.truncate(10); |