1 //===- llvm/unittest/Support/ConstantRangeTest.cpp - ConstantRange tests --===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Support/ConstantRange.h"
11 #include "llvm/Instructions.h"
13 #include "gtest/gtest.h"
19 class ConstantRangeTest
: public ::testing::Test
{
21 static ConstantRange Full
;
22 static ConstantRange Empty
;
23 static ConstantRange One
;
24 static ConstantRange Some
;
25 static ConstantRange Wrap
;
28 ConstantRange
ConstantRangeTest::Full(16);
29 ConstantRange
ConstantRangeTest::Empty(16, false);
30 ConstantRange
ConstantRangeTest::One(APInt(16, 0xa));
31 ConstantRange
ConstantRangeTest::Some(APInt(16, 0xa), APInt(16, 0xaaa));
32 ConstantRange
ConstantRangeTest::Wrap(APInt(16, 0xaaa), APInt(16, 0xa));
34 TEST_F(ConstantRangeTest
, Basics
) {
35 EXPECT_TRUE(Full
.isFullSet());
36 EXPECT_FALSE(Full
.isEmptySet());
37 EXPECT_TRUE(Full
.inverse().isEmptySet());
38 EXPECT_FALSE(Full
.isWrappedSet());
39 EXPECT_TRUE(Full
.contains(APInt(16, 0x0)));
40 EXPECT_TRUE(Full
.contains(APInt(16, 0x9)));
41 EXPECT_TRUE(Full
.contains(APInt(16, 0xa)));
42 EXPECT_TRUE(Full
.contains(APInt(16, 0xaa9)));
43 EXPECT_TRUE(Full
.contains(APInt(16, 0xaaa)));
45 EXPECT_FALSE(Empty
.isFullSet());
46 EXPECT_TRUE(Empty
.isEmptySet());
47 EXPECT_TRUE(Empty
.inverse().isFullSet());
48 EXPECT_FALSE(Empty
.isWrappedSet());
49 EXPECT_FALSE(Empty
.contains(APInt(16, 0x0)));
50 EXPECT_FALSE(Empty
.contains(APInt(16, 0x9)));
51 EXPECT_FALSE(Empty
.contains(APInt(16, 0xa)));
52 EXPECT_FALSE(Empty
.contains(APInt(16, 0xaa9)));
53 EXPECT_FALSE(Empty
.contains(APInt(16, 0xaaa)));
55 EXPECT_FALSE(One
.isFullSet());
56 EXPECT_FALSE(One
.isEmptySet());
57 EXPECT_FALSE(One
.isWrappedSet());
58 EXPECT_FALSE(One
.contains(APInt(16, 0x0)));
59 EXPECT_FALSE(One
.contains(APInt(16, 0x9)));
60 EXPECT_TRUE(One
.contains(APInt(16, 0xa)));
61 EXPECT_FALSE(One
.contains(APInt(16, 0xaa9)));
62 EXPECT_FALSE(One
.contains(APInt(16, 0xaaa)));
63 EXPECT_FALSE(One
.inverse().contains(APInt(16, 0xa)));
65 EXPECT_FALSE(Some
.isFullSet());
66 EXPECT_FALSE(Some
.isEmptySet());
67 EXPECT_FALSE(Some
.isWrappedSet());
68 EXPECT_FALSE(Some
.contains(APInt(16, 0x0)));
69 EXPECT_FALSE(Some
.contains(APInt(16, 0x9)));
70 EXPECT_TRUE(Some
.contains(APInt(16, 0xa)));
71 EXPECT_TRUE(Some
.contains(APInt(16, 0xaa9)));
72 EXPECT_FALSE(Some
.contains(APInt(16, 0xaaa)));
74 EXPECT_FALSE(Wrap
.isFullSet());
75 EXPECT_FALSE(Wrap
.isEmptySet());
76 EXPECT_TRUE(Wrap
.isWrappedSet());
77 EXPECT_TRUE(Wrap
.contains(APInt(16, 0x0)));
78 EXPECT_TRUE(Wrap
.contains(APInt(16, 0x9)));
79 EXPECT_FALSE(Wrap
.contains(APInt(16, 0xa)));
80 EXPECT_FALSE(Wrap
.contains(APInt(16, 0xaa9)));
81 EXPECT_TRUE(Wrap
.contains(APInt(16, 0xaaa)));
84 TEST_F(ConstantRangeTest
, Equality
) {
85 EXPECT_EQ(Full
, Full
);
86 EXPECT_EQ(Empty
, Empty
);
88 EXPECT_EQ(Some
, Some
);
89 EXPECT_EQ(Wrap
, Wrap
);
90 EXPECT_NE(Full
, Empty
);
92 EXPECT_NE(Full
, Some
);
93 EXPECT_NE(Full
, Wrap
);
94 EXPECT_NE(Empty
, One
);
95 EXPECT_NE(Empty
, Some
);
96 EXPECT_NE(Empty
, Wrap
);
99 EXPECT_NE(Some
, Wrap
);
102 TEST_F(ConstantRangeTest
, SingleElement
) {
103 EXPECT_EQ(Full
.getSingleElement(), static_cast<APInt
*>(NULL
));
104 EXPECT_EQ(Empty
.getSingleElement(), static_cast<APInt
*>(NULL
));
105 EXPECT_EQ(*One
.getSingleElement(), APInt(16, 0xa));
106 EXPECT_EQ(Some
.getSingleElement(), static_cast<APInt
*>(NULL
));
107 EXPECT_EQ(Wrap
.getSingleElement(), static_cast<APInt
*>(NULL
));
109 EXPECT_FALSE(Full
.isSingleElement());
110 EXPECT_FALSE(Empty
.isSingleElement());
111 EXPECT_TRUE(One
.isSingleElement());
112 EXPECT_FALSE(Some
.isSingleElement());
113 EXPECT_FALSE(Wrap
.isSingleElement());
116 TEST_F(ConstantRangeTest
, GetSetSize
) {
117 EXPECT_EQ(Full
.getSetSize(), APInt(16, 0));
118 EXPECT_EQ(Empty
.getSetSize(), APInt(16, 0));
119 EXPECT_EQ(One
.getSetSize(), APInt(16, 1));
120 EXPECT_EQ(Some
.getSetSize(), APInt(16, 0xaa0));
121 EXPECT_EQ(Wrap
.getSetSize(), APInt(16, 0x10000 - 0xaa0));
124 TEST_F(ConstantRangeTest
, GetMinsAndMaxes
) {
125 EXPECT_EQ(Full
.getUnsignedMax(), APInt(16, UINT16_MAX
));
126 EXPECT_EQ(One
.getUnsignedMax(), APInt(16, 0xa));
127 EXPECT_EQ(Some
.getUnsignedMax(), APInt(16, 0xaa9));
128 EXPECT_EQ(Wrap
.getUnsignedMax(), APInt(16, UINT16_MAX
));
130 EXPECT_EQ(Full
.getUnsignedMin(), APInt(16, 0));
131 EXPECT_EQ(One
.getUnsignedMin(), APInt(16, 0xa));
132 EXPECT_EQ(Some
.getUnsignedMin(), APInt(16, 0xa));
133 EXPECT_EQ(Wrap
.getUnsignedMin(), APInt(16, 0));
135 EXPECT_EQ(Full
.getSignedMax(), APInt(16, INT16_MAX
));
136 EXPECT_EQ(One
.getSignedMax(), APInt(16, 0xa));
137 EXPECT_EQ(Some
.getSignedMax(), APInt(16, 0xaa9));
138 EXPECT_EQ(Wrap
.getSignedMax(), APInt(16, INT16_MAX
));
140 EXPECT_EQ(Full
.getSignedMin(), APInt(16, (uint64_t)INT16_MIN
));
141 EXPECT_EQ(One
.getSignedMin(), APInt(16, 0xa));
142 EXPECT_EQ(Some
.getSignedMin(), APInt(16, 0xa));
143 EXPECT_EQ(Wrap
.getSignedMin(), APInt(16, (uint64_t)INT16_MIN
));
146 EXPECT_EQ(ConstantRange(APInt(4, 7), APInt(4, 0)).getSignedMax(),
150 TEST_F(ConstantRangeTest
, SignWrapped
) {
151 EXPECT_TRUE(Full
.isSignWrappedSet());
152 EXPECT_FALSE(Empty
.isSignWrappedSet());
153 EXPECT_FALSE(One
.isSignWrappedSet());
154 EXPECT_FALSE(Some
.isSignWrappedSet());
155 EXPECT_TRUE(Wrap
.isSignWrappedSet());
157 EXPECT_FALSE(ConstantRange(APInt(8, 127), APInt(8, 128)).isSignWrappedSet());
158 EXPECT_TRUE(ConstantRange(APInt(8, 127), APInt(8, 129)).isSignWrappedSet());
159 EXPECT_FALSE(ConstantRange(APInt(8, 128), APInt(8, 129)).isSignWrappedSet());
160 EXPECT_TRUE(ConstantRange(APInt(8, 10), APInt(8, 9)).isSignWrappedSet());
161 EXPECT_TRUE(ConstantRange(APInt(8, 10), APInt(8, 250)).isSignWrappedSet());
162 EXPECT_FALSE(ConstantRange(APInt(8, 250), APInt(8, 10)).isSignWrappedSet());
163 EXPECT_FALSE(ConstantRange(APInt(8, 250), APInt(8, 251)).isSignWrappedSet());
166 TEST_F(ConstantRangeTest
, Trunc
) {
167 ConstantRange TFull
= Full
.truncate(10);
168 ConstantRange TEmpty
= Empty
.truncate(10);
169 ConstantRange TOne
= One
.truncate(10);
170 ConstantRange TSome
= Some
.truncate(10);
171 ConstantRange TWrap
= Wrap
.truncate(10);
172 EXPECT_TRUE(TFull
.isFullSet());
173 EXPECT_TRUE(TEmpty
.isEmptySet());
174 EXPECT_EQ(TOne
, ConstantRange(One
.getLower().trunc(10),
175 One
.getUpper().trunc(10)));
176 EXPECT_TRUE(TSome
.isFullSet());
179 TEST_F(ConstantRangeTest
, ZExt
) {
180 ConstantRange ZFull
= Full
.zeroExtend(20);
181 ConstantRange ZEmpty
= Empty
.zeroExtend(20);
182 ConstantRange ZOne
= One
.zeroExtend(20);
183 ConstantRange ZSome
= Some
.zeroExtend(20);
184 ConstantRange ZWrap
= Wrap
.zeroExtend(20);
185 EXPECT_EQ(ZFull
, ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
186 EXPECT_TRUE(ZEmpty
.isEmptySet());
187 EXPECT_EQ(ZOne
, ConstantRange(One
.getLower().zext(20),
188 One
.getUpper().zext(20)));
189 EXPECT_EQ(ZSome
, ConstantRange(Some
.getLower().zext(20),
190 Some
.getUpper().zext(20)));
191 EXPECT_EQ(ZWrap
, ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
194 TEST_F(ConstantRangeTest
, SExt
) {
195 ConstantRange SFull
= Full
.signExtend(20);
196 ConstantRange SEmpty
= Empty
.signExtend(20);
197 ConstantRange SOne
= One
.signExtend(20);
198 ConstantRange SSome
= Some
.signExtend(20);
199 ConstantRange SWrap
= Wrap
.signExtend(20);
200 EXPECT_EQ(SFull
, ConstantRange(APInt(20, (uint64_t)INT16_MIN
, true),
201 APInt(20, INT16_MAX
+ 1, true)));
202 EXPECT_TRUE(SEmpty
.isEmptySet());
203 EXPECT_EQ(SOne
, ConstantRange(One
.getLower().sext(20),
204 One
.getUpper().sext(20)));
205 EXPECT_EQ(SSome
, ConstantRange(Some
.getLower().sext(20),
206 Some
.getUpper().sext(20)));
207 EXPECT_EQ(SWrap
, ConstantRange(APInt(20, (uint64_t)INT16_MIN
, true),
208 APInt(20, INT16_MAX
+ 1, true)));
210 EXPECT_EQ(ConstantRange(APInt(8, 120), APInt(8, 140)).signExtend(16),
211 ConstantRange(APInt(16, -128), APInt(16, 128)));
214 TEST_F(ConstantRangeTest
, IntersectWith
) {
215 EXPECT_EQ(Empty
.intersectWith(Full
), Empty
);
216 EXPECT_EQ(Empty
.intersectWith(Empty
), Empty
);
217 EXPECT_EQ(Empty
.intersectWith(One
), Empty
);
218 EXPECT_EQ(Empty
.intersectWith(Some
), Empty
);
219 EXPECT_EQ(Empty
.intersectWith(Wrap
), Empty
);
220 EXPECT_EQ(Full
.intersectWith(Full
), Full
);
221 EXPECT_EQ(Some
.intersectWith(Some
), Some
);
222 EXPECT_EQ(Some
.intersectWith(One
), One
);
223 EXPECT_EQ(Full
.intersectWith(One
), One
);
224 EXPECT_EQ(Full
.intersectWith(Some
), Some
);
225 EXPECT_EQ(Some
.intersectWith(Wrap
), Empty
);
226 EXPECT_EQ(One
.intersectWith(Wrap
), Empty
);
227 EXPECT_EQ(One
.intersectWith(Wrap
), Wrap
.intersectWith(One
));
229 // Klee generated testcase from PR4545.
230 // The intersection of i16 [4, 2) and [6, 5) is disjoint, looking like
231 // 01..4.6789ABCDEF where the dots represent values not in the intersection.
232 ConstantRange
LHS(APInt(16, 4), APInt(16, 2));
233 ConstantRange
RHS(APInt(16, 6), APInt(16, 5));
234 EXPECT_TRUE(LHS
.intersectWith(RHS
) == LHS
);
237 TEST_F(ConstantRangeTest
, UnionWith
) {
238 EXPECT_EQ(Wrap
.unionWith(One
),
239 ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
240 EXPECT_EQ(One
.unionWith(Wrap
), Wrap
.unionWith(One
));
241 EXPECT_EQ(Empty
.unionWith(Empty
), Empty
);
242 EXPECT_EQ(Full
.unionWith(Full
), Full
);
243 EXPECT_EQ(Some
.unionWith(Wrap
), Full
);
246 EXPECT_EQ(ConstantRange(APInt(16, 14), APInt(16, 1)).unionWith(
247 ConstantRange(APInt(16, 0), APInt(16, 8))),
248 ConstantRange(APInt(16, 14), APInt(16, 8)));
249 EXPECT_EQ(ConstantRange(APInt(16, 6), APInt(16, 4)).unionWith(
250 ConstantRange(APInt(16, 4), APInt(16, 0))),
252 EXPECT_EQ(ConstantRange(APInt(16, 1), APInt(16, 0)).unionWith(
253 ConstantRange(APInt(16, 2), APInt(16, 1))),
257 TEST_F(ConstantRangeTest
, SubtractAPInt
) {
258 EXPECT_EQ(Full
.subtract(APInt(16, 4)), Full
);
259 EXPECT_EQ(Empty
.subtract(APInt(16, 4)), Empty
);
260 EXPECT_EQ(Some
.subtract(APInt(16, 4)),
261 ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
262 EXPECT_EQ(Wrap
.subtract(APInt(16, 4)),
263 ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
264 EXPECT_EQ(One
.subtract(APInt(16, 4)),
265 ConstantRange(APInt(16, 0x6)));
268 TEST_F(ConstantRangeTest
, Add
) {
269 EXPECT_EQ(Full
.add(APInt(16, 4)), Full
);
270 EXPECT_EQ(Full
.add(Full
), Full
);
271 EXPECT_EQ(Full
.add(Empty
), Empty
);
272 EXPECT_EQ(Full
.add(One
), Full
);
273 EXPECT_EQ(Full
.add(Some
), Full
);
274 EXPECT_EQ(Full
.add(Wrap
), Full
);
275 EXPECT_EQ(Empty
.add(Empty
), Empty
);
276 EXPECT_EQ(Empty
.add(One
), Empty
);
277 EXPECT_EQ(Empty
.add(Some
), Empty
);
278 EXPECT_EQ(Empty
.add(Wrap
), Empty
);
279 EXPECT_EQ(Empty
.add(APInt(16, 4)), Empty
);
280 EXPECT_EQ(Some
.add(APInt(16, 4)),
281 ConstantRange(APInt(16, 0xe), APInt(16, 0xaae)));
282 EXPECT_EQ(Wrap
.add(APInt(16, 4)),
283 ConstantRange(APInt(16, 0xaae), APInt(16, 0xe)));
284 EXPECT_EQ(One
.add(APInt(16, 4)),
285 ConstantRange(APInt(16, 0xe)));
288 TEST_F(ConstantRangeTest
, Sub
) {
289 EXPECT_EQ(Full
.sub(APInt(16, 4)), Full
);
290 EXPECT_EQ(Full
.sub(Full
), Full
);
291 EXPECT_EQ(Full
.sub(Empty
), Empty
);
292 EXPECT_EQ(Full
.sub(One
), Full
);
293 EXPECT_EQ(Full
.sub(Some
), Full
);
294 EXPECT_EQ(Full
.sub(Wrap
), Full
);
295 EXPECT_EQ(Empty
.sub(Empty
), Empty
);
296 EXPECT_EQ(Empty
.sub(One
), Empty
);
297 EXPECT_EQ(Empty
.sub(Some
), Empty
);
298 EXPECT_EQ(Empty
.sub(Wrap
), Empty
);
299 EXPECT_EQ(Empty
.sub(APInt(16, 4)), Empty
);
300 EXPECT_EQ(Some
.sub(APInt(16, 4)),
301 ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
302 EXPECT_EQ(Wrap
.sub(APInt(16, 4)),
303 ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
304 EXPECT_EQ(One
.sub(APInt(16, 4)),
305 ConstantRange(APInt(16, 0x6)));
308 TEST_F(ConstantRangeTest
, Multiply
) {
309 EXPECT_EQ(Full
.multiply(Full
), Full
);
310 EXPECT_EQ(Full
.multiply(Empty
), Empty
);
311 EXPECT_EQ(Full
.multiply(One
), Full
);
312 EXPECT_EQ(Full
.multiply(Some
), Full
);
313 EXPECT_EQ(Full
.multiply(Wrap
), Full
);
314 EXPECT_EQ(Empty
.multiply(Empty
), Empty
);
315 EXPECT_EQ(Empty
.multiply(One
), Empty
);
316 EXPECT_EQ(Empty
.multiply(Some
), Empty
);
317 EXPECT_EQ(Empty
.multiply(Wrap
), Empty
);
318 EXPECT_EQ(One
.multiply(One
), ConstantRange(APInt(16, 0xa*0xa),
319 APInt(16, 0xa*0xa + 1)));
320 EXPECT_EQ(One
.multiply(Some
), ConstantRange(APInt(16, 0xa*0xa),
321 APInt(16, 0xa*0xaa9 + 1)));
322 EXPECT_EQ(One
.multiply(Wrap
), Full
);
323 EXPECT_EQ(Some
.multiply(Some
), Full
);
324 EXPECT_EQ(Some
.multiply(Wrap
), Full
);
325 EXPECT_EQ(Wrap
.multiply(Wrap
), Full
);
327 // http://llvm.org/PR4545
328 EXPECT_EQ(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
329 ConstantRange(APInt(4, 6), APInt(4, 2))),
330 ConstantRange(4, /*isFullSet=*/true));
333 TEST_F(ConstantRangeTest
, UMax
) {
334 EXPECT_EQ(Full
.umax(Full
), Full
);
335 EXPECT_EQ(Full
.umax(Empty
), Empty
);
336 EXPECT_EQ(Full
.umax(Some
), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
337 EXPECT_EQ(Full
.umax(Wrap
), Full
);
338 EXPECT_EQ(Full
.umax(Some
), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
339 EXPECT_EQ(Empty
.umax(Empty
), Empty
);
340 EXPECT_EQ(Empty
.umax(Some
), Empty
);
341 EXPECT_EQ(Empty
.umax(Wrap
), Empty
);
342 EXPECT_EQ(Empty
.umax(One
), Empty
);
343 EXPECT_EQ(Some
.umax(Some
), Some
);
344 EXPECT_EQ(Some
.umax(Wrap
), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
345 EXPECT_EQ(Some
.umax(One
), Some
);
346 // TODO: ConstantRange is currently over-conservative here.
347 EXPECT_EQ(Wrap
.umax(Wrap
), Full
);
348 EXPECT_EQ(Wrap
.umax(One
), ConstantRange(APInt(16, 0xa), APInt(16, 0)));
349 EXPECT_EQ(One
.umax(One
), One
);
352 TEST_F(ConstantRangeTest
, SMax
) {
353 EXPECT_EQ(Full
.smax(Full
), Full
);
354 EXPECT_EQ(Full
.smax(Empty
), Empty
);
355 EXPECT_EQ(Full
.smax(Some
), ConstantRange(APInt(16, 0xa),
356 APInt::getSignedMinValue(16)));
357 EXPECT_EQ(Full
.smax(Wrap
), Full
);
358 EXPECT_EQ(Full
.smax(One
), ConstantRange(APInt(16, 0xa),
359 APInt::getSignedMinValue(16)));
360 EXPECT_EQ(Empty
.smax(Empty
), Empty
);
361 EXPECT_EQ(Empty
.smax(Some
), Empty
);
362 EXPECT_EQ(Empty
.smax(Wrap
), Empty
);
363 EXPECT_EQ(Empty
.smax(One
), Empty
);
364 EXPECT_EQ(Some
.smax(Some
), Some
);
365 EXPECT_EQ(Some
.smax(Wrap
), ConstantRange(APInt(16, 0xa),
366 APInt(16, (uint64_t)INT16_MIN
)));
367 EXPECT_EQ(Some
.smax(One
), Some
);
368 EXPECT_EQ(Wrap
.smax(One
), ConstantRange(APInt(16, 0xa),
369 APInt(16, (uint64_t)INT16_MIN
)));
370 EXPECT_EQ(One
.smax(One
), One
);
373 TEST_F(ConstantRangeTest
, UDiv
) {
374 EXPECT_EQ(Full
.udiv(Full
), Full
);
375 EXPECT_EQ(Full
.udiv(Empty
), Empty
);
376 EXPECT_EQ(Full
.udiv(One
), ConstantRange(APInt(16, 0),
377 APInt(16, 0xffff / 0xa + 1)));
378 EXPECT_EQ(Full
.udiv(Some
), ConstantRange(APInt(16, 0),
379 APInt(16, 0xffff / 0xa + 1)));
380 EXPECT_EQ(Full
.udiv(Wrap
), Full
);
381 EXPECT_EQ(Empty
.udiv(Empty
), Empty
);
382 EXPECT_EQ(Empty
.udiv(One
), Empty
);
383 EXPECT_EQ(Empty
.udiv(Some
), Empty
);
384 EXPECT_EQ(Empty
.udiv(Wrap
), Empty
);
385 EXPECT_EQ(One
.udiv(One
), ConstantRange(APInt(16, 1)));
386 EXPECT_EQ(One
.udiv(Some
), ConstantRange(APInt(16, 0), APInt(16, 2)));
387 EXPECT_EQ(One
.udiv(Wrap
), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
388 EXPECT_EQ(Some
.udiv(Some
), ConstantRange(APInt(16, 0), APInt(16, 0x111)));
389 EXPECT_EQ(Some
.udiv(Wrap
), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
390 EXPECT_EQ(Wrap
.udiv(Wrap
), Full
);
393 TEST_F(ConstantRangeTest
, Shl
) {
394 EXPECT_EQ(Full
.shl(Full
), Full
);
395 EXPECT_EQ(Full
.shl(Empty
), Empty
);
396 EXPECT_EQ(Full
.shl(One
), Full
); // TODO: [0, (-1 << 0xa) + 1)
397 EXPECT_EQ(Full
.shl(Some
), Full
); // TODO: [0, (-1 << 0xa) + 1)
398 EXPECT_EQ(Full
.shl(Wrap
), Full
);
399 EXPECT_EQ(Empty
.shl(Empty
), Empty
);
400 EXPECT_EQ(Empty
.shl(One
), Empty
);
401 EXPECT_EQ(Empty
.shl(Some
), Empty
);
402 EXPECT_EQ(Empty
.shl(Wrap
), Empty
);
403 EXPECT_EQ(One
.shl(One
), ConstantRange(APInt(16, 0xa << 0xa),
404 APInt(16, (0xa << 0xa) + 1)));
405 EXPECT_EQ(One
.shl(Some
), Full
); // TODO: [0xa << 0xa, 0)
406 EXPECT_EQ(One
.shl(Wrap
), Full
); // TODO: [0xa, 0xa << 14 + 1)
407 EXPECT_EQ(Some
.shl(Some
), Full
); // TODO: [0xa << 0xa, 0xfc01)
408 EXPECT_EQ(Some
.shl(Wrap
), Full
); // TODO: [0xa, 0x7ff << 0x5 + 1)
409 EXPECT_EQ(Wrap
.shl(Wrap
), Full
);
412 TEST_F(ConstantRangeTest
, Lshr
) {
413 EXPECT_EQ(Full
.lshr(Full
), Full
);
414 EXPECT_EQ(Full
.lshr(Empty
), Empty
);
415 EXPECT_EQ(Full
.lshr(One
), ConstantRange(APInt(16, 0),
416 APInt(16, (0xffff >> 0xa) + 1)));
417 EXPECT_EQ(Full
.lshr(Some
), ConstantRange(APInt(16, 0),
418 APInt(16, (0xffff >> 0xa) + 1)));
419 EXPECT_EQ(Full
.lshr(Wrap
), Full
);
420 EXPECT_EQ(Empty
.lshr(Empty
), Empty
);
421 EXPECT_EQ(Empty
.lshr(One
), Empty
);
422 EXPECT_EQ(Empty
.lshr(Some
), Empty
);
423 EXPECT_EQ(Empty
.lshr(Wrap
), Empty
);
424 EXPECT_EQ(One
.lshr(One
), ConstantRange(APInt(16, 0)));
425 EXPECT_EQ(One
.lshr(Some
), ConstantRange(APInt(16, 0)));
426 EXPECT_EQ(One
.lshr(Wrap
), ConstantRange(APInt(16, 0), APInt(16, 0xb)));
427 EXPECT_EQ(Some
.lshr(Some
), ConstantRange(APInt(16, 0),
428 APInt(16, (0xaaa >> 0xa) + 1)));
429 EXPECT_EQ(Some
.lshr(Wrap
), ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
430 EXPECT_EQ(Wrap
.lshr(Wrap
), Full
);
433 TEST(ConstantRange
, MakeICmpRegion
) {
435 ConstantRange SMax
= ConstantRange(APInt::getSignedMaxValue(32));
436 EXPECT_TRUE(ConstantRange::makeICmpRegion(ICmpInst::ICMP_SGT
,
440 } // anonymous namespace