blob: f377b6f068af51d580247037941139ba2081e180 [file] [log] [blame]
Dan Gohmana3755d82009-07-09 22:07:27 +00001//===- llvm/unittest/Support/ConstantRangeTest.cpp - ConstantRange tests --===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/Support/ConstantRange.h"
Chris Lattner8142ce52009-08-23 06:32:25 +000011#include "llvm/Support/raw_ostream.h"
Dan Gohmana3755d82009-07-09 22:07:27 +000012
13#include "gtest/gtest.h"
14
15using namespace llvm;
16
17namespace {
18
Nick Lewycky44b3e8d2009-07-11 18:43:20 +000019class ConstantRangeTest : public ::testing::Test {
20protected:
21 static ConstantRange Full;
22 static ConstantRange Empty;
23 static ConstantRange One;
24 static ConstantRange Some;
25 static ConstantRange Wrap;
26};
Dan Gohmana3755d82009-07-09 22:07:27 +000027
Nick Lewycky44b3e8d2009-07-11 18:43:20 +000028ConstantRange ConstantRangeTest::Full(16);
29ConstantRange ConstantRangeTest::Empty(16, false);
30ConstantRange ConstantRangeTest::One(APInt(16, 0xa));
31ConstantRange ConstantRangeTest::Some(APInt(16, 0xa), APInt(16, 0xaaa));
32ConstantRange ConstantRangeTest::Wrap(APInt(16, 0xaaa), APInt(16, 0xa));
33
34TEST_F(ConstantRangeTest, Basics) {
Dan Gohmana3755d82009-07-09 22:07:27 +000035 EXPECT_TRUE(Full.isFullSet());
36 EXPECT_FALSE(Full.isEmptySet());
37 EXPECT_FALSE(Full.isWrappedSet());
38 EXPECT_TRUE(Full.contains(APInt(16, 0x0)));
39 EXPECT_TRUE(Full.contains(APInt(16, 0x9)));
40 EXPECT_TRUE(Full.contains(APInt(16, 0xa)));
41 EXPECT_TRUE(Full.contains(APInt(16, 0xaa9)));
42 EXPECT_TRUE(Full.contains(APInt(16, 0xaaa)));
43
44 EXPECT_FALSE(Empty.isFullSet());
45 EXPECT_TRUE(Empty.isEmptySet());
46 EXPECT_FALSE(Empty.isWrappedSet());
47 EXPECT_FALSE(Empty.contains(APInt(16, 0x0)));
48 EXPECT_FALSE(Empty.contains(APInt(16, 0x9)));
49 EXPECT_FALSE(Empty.contains(APInt(16, 0xa)));
50 EXPECT_FALSE(Empty.contains(APInt(16, 0xaa9)));
51 EXPECT_FALSE(Empty.contains(APInt(16, 0xaaa)));
52
53 EXPECT_FALSE(One.isFullSet());
54 EXPECT_FALSE(One.isEmptySet());
55 EXPECT_FALSE(One.isWrappedSet());
56 EXPECT_FALSE(One.contains(APInt(16, 0x0)));
57 EXPECT_FALSE(One.contains(APInt(16, 0x9)));
58 EXPECT_TRUE(One.contains(APInt(16, 0xa)));
59 EXPECT_FALSE(One.contains(APInt(16, 0xaa9)));
60 EXPECT_FALSE(One.contains(APInt(16, 0xaaa)));
61
62 EXPECT_FALSE(Some.isFullSet());
63 EXPECT_FALSE(Some.isEmptySet());
64 EXPECT_FALSE(Some.isWrappedSet());
65 EXPECT_FALSE(Some.contains(APInt(16, 0x0)));
66 EXPECT_FALSE(Some.contains(APInt(16, 0x9)));
67 EXPECT_TRUE(Some.contains(APInt(16, 0xa)));
68 EXPECT_TRUE(Some.contains(APInt(16, 0xaa9)));
69 EXPECT_FALSE(Some.contains(APInt(16, 0xaaa)));
70
71 EXPECT_FALSE(Wrap.isFullSet());
72 EXPECT_FALSE(Wrap.isEmptySet());
73 EXPECT_TRUE(Wrap.isWrappedSet());
74 EXPECT_TRUE(Wrap.contains(APInt(16, 0x0)));
75 EXPECT_TRUE(Wrap.contains(APInt(16, 0x9)));
76 EXPECT_FALSE(Wrap.contains(APInt(16, 0xa)));
77 EXPECT_FALSE(Wrap.contains(APInt(16, 0xaa9)));
78 EXPECT_TRUE(Wrap.contains(APInt(16, 0xaaa)));
Nick Lewycky44b3e8d2009-07-11 18:43:20 +000079}
Dan Gohmana3755d82009-07-09 22:07:27 +000080
Nick Lewycky44b3e8d2009-07-11 18:43:20 +000081TEST_F(ConstantRangeTest, Equality) {
Chris Lattner8142ce52009-08-23 06:32:25 +000082 EXPECT_TRUE(Full == Full);
83 EXPECT_TRUE(Empty == Empty);
84 EXPECT_TRUE(One == One);
85 EXPECT_TRUE(Some == Some);
86 EXPECT_TRUE(Wrap == Wrap);
87 EXPECT_TRUE(Full != Empty);
88 EXPECT_TRUE(Full != One);
89 EXPECT_TRUE(Full != Some);
90 EXPECT_TRUE(Full != Wrap);
91 EXPECT_TRUE(Empty != One);
92 EXPECT_TRUE(Empty != Some);
93 EXPECT_TRUE(Empty != Wrap);
94 EXPECT_TRUE(One != Some);
95 EXPECT_TRUE(One != Wrap);
96 EXPECT_TRUE(Some != Wrap);
Nick Lewycky44b3e8d2009-07-11 18:43:20 +000097}
Dan Gohmana3755d82009-07-09 22:07:27 +000098
Nick Lewycky44b3e8d2009-07-11 18:43:20 +000099TEST_F(ConstantRangeTest, SingleElement) {
Dan Gohmana3755d82009-07-09 22:07:27 +0000100 EXPECT_EQ(Full.getSingleElement(), static_cast<APInt *>(NULL));
101 EXPECT_EQ(Empty.getSingleElement(), static_cast<APInt *>(NULL));
102 EXPECT_EQ(*One.getSingleElement(), APInt(16, 0xa));
103 EXPECT_EQ(Some.getSingleElement(), static_cast<APInt *>(NULL));
104 EXPECT_EQ(Wrap.getSingleElement(), static_cast<APInt *>(NULL));
105
106 EXPECT_FALSE(Full.isSingleElement());
107 EXPECT_FALSE(Empty.isSingleElement());
108 EXPECT_TRUE(One.isSingleElement());
109 EXPECT_FALSE(Some.isSingleElement());
110 EXPECT_FALSE(Wrap.isSingleElement());
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000111}
Dan Gohmana3755d82009-07-09 22:07:27 +0000112
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000113TEST_F(ConstantRangeTest, GetSetSize) {
Dan Gohmana3755d82009-07-09 22:07:27 +0000114 EXPECT_EQ(Full.getSetSize(), APInt(16, 0));
115 EXPECT_EQ(Empty.getSetSize(), APInt(16, 0));
116 EXPECT_EQ(One.getSetSize(), APInt(16, 1));
117 EXPECT_EQ(Some.getSetSize(), APInt(16, 0xaa0));
118 EXPECT_EQ(Wrap.getSetSize(), APInt(16, 0x10000 - 0xaa0));
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000119}
Dan Gohmana3755d82009-07-09 22:07:27 +0000120
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000121TEST_F(ConstantRangeTest, GetMinsAndMaxes) {
Dan Gohmana3755d82009-07-09 22:07:27 +0000122 EXPECT_EQ(Full.getUnsignedMax(), APInt(16, UINT16_MAX));
123 EXPECT_EQ(One.getUnsignedMax(), APInt(16, 0xa));
124 EXPECT_EQ(Some.getUnsignedMax(), APInt(16, 0xaa9));
125 EXPECT_EQ(Wrap.getUnsignedMax(), APInt(16, UINT16_MAX));
126
127 EXPECT_EQ(Full.getUnsignedMin(), APInt(16, 0));
128 EXPECT_EQ(One.getUnsignedMin(), APInt(16, 0xa));
129 EXPECT_EQ(Some.getUnsignedMin(), APInt(16, 0xa));
130 EXPECT_EQ(Wrap.getUnsignedMin(), APInt(16, 0));
131
132 EXPECT_EQ(Full.getSignedMax(), APInt(16, INT16_MAX));
133 EXPECT_EQ(One.getSignedMax(), APInt(16, 0xa));
134 EXPECT_EQ(Some.getSignedMax(), APInt(16, 0xaa9));
135 EXPECT_EQ(Wrap.getSignedMax(), APInt(16, INT16_MAX));
136
Ryan Flynnb714c082009-07-22 16:17:36 +0000137 EXPECT_EQ(Full.getSignedMin(), APInt(16, (uint64_t)INT16_MIN));
Dan Gohmana3755d82009-07-09 22:07:27 +0000138 EXPECT_EQ(One.getSignedMin(), APInt(16, 0xa));
139 EXPECT_EQ(Some.getSignedMin(), APInt(16, 0xa));
Ryan Flynnb714c082009-07-22 16:17:36 +0000140 EXPECT_EQ(Wrap.getSignedMin(), APInt(16, (uint64_t)INT16_MIN));
Nick Lewycky780905e2009-07-13 04:50:21 +0000141
142 // Found by Klee
143 EXPECT_EQ(ConstantRange(APInt(4, 7), APInt(4, 0)).getSignedMax(),
144 APInt(4, 7));
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000145}
Dan Gohmana3755d82009-07-09 22:07:27 +0000146
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000147TEST_F(ConstantRangeTest, Trunc) {
Dan Gohmana3755d82009-07-09 22:07:27 +0000148 ConstantRange TFull = Full.truncate(10);
149 ConstantRange TEmpty = Empty.truncate(10);
150 ConstantRange TOne = One.truncate(10);
151 ConstantRange TSome = Some.truncate(10);
152 ConstantRange TWrap = Wrap.truncate(10);
153 EXPECT_TRUE(TFull.isFullSet());
154 EXPECT_TRUE(TEmpty.isEmptySet());
Chris Lattner8142ce52009-08-23 06:32:25 +0000155 EXPECT_TRUE(TOne == ConstantRange(APInt(One.getLower()).trunc(10),
Dan Gohmana3755d82009-07-09 22:07:27 +0000156 APInt(One.getUpper()).trunc(10)));
Dan Gohmana3755d82009-07-09 22:07:27 +0000157 EXPECT_TRUE(TSome.isFullSet());
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000158}
Dan Gohmana3755d82009-07-09 22:07:27 +0000159
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000160TEST_F(ConstantRangeTest, ZExt) {
Dan Gohmana3755d82009-07-09 22:07:27 +0000161 ConstantRange ZFull = Full.zeroExtend(20);
162 ConstantRange ZEmpty = Empty.zeroExtend(20);
163 ConstantRange ZOne = One.zeroExtend(20);
164 ConstantRange ZSome = Some.zeroExtend(20);
165 ConstantRange ZWrap = Wrap.zeroExtend(20);
Chris Lattner8142ce52009-08-23 06:32:25 +0000166 EXPECT_TRUE(ZFull == ConstantRange(APInt(20, 0), APInt(20, 0x10000)));
Dan Gohmana3755d82009-07-09 22:07:27 +0000167 EXPECT_TRUE(ZEmpty.isEmptySet());
Chris Lattner8142ce52009-08-23 06:32:25 +0000168 EXPECT_TRUE(ZOne == ConstantRange(APInt(One.getLower()).zext(20),
169 APInt(One.getUpper()).zext(20)));
170 EXPECT_TRUE(ZSome == ConstantRange(APInt(Some.getLower()).zext(20),
171 APInt(Some.getUpper()).zext(20)));
172 EXPECT_TRUE(ZWrap == ConstantRange(APInt(Wrap.getLower()).zext(20),
173 APInt(Wrap.getUpper()).zext(20)));
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000174}
Dan Gohmana3755d82009-07-09 22:07:27 +0000175
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000176TEST_F(ConstantRangeTest, SExt) {
Dan Gohmana3755d82009-07-09 22:07:27 +0000177 ConstantRange SFull = Full.signExtend(20);
178 ConstantRange SEmpty = Empty.signExtend(20);
179 ConstantRange SOne = One.signExtend(20);
180 ConstantRange SSome = Some.signExtend(20);
181 ConstantRange SWrap = Wrap.signExtend(20);
Chris Lattner8142ce52009-08-23 06:32:25 +0000182 EXPECT_TRUE(SFull == ConstantRange(APInt(20, (uint64_t)INT16_MIN, true),
183 APInt(20, INT16_MAX + 1, true)));
Dan Gohmana3755d82009-07-09 22:07:27 +0000184 EXPECT_TRUE(SEmpty.isEmptySet());
Chris Lattner8142ce52009-08-23 06:32:25 +0000185 EXPECT_TRUE(SOne == ConstantRange(APInt(One.getLower()).sext(20),
186 APInt(One.getUpper()).sext(20)));
187 EXPECT_TRUE(SSome == ConstantRange(APInt(Some.getLower()).sext(20),
188 APInt(Some.getUpper()).sext(20)));
189 EXPECT_TRUE(SWrap == ConstantRange(APInt(Wrap.getLower()).sext(20),
190 APInt(Wrap.getUpper()).sext(20)));
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000191}
192
193TEST_F(ConstantRangeTest, IntersectWith) {
Dan Gohmana3755d82009-07-09 22:07:27 +0000194 EXPECT_TRUE(Empty.intersectWith(Full).isEmptySet());
195 EXPECT_TRUE(Empty.intersectWith(Empty).isEmptySet());
196 EXPECT_TRUE(Empty.intersectWith(One).isEmptySet());
197 EXPECT_TRUE(Empty.intersectWith(Some).isEmptySet());
198 EXPECT_TRUE(Empty.intersectWith(Wrap).isEmptySet());
199 EXPECT_TRUE(Full.intersectWith(Full).isFullSet());
200 EXPECT_TRUE(Some.intersectWith(Some) == Some);
201 EXPECT_TRUE(Some.intersectWith(One) == One);
202 EXPECT_TRUE(Full.intersectWith(One) == One);
203 EXPECT_TRUE(Full.intersectWith(Some) == Some);
204 EXPECT_TRUE(Some.intersectWith(Wrap).isEmptySet());
205 EXPECT_TRUE(One.intersectWith(Wrap).isEmptySet());
Chris Lattner8142ce52009-08-23 06:32:25 +0000206 EXPECT_TRUE(One.intersectWith(Wrap) == Wrap.intersectWith(One));
Dan Gohmana3755d82009-07-09 22:07:27 +0000207
Nick Lewycky3a4a8842009-07-18 06:34:42 +0000208 // Klee generated testcase from PR4545.
209 // The intersection of i16 [4, 2) and [6, 5) is disjoint, looking like
210 // 01..4.6789ABCDEF where the dots represent values not in the intersection.
211 ConstantRange LHS(APInt(16, 4), APInt(16, 2));
212 ConstantRange RHS(APInt(16, 6), APInt(16, 5));
Chris Lattner8142ce52009-08-23 06:32:25 +0000213 EXPECT_TRUE(LHS.intersectWith(RHS) == LHS);
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000214}
Dan Gohmana3755d82009-07-09 22:07:27 +0000215
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000216TEST_F(ConstantRangeTest, UnionWith) {
Chris Lattner8142ce52009-08-23 06:32:25 +0000217 EXPECT_TRUE(Wrap.unionWith(One) ==
218 ConstantRange(APInt(16, 0xaaa), APInt(16, 0xb)));
219 EXPECT_TRUE(One.unionWith(Wrap) == Wrap.unionWith(One));
Dan Gohmana3755d82009-07-09 22:07:27 +0000220 EXPECT_TRUE(Empty.unionWith(Empty).isEmptySet());
221 EXPECT_TRUE(Full.unionWith(Full).isFullSet());
222 EXPECT_TRUE(Some.unionWith(Wrap).isFullSet());
Nick Lewycky7e7dc452009-07-19 03:44:35 +0000223
224 // PR4545
Chris Lattner8142ce52009-08-23 06:32:25 +0000225 EXPECT_TRUE(ConstantRange(APInt(16, 14), APInt(16, 1)).unionWith(
226 ConstantRange(APInt(16, 0), APInt(16, 8))) ==
227 ConstantRange(APInt(16, 14), APInt(16, 8)));
228 EXPECT_TRUE(ConstantRange(APInt(16, 6), APInt(16, 4)).unionWith(
229 ConstantRange(APInt(16, 4), APInt(16, 0))) ==
230 ConstantRange(16));
231 EXPECT_TRUE(ConstantRange(APInt(16, 1), APInt(16, 0)).unionWith(
232 ConstantRange(APInt(16, 2), APInt(16, 1))) ==
233 ConstantRange(16));
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000234}
Dan Gohmana3755d82009-07-09 22:07:27 +0000235
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000236TEST_F(ConstantRangeTest, SubtractAPInt) {
Dan Gohmana3755d82009-07-09 22:07:27 +0000237 EXPECT_TRUE(Full.subtract(APInt(16, 4)).isFullSet());
238 EXPECT_TRUE(Empty.subtract(APInt(16, 4)).isEmptySet());
Chris Lattner8142ce52009-08-23 06:32:25 +0000239 EXPECT_TRUE(Some.subtract(APInt(16, 4)) ==
240 ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6)));
241 EXPECT_TRUE(Wrap.subtract(APInt(16, 4)) ==
242 ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6)));
243 EXPECT_TRUE(One.subtract(APInt(16, 4)) ==
244 ConstantRange(APInt(16, 0x6)));
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000245}
Dan Gohmana3755d82009-07-09 22:07:27 +0000246
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000247TEST_F(ConstantRangeTest, Add) {
Dan Gohmana3755d82009-07-09 22:07:27 +0000248 EXPECT_TRUE(Full.add(APInt(16, 4)).isFullSet());
Chris Lattner8142ce52009-08-23 06:32:25 +0000249 EXPECT_TRUE(Full.add(Full) == Full);
250 EXPECT_TRUE(Full.add(Empty) == Empty);
251 EXPECT_TRUE(Full.add(One) == Full);
252 EXPECT_TRUE(Full.add(Some) == Full);
253 EXPECT_TRUE(Full.add(Wrap) == Full);
254 EXPECT_TRUE(Empty.add(Empty) == Empty);
255 EXPECT_TRUE(Empty.add(One) == Empty);
256 EXPECT_TRUE(Empty.add(Some) == Empty);
257 EXPECT_TRUE(Empty.add(Wrap) == Empty);
Dan Gohmana3755d82009-07-09 22:07:27 +0000258 EXPECT_TRUE(Empty.add(APInt(16, 4)).isEmptySet());
Chris Lattner8142ce52009-08-23 06:32:25 +0000259 EXPECT_TRUE(Some.add(APInt(16, 4)) ==
260 ConstantRange(APInt(16, 0xe), APInt(16, 0xaae)));
261 EXPECT_TRUE(Wrap.add(APInt(16, 4)) ==
262 ConstantRange(APInt(16, 0xaae), APInt(16, 0xe)));
263 EXPECT_TRUE(One.add(APInt(16, 4)) ==
264 ConstantRange(APInt(16, 0xe)));
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000265}
Dan Gohmana3755d82009-07-09 22:07:27 +0000266
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000267TEST_F(ConstantRangeTest, Multiply) {
Chris Lattner8142ce52009-08-23 06:32:25 +0000268 EXPECT_TRUE(Full.multiply(Full) == Full);
269 EXPECT_TRUE(Full.multiply(Empty) == Empty);
270 EXPECT_TRUE(Full.multiply(One) == Full);
271 EXPECT_TRUE(Full.multiply(Some) == Full);
272 EXPECT_TRUE(Full.multiply(Wrap) == Full);
273 EXPECT_TRUE(Empty.multiply(Empty) == Empty);
274 EXPECT_TRUE(Empty.multiply(One) == Empty);
275 EXPECT_TRUE(Empty.multiply(Some) == Empty);
276 EXPECT_TRUE(Empty.multiply(Wrap) == Empty);
277 EXPECT_TRUE(One.multiply(One) == ConstantRange(APInt(16, 0xa*0xa),
278 APInt(16, 0xa*0xa + 1)));
279 EXPECT_TRUE(One.multiply(Some) == ConstantRange(APInt(16, 0xa*0xa),
280 APInt(16, 0xa*0xaa9 + 1)));
Nick Lewycky2ff893f2009-07-12 02:19:05 +0000281 EXPECT_TRUE(One.multiply(Wrap).isFullSet());
282 EXPECT_TRUE(Some.multiply(Some).isFullSet());
Chris Lattner8142ce52009-08-23 06:32:25 +0000283 EXPECT_TRUE(Some.multiply(Wrap) == Full);
284 EXPECT_TRUE(Wrap.multiply(Wrap) == Full);
Nick Lewyckyf1db1202009-07-13 03:27:41 +0000285
286 // http://llvm.org/PR4545
Chris Lattner8142ce52009-08-23 06:32:25 +0000287 EXPECT_TRUE(ConstantRange(APInt(4, 1), APInt(4, 6)).multiply(
288 ConstantRange(APInt(4, 6), APInt(4, 2))) ==
289 ConstantRange(4, /*isFullSet=*/true));
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000290}
Dan Gohmana3755d82009-07-09 22:07:27 +0000291
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000292TEST_F(ConstantRangeTest, UMax) {
293 EXPECT_TRUE(Full.umax(Full).isFullSet());
294 EXPECT_TRUE(Full.umax(Empty).isEmptySet());
Chris Lattner8142ce52009-08-23 06:32:25 +0000295 EXPECT_TRUE(Full.umax(Some) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000296 EXPECT_TRUE(Full.umax(Wrap).isFullSet());
Chris Lattner8142ce52009-08-23 06:32:25 +0000297 EXPECT_TRUE(Full.umax(Some) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
298 EXPECT_TRUE(Empty.umax(Empty) == Empty);
299 EXPECT_TRUE(Empty.umax(Some) == Empty);
300 EXPECT_TRUE(Empty.umax(Wrap) == Empty);
301 EXPECT_TRUE(Empty.umax(One) == Empty);
302 EXPECT_TRUE(Some.umax(Some) == Some);
303 EXPECT_TRUE(Some.umax(Wrap) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
304 EXPECT_TRUE(Some.umax(One) == Some);
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000305 // TODO: ConstantRange is currently over-conservative here.
Chris Lattner8142ce52009-08-23 06:32:25 +0000306 EXPECT_TRUE(Wrap.umax(Wrap) == Full);
307 EXPECT_TRUE(Wrap.umax(One) == ConstantRange(APInt(16, 0xa), APInt(16, 0)));
308 EXPECT_TRUE(One.umax(One) == One);
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000309}
310
311TEST_F(ConstantRangeTest, SMax) {
Dan Gohman38b06442009-07-09 23:16:10 +0000312 EXPECT_TRUE(Full.smax(Full).isFullSet());
313 EXPECT_TRUE(Full.smax(Empty).isEmptySet());
Chris Lattner8142ce52009-08-23 06:32:25 +0000314 EXPECT_TRUE(Full.smax(Some) == ConstantRange(APInt(16, 0xa),
315 APInt::getSignedMinValue(16)));
Dan Gohman38b06442009-07-09 23:16:10 +0000316 EXPECT_TRUE(Full.smax(Wrap).isFullSet());
Chris Lattner8142ce52009-08-23 06:32:25 +0000317 EXPECT_TRUE(Full.smax(One) == ConstantRange(APInt(16, 0xa),
318 APInt::getSignedMinValue(16)));
319 EXPECT_TRUE(Empty.smax(Empty) == Empty);
320 EXPECT_TRUE(Empty.smax(Some) == Empty);
321 EXPECT_TRUE(Empty.smax(Wrap) == Empty);
322 EXPECT_TRUE(Empty.smax(One) == Empty);
323 EXPECT_TRUE(Some.smax(Some) == Some);
324 EXPECT_TRUE(Some.smax(Wrap) == ConstantRange(APInt(16, 0xa),
325 APInt(16, (uint64_t)INT16_MIN)));
326 EXPECT_TRUE(Some.smax(One) == Some);
327 EXPECT_TRUE(Wrap.smax(One) == ConstantRange(APInt(16, 0xa),
328 APInt(16, (uint64_t)INT16_MIN)));
329 EXPECT_TRUE(One.smax(One) == One);
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000330}
Dan Gohmana3755d82009-07-09 22:07:27 +0000331
Nick Lewycky44b3e8d2009-07-11 18:43:20 +0000332TEST_F(ConstantRangeTest, UDiv) {
Chris Lattner8142ce52009-08-23 06:32:25 +0000333 EXPECT_TRUE(Full.udiv(Full) == Full);
334 EXPECT_TRUE(Full.udiv(Empty) == Empty);
335 EXPECT_TRUE(Full.udiv(One) == ConstantRange(APInt(16, 0),
336 APInt(16, 0xffff / 0xa + 1)));
337 EXPECT_TRUE(Full.udiv(Some) == ConstantRange(APInt(16, 0),
338 APInt(16, 0xffff / 0xa + 1)));
339 EXPECT_TRUE(Full.udiv(Wrap) == Full);
340 EXPECT_TRUE(Empty.udiv(Empty) == Empty);
341 EXPECT_TRUE(Empty.udiv(One) == Empty);
342 EXPECT_TRUE(Empty.udiv(Some) == Empty);
343 EXPECT_TRUE(Empty.udiv(Wrap) == Empty);
344 EXPECT_TRUE(One.udiv(One) == ConstantRange(APInt(16, 1)));
345 EXPECT_TRUE(One.udiv(Some) == ConstantRange(APInt(16, 0), APInt(16, 2)));
346 EXPECT_TRUE(One.udiv(Wrap) == ConstantRange(APInt(16, 0), APInt(16, 0xb)));
347 EXPECT_TRUE(Some.udiv(Some) == ConstantRange(APInt(16, 0), APInt(16, 0x111)));
348 EXPECT_TRUE(Some.udiv(Wrap) == ConstantRange(APInt(16, 0), APInt(16, 0xaaa)));
349 EXPECT_TRUE(Wrap.udiv(Wrap) == Full);
Dan Gohmana3755d82009-07-09 22:07:27 +0000350}
351
352} // anonymous namespace