llvm.org GIT mirror llvm / 44b3e8d
Break the world's largest unit test down a few logical lines. No semantic changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75369 91177308-0d34-0410-b5e6-96231b3b80d8 Nick Lewycky 10 years ago
1 changed file(s) with 85 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
1414
1515 namespace {
1616
17 TEST(ConstantRangeTest, Unsigned) {
18 ConstantRange Full(16);
19 ConstantRange Empty(16, false);
20 ConstantRange One(APInt(16, 0xa));
21 ConstantRange Some(APInt(16, 0xa), APInt(16, 0xaaa));
22 ConstantRange Wrap(APInt(16, 0xaaa), APInt(16, 0xa));
23
17 class ConstantRangeTest : public ::testing::Test {
18 protected:
19 static ConstantRange Full;
20 static ConstantRange Empty;
21 static ConstantRange One;
22 static ConstantRange Some;
23 static ConstantRange Wrap;
24 };
25
26 ConstantRange ConstantRangeTest::Full(16);
27 ConstantRange ConstantRangeTest::Empty(16, false);
28 ConstantRange ConstantRangeTest::One(APInt(16, 0xa));
29 ConstantRange ConstantRangeTest::Some(APInt(16, 0xa), APInt(16, 0xaaa));
30 ConstantRange ConstantRangeTest::Wrap(APInt(16, 0xaaa), APInt(16, 0xa));
31
32 TEST_F(ConstantRangeTest, Basics) {
2433 EXPECT_TRUE(Full.isFullSet());
2534 EXPECT_FALSE(Full.isEmptySet());
2635 EXPECT_FALSE(Full.isWrappedSet());
6574 EXPECT_FALSE(Wrap.contains(APInt(16, 0xa)));
6675 EXPECT_FALSE(Wrap.contains(APInt(16, 0xaa9)));
6776 EXPECT_TRUE(Wrap.contains(APInt(16, 0xaaa)));
68
77 }
78
79 TEST_F(ConstantRangeTest, Equality) {
6980 EXPECT_EQ(Full, Full);
7081 EXPECT_EQ(Empty, Empty);
7182 EXPECT_EQ(One, One);
8192 EXPECT_NE(One, Some);
8293 EXPECT_NE(One, Wrap);
8394 EXPECT_NE(Some, Wrap);
84
95 }
96
97 TEST_F(ConstantRangeTest, SingleElement) {
8598 EXPECT_EQ(Full.getSingleElement(), static_cast(NULL));
8699 EXPECT_EQ(Empty.getSingleElement(), static_cast(NULL));
87100 EXPECT_EQ(*One.getSingleElement(), APInt(16, 0xa));
93106 EXPECT_TRUE(One.isSingleElement());
94107 EXPECT_FALSE(Some.isSingleElement());
95108 EXPECT_FALSE(Wrap.isSingleElement());
96
109 }
110
111 TEST_F(ConstantRangeTest, GetSetSize) {
97112 EXPECT_EQ(Full.getSetSize(), APInt(16, 0));
98113 EXPECT_EQ(Empty.getSetSize(), APInt(16, 0));
99114 EXPECT_EQ(One.getSetSize(), APInt(16, 1));
100115 EXPECT_EQ(Some.getSetSize(), APInt(16, 0xaa0));
101116 EXPECT_EQ(Wrap.getSetSize(), APInt(16, 0x10000 - 0xaa0));
102
117 }
118
119 TEST_F(ConstantRangeTest, GetMinsAndMaxes) {
103120 EXPECT_EQ(Full.getUnsignedMax(), APInt(16, UINT16_MAX));
104121 EXPECT_EQ(One.getUnsignedMax(), APInt(16, 0xa));
105122 EXPECT_EQ(Some.getUnsignedMax(), APInt(16, 0xaa9));
119136 EXPECT_EQ(One.getSignedMin(), APInt(16, 0xa));
120137 EXPECT_EQ(Some.getSignedMin(), APInt(16, 0xa));
121138 EXPECT_EQ(Wrap.getSignedMin(), APInt(16, INT16_MIN));
122
139 }
140
141 TEST_F(ConstantRangeTest, Trunc) {
123142 ConstantRange TFull = Full.truncate(10);
124143 ConstantRange TEmpty = Empty.truncate(10);
125144 ConstantRange TOne = One.truncate(10);
131150 APInt(One.getUpper()).trunc(10)));
132151 // TODO: ConstantRange is currently over-conservative here.
133152 EXPECT_TRUE(TSome.isFullSet());
134
153 }
154
155 TEST_F(ConstantRangeTest, ZExt) {
135156 ConstantRange ZFull = Full.zeroExtend(20);
136157 ConstantRange ZEmpty = Empty.zeroExtend(20);
137158 ConstantRange ZOne = One.zeroExtend(20);
145166 APInt(Some.getUpper()).zext(20)));
146167 EXPECT_EQ(ZWrap, ConstantRange(APInt(Wrap.getLower()).zext(20),
147168 APInt(Wrap.getUpper()).zext(20)));
148
169 }
170
171 TEST_F(ConstantRangeTest, SExt) {
149172 ConstantRange SFull = Full.signExtend(20);
150173 ConstantRange SEmpty = Empty.signExtend(20);
151174 ConstantRange SOne = One.signExtend(20);
161184 EXPECT_EQ(SWrap, ConstantRange(APInt(Wrap.getLower()).sext(20),
162185 APInt(Wrap.getUpper()).sext(20)));
163186
187 }
188
189 TEST_F(ConstantRangeTest, IntersectWith) {
164190 EXPECT_TRUE(Empty.intersectWith(Full).isEmptySet());
165191 EXPECT_TRUE(Empty.intersectWith(Empty).isEmptySet());
166192 EXPECT_TRUE(Empty.intersectWith(One).isEmptySet());
174200 EXPECT_TRUE(Some.intersectWith(Wrap).isEmptySet());
175201 EXPECT_TRUE(One.intersectWith(Wrap).isEmptySet());
176202 EXPECT_EQ(One.intersectWith(Wrap), Wrap.intersectWith(One));
177
203 }
204
205 TEST_F(ConstantRangeTest, MaximalIntersectWith) {
178206 EXPECT_TRUE(Empty.maximalIntersectWith(Full).isEmptySet());
179207 EXPECT_TRUE(Empty.maximalIntersectWith(Empty).isEmptySet());
180208 EXPECT_TRUE(Empty.maximalIntersectWith(One).isEmptySet());
188216 EXPECT_TRUE(Some.maximalIntersectWith(Wrap).isEmptySet());
189217 EXPECT_TRUE(One.maximalIntersectWith(Wrap).isEmptySet());
190218 EXPECT_EQ(One.maximalIntersectWith(Wrap), Wrap.maximalIntersectWith(One));
191
219 }
220
221 TEST_F(ConstantRangeTest, UnionWith) {
192222 EXPECT_EQ(Wrap.unionWith(One),
193223 ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
194224 EXPECT_EQ(One.unionWith(Wrap), Wrap.unionWith(One));
195225 EXPECT_TRUE(Empty.unionWith(Empty).isEmptySet());
196226 EXPECT_TRUE(Full.unionWith(Full).isFullSet());
197227 EXPECT_TRUE(Some.unionWith(Wrap).isFullSet());
198
228 }
229
230 TEST_F(ConstantRangeTest, SubtractAPInt) {
199231 EXPECT_TRUE(Full.subtract(APInt(16, 4)).isFullSet());
200232 EXPECT_TRUE(Empty.subtract(APInt(16, 4)).isEmptySet());
201233 EXPECT_EQ(Some.subtract(APInt(16, 4)),
204236 ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
205237 EXPECT_EQ(One.subtract(APInt(16, 4)),
206238 ConstantRange(APInt(16, 0x6)));
207
239 }
240
241 TEST_F(ConstantRangeTest, Add) {
208242 EXPECT_TRUE(Full.add(APInt(16, 4)).isFullSet());
209243 EXPECT_EQ(Full.add(Empty), Empty);
210244 EXPECT_EQ(Full.add(One), Full);
221255 ConstantRange(APInt(16, 0xaae), APInt(16, 0xe)));
222256 EXPECT_EQ(One.add(APInt(16, 4)),
223257 ConstantRange(APInt(16, 0xe)));
224
258 }
259
260 TEST_F(ConstantRangeTest, Multiply) {
261 EXPECT_EQ(Full.multiply(Full), Full);
262 EXPECT_EQ(Full.multiply(Empty), Empty);
263 EXPECT_EQ(Full.multiply(One), Full);
264 EXPECT_EQ(Full.multiply(Some), Full);
265 EXPECT_EQ(Full.multiply(Wrap), Full);
266 EXPECT_EQ(Empty.multiply(Empty), Empty);
267 EXPECT_EQ(Empty.multiply(One), Empty);
268 EXPECT_EQ(Empty.multiply(Some), Empty);
269 EXPECT_EQ(Empty.multiply(Wrap), Empty);
270 // TODO: ConstantRange is currently over-conservative here.
271 EXPECT_EQ(One.multiply(One), Full);
272 // TODO: ConstantRange is currently over-conservative here.
273 EXPECT_EQ(One.multiply(Some), Full);
274 // TODO: ConstantRange is currently over-conservative here.
275 EXPECT_EQ(One.multiply(Wrap), Full);
276 // TODO: ConstantRange is currently over-conservative here.
277 EXPECT_EQ(Some.multiply(Some), Full);
278 // TODO: ConstantRange is currently over-conservative here.
279 EXPECT_EQ(Some.multiply(Wrap), Full);
280 // TODO: ConstantRange is currently over-conservative here.
281 EXPECT_EQ(Wrap.multiply(Wrap), Full);
282 }
283
284 TEST_F(ConstantRangeTest, UMax) {
225285 EXPECT_TRUE(Full.umax(Full).isFullSet());
226286 EXPECT_TRUE(Full.umax(Empty).isEmptySet());
227287 EXPECT_TRUE(Full.umax(Some).isFullSet());
238298 EXPECT_EQ(Wrap.umax(Wrap), Full);
239299 EXPECT_EQ(Wrap.umax(One), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
240300 EXPECT_EQ(One.umax(One), One);
241
242 EXPECT_EQ(Full.multiply(Full), Full);
243 EXPECT_EQ(Full.multiply(Empty), Empty);
244 EXPECT_EQ(Full.multiply(One), Full);
245 EXPECT_EQ(Full.multiply(Some), Full);
246 EXPECT_EQ(Full.multiply(Wrap), Full);
247 EXPECT_EQ(Empty.multiply(Empty), Empty);
248 EXPECT_EQ(Empty.multiply(One), Empty);
249 EXPECT_EQ(Empty.multiply(Some), Empty);
250 EXPECT_EQ(Empty.multiply(Wrap), Empty);
251 // TODO: ConstantRange is currently over-conservative here.
252 EXPECT_EQ(One.multiply(One), Full);
253 // TODO: ConstantRange is currently over-conservative here.
254 EXPECT_EQ(One.multiply(Some), Full);
255 // TODO: ConstantRange is currently over-conservative here.
256 EXPECT_EQ(One.multiply(Wrap), Full);
257 // TODO: ConstantRange is currently over-conservative here.
258 EXPECT_EQ(Some.multiply(Some), Full);
259 // TODO: ConstantRange is currently over-conservative here.
260 EXPECT_EQ(Some.multiply(Wrap), Full);
261 // TODO: ConstantRange is currently over-conservative here.
262 EXPECT_EQ(Wrap.multiply(Wrap), Full);
263
301 }
302
303 TEST_F(ConstantRangeTest, SMax) {
264304 EXPECT_TRUE(Full.smax(Full).isFullSet());
265305 EXPECT_TRUE(Full.smax(Empty).isEmptySet());
266306 EXPECT_TRUE(Full.smax(Some).isFullSet());
277317 EXPECT_EQ(Wrap.smax(One), ConstantRange(APInt(16, 0xa),
278318 APInt(16, INT16_MIN)));
279319 EXPECT_EQ(One.smax(One), One);
280
320 }
321
322 TEST_F(ConstantRangeTest, UDiv) {
281323 EXPECT_EQ(Full.udiv(Full), Full);
282324 EXPECT_EQ(Full.udiv(Empty), Empty);
283325 EXPECT_EQ(Full.udiv(One), Full);