summaryrefslogtreecommitdiffstats
path: root/unittests/Support/ConstantRangeTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/Support/ConstantRangeTest.cpp')
-rw-r--r--unittests/Support/ConstantRangeTest.cpp54
1 files changed, 40 insertions, 14 deletions
diff --git a/unittests/Support/ConstantRangeTest.cpp b/unittests/Support/ConstantRangeTest.cpp
index 091ecd4a..161e2cf 100644
--- a/unittests/Support/ConstantRangeTest.cpp
+++ b/unittests/Support/ConstantRangeTest.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/ConstantRange.h"
+#include "llvm/Instructions.h"
#include "gtest/gtest.h"
@@ -146,6 +147,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);
@@ -154,8 +171,8 @@ TEST_F(ConstantRangeTest, Trunc) {
ConstantRange TWrap = Wrap.truncate(10);
EXPECT_TRUE(TFull.isFullSet());
EXPECT_TRUE(TEmpty.isEmptySet());
- EXPECT_EQ(TOne, ConstantRange(APInt(One.getLower()).trunc(10),
- APInt(One.getUpper()).trunc(10)));
+ EXPECT_EQ(TOne, ConstantRange(One.getLower().trunc(10),
+ One.getUpper().trunc(10)));
EXPECT_TRUE(TSome.isFullSet());
}
@@ -167,12 +184,11 @@ TEST_F(ConstantRangeTest, ZExt) {
ConstantRange ZWrap = Wrap.zeroExtend(20);
EXPECT_EQ(ZFull, ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
EXPECT_TRUE(ZEmpty.isEmptySet());
- EXPECT_EQ(ZOne, ConstantRange(APInt(One.getLower()).zext(20),
- 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(ZOne, ConstantRange(One.getLower().zext(20),
+ One.getUpper().zext(20)));
+ EXPECT_EQ(ZSome, ConstantRange(Some.getLower().zext(20),
+ Some.getUpper().zext(20)));
+ EXPECT_EQ(ZWrap, ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
}
TEST_F(ConstantRangeTest, SExt) {
@@ -184,12 +200,15 @@ TEST_F(ConstantRangeTest, SExt) {
EXPECT_EQ(SFull, ConstantRange(APInt(20, (uint64_t)INT16_MIN, true),
APInt(20, INT16_MAX + 1, true)));
EXPECT_TRUE(SEmpty.isEmptySet());
- EXPECT_EQ(SOne, ConstantRange(APInt(One.getLower()).sext(20),
- 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(SOne, ConstantRange(One.getLower().sext(20),
+ One.getUpper().sext(20)));
+ EXPECT_EQ(SSome, ConstantRange(Some.getLower().sext(20),
+ Some.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) {
@@ -411,4 +430,11 @@ TEST_F(ConstantRangeTest, Lshr) {
EXPECT_EQ(Wrap.lshr(Wrap), Full);
}
+TEST(ConstantRange, MakeICmpRegion) {
+ // PR8250
+ ConstantRange SMax = ConstantRange(APInt::getSignedMaxValue(32));
+ EXPECT_TRUE(ConstantRange::makeICmpRegion(ICmpInst::ICMP_SGT,
+ SMax).isEmptySet());
+}
+
} // anonymous namespace
OpenPOWER on IntegriCloud