aboutsummaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2010-08-11 22:04:36 +0000
committerNick Lewycky <nicholas@mxc.ca>2010-08-11 22:04:36 +0000
commit7f9ef4bb514d5a28637789d8f397dadd4344dc1b (patch)
tree8b94b927b25fd741e8e666bb9bd2c45defe050da /unittests
parent4fd393cc26bb75e81ecf19e795b27509e16d0550 (diff)
downloadexternal_llvm-7f9ef4bb514d5a28637789d8f397dadd4344dc1b.zip
external_llvm-7f9ef4bb514d5a28637789d8f397dadd4344dc1b.tar.gz
external_llvm-7f9ef4bb514d5a28637789d8f397dadd4344dc1b.tar.bz2
Clean up ConstantRange a bit:
- remove ashr which never worked. - fix lshr and shl and add tests. - remove dead function "intersect1Wrapped". - add a new sub method to subtract ranges, with test. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@110861 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Support/ConstantRangeTest.cpp66
1 files changed, 63 insertions, 3 deletions
diff --git a/unittests/Support/ConstantRangeTest.cpp b/unittests/Support/ConstantRangeTest.cpp
index fc1f5b8..091ecd4 100644
--- a/unittests/Support/ConstantRangeTest.cpp
+++ b/unittests/Support/ConstantRangeTest.cpp
@@ -259,11 +259,31 @@ TEST_F(ConstantRangeTest, Add) {
EXPECT_EQ(Empty.add(Wrap), Empty);
EXPECT_EQ(Empty.add(APInt(16, 4)), Empty);
EXPECT_EQ(Some.add(APInt(16, 4)),
- ConstantRange(APInt(16, 0xe), APInt(16, 0xaae)));
+ ConstantRange(APInt(16, 0xe), APInt(16, 0xaae)));
EXPECT_EQ(Wrap.add(APInt(16, 4)),
- ConstantRange(APInt(16, 0xaae), APInt(16, 0xe)));
+ ConstantRange(APInt(16, 0xaae), APInt(16, 0xe)));
EXPECT_EQ(One.add(APInt(16, 4)),
- ConstantRange(APInt(16, 0xe)));
+ ConstantRange(APInt(16, 0xe)));
+}
+
+TEST_F(ConstantRangeTest, Sub) {
+ EXPECT_EQ(Full.sub(APInt(16, 4)), Full);
+ EXPECT_EQ(Full.sub(Full), Full);
+ EXPECT_EQ(Full.sub(Empty), Empty);
+ EXPECT_EQ(Full.sub(One), Full);
+ EXPECT_EQ(Full.sub(Some), Full);
+ EXPECT_EQ(Full.sub(Wrap), Full);
+ EXPECT_EQ(Empty.sub(Empty), Empty);
+ EXPECT_EQ(Empty.sub(One), Empty);
+ EXPECT_EQ(Empty.sub(Some), Empty);
+ EXPECT_EQ(Empty.sub(Wrap), Empty);
+ EXPECT_EQ(Empty.sub(APInt(16, 4)), Empty);
+ EXPECT_EQ(Some.sub(APInt(16, 4)),
+ ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
+ EXPECT_EQ(Wrap.sub(APInt(16, 4)),
+ ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
+ EXPECT_EQ(One.sub(APInt(16, 4)),
+ ConstantRange(APInt(16, 0x6)));
}
TEST_F(ConstantRangeTest, Multiply) {
@@ -351,4 +371,44 @@ TEST_F(ConstantRangeTest, UDiv) {
EXPECT_EQ(Wrap.udiv(Wrap), Full);
}
+TEST_F(ConstantRangeTest, Shl) {
+ EXPECT_EQ(Full.shl(Full), Full);
+ EXPECT_EQ(Full.shl(Empty), Empty);
+ EXPECT_EQ(Full.shl(One), Full); // TODO: [0, (-1 << 0xa) + 1)
+ EXPECT_EQ(Full.shl(Some), Full); // TODO: [0, (-1 << 0xa) + 1)
+ EXPECT_EQ(Full.shl(Wrap), Full);
+ EXPECT_EQ(Empty.shl(Empty), Empty);
+ EXPECT_EQ(Empty.shl(One), Empty);
+ EXPECT_EQ(Empty.shl(Some), Empty);
+ EXPECT_EQ(Empty.shl(Wrap), Empty);
+ EXPECT_EQ(One.shl(One), ConstantRange(APInt(16, 0xa << 0xa),
+ APInt(16, (0xa << 0xa) + 1)));
+ EXPECT_EQ(One.shl(Some), Full); // TODO: [0xa << 0xa, 0)
+ EXPECT_EQ(One.shl(Wrap), Full); // TODO: [0xa, 0xa << 14 + 1)
+ EXPECT_EQ(Some.shl(Some), Full); // TODO: [0xa << 0xa, 0xfc01)
+ EXPECT_EQ(Some.shl(Wrap), Full); // TODO: [0xa, 0x7ff << 0x5 + 1)
+ EXPECT_EQ(Wrap.shl(Wrap), Full);
+}
+
+TEST_F(ConstantRangeTest, Lshr) {
+ EXPECT_EQ(Full.lshr(Full), Full);
+ EXPECT_EQ(Full.lshr(Empty), Empty);
+ EXPECT_EQ(Full.lshr(One), ConstantRange(APInt(16, 0),
+ APInt(16, (0xffff >> 0xa) + 1)));
+ EXPECT_EQ(Full.lshr(Some), ConstantRange(APInt(16, 0),
+ APInt(16, (0xffff >> 0xa) + 1)));
+ EXPECT_EQ(Full.lshr(Wrap), Full);
+ EXPECT_EQ(Empty.lshr(Empty), Empty);
+ EXPECT_EQ(Empty.lshr(One), Empty);
+ EXPECT_EQ(Empty.lshr(Some), Empty);
+ EXPECT_EQ(Empty.lshr(Wrap), Empty);
+ EXPECT_EQ(One.lshr(One), ConstantRange(APInt(16, 0)));
+ EXPECT_EQ(One.lshr(Some), ConstantRange(APInt(16, 0)));
+ EXPECT_EQ(One.lshr(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
+ EXPECT_EQ(Some.lshr(Some), ConstantRange(APInt(16, 0),
+ APInt(16, (0xaaa >> 0xa) + 1)));
+ EXPECT_EQ(Some.lshr(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
+ EXPECT_EQ(Wrap.lshr(Wrap), Full);
+}
+
} // anonymous namespace