diff options
| author | Nick Lewycky <nicholas@mxc.ca> | 2010-09-06 23:52:49 +0000 |
|---|---|---|
| committer | Nick Lewycky <nicholas@mxc.ca> | 2010-09-06 23:52:49 +0000 |
| commit | a35462da3dcf340d4c48899586c43f34d838465a (patch) | |
| tree | 1ad34f123066729522c4faef3e6525696a6d7ab6 /llvm/unittests/Support/ConstantRangeTest.cpp | |
| parent | 7ece716da2061bd01dcaf29e8e384f1c0722bf8a (diff) | |
| download | llvm-a35462da3dcf340d4c48899586c43f34d838465a.zip llvm-a35462da3dcf340d4c48899586c43f34d838465a.tar.gz llvm-a35462da3dcf340d4c48899586c43f34d838465a.tar.bz2 | |
Add a new isSignWrappedSet() method to ConstantRange.
Fix zeroExtend and signExtend to support empty sets, and to return the smallest
possible result set which contains the extension of each element in their
inputs. For example zext i8 [100, 10) to i16 is now [0, 256), not i16 [100, 10)
which contains 63446 members.
llvm-svn: 113187
Diffstat (limited to 'llvm/unittests/Support/ConstantRangeTest.cpp')
| -rw-r--r-- | llvm/unittests/Support/ConstantRangeTest.cpp | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/llvm/unittests/Support/ConstantRangeTest.cpp b/llvm/unittests/Support/ConstantRangeTest.cpp index 091ecd4..1cedeae 100644 --- a/llvm/unittests/Support/ConstantRangeTest.cpp +++ b/llvm/unittests/Support/ConstantRangeTest.cpp @@ -146,6 +146,22 @@ TEST_F(ConstantRangeTest, GetMinsAndMaxes) { APInt(4, 7)); } +TEST_F(ConstantRangeTest, SignWrapped) { + EXPECT_TRUE(Full.isSignWrappedSet()); + EXPECT_FALSE(Empty.isSignWrappedSet()); + EXPECT_FALSE(One.isSignWrappedSet()); + EXPECT_FALSE(Some.isSignWrappedSet()); + EXPECT_TRUE(Wrap.isSignWrappedSet()); + + EXPECT_FALSE(ConstantRange(APInt(8, 127), APInt(8, 128)).isSignWrappedSet()); + EXPECT_TRUE(ConstantRange(APInt(8, 127), APInt(8, 129)).isSignWrappedSet()); + EXPECT_FALSE(ConstantRange(APInt(8, 128), APInt(8, 129)).isSignWrappedSet()); + EXPECT_TRUE(ConstantRange(APInt(8, 10), APInt(8, 9)).isSignWrappedSet()); + EXPECT_TRUE(ConstantRange(APInt(8, 10), APInt(8, 250)).isSignWrappedSet()); + EXPECT_FALSE(ConstantRange(APInt(8, 250), APInt(8, 10)).isSignWrappedSet()); + EXPECT_FALSE(ConstantRange(APInt(8, 250), APInt(8, 251)).isSignWrappedSet()); +} + TEST_F(ConstantRangeTest, Trunc) { ConstantRange TFull = Full.truncate(10); ConstantRange TEmpty = Empty.truncate(10); @@ -171,8 +187,7 @@ TEST_F(ConstantRangeTest, ZExt) { APInt(One.getUpper()).zext(20))); EXPECT_EQ(ZSome, ConstantRange(APInt(Some.getLower()).zext(20), APInt(Some.getUpper()).zext(20))); - EXPECT_EQ(ZWrap, ConstantRange(APInt(Wrap.getLower()).zext(20), - APInt(Wrap.getUpper()).zext(20))); + EXPECT_EQ(ZWrap, ConstantRange(APInt(20, 0), APInt(20, 0x10000))); } TEST_F(ConstantRangeTest, SExt) { @@ -188,8 +203,11 @@ TEST_F(ConstantRangeTest, SExt) { APInt(One.getUpper()).sext(20))); EXPECT_EQ(SSome, ConstantRange(APInt(Some.getLower()).sext(20), APInt(Some.getUpper()).sext(20))); - EXPECT_EQ(SWrap, ConstantRange(APInt(Wrap.getLower()).sext(20), - APInt(Wrap.getUpper()).sext(20))); + EXPECT_EQ(SWrap, ConstantRange(APInt(20, (uint64_t)INT16_MIN, true), + APInt(20, INT16_MAX + 1, true))); + + EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, 140)).signExtend(16), + ConstantRange(APInt(16, -128), APInt(16, 128))); } TEST_F(ConstantRangeTest, IntersectWith) { |
