1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
4 define void @test.not.uge.ult(i8 %start, i8 %low, i8 %high) {
5 ; CHECK-LABEL: @test.not.uge.ult(
7 ; CHECK-NEXT: [[SUB_PTR_I:%.*]] = sub nuw i8 [[START:%.*]], 3
8 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[SUB_PTR_I]], [[HIGH:%.*]]
9 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
11 ; CHECK-NEXT: ret void
13 ; CHECK-NEXT: [[T_0:%.*]] = icmp ult i8 [[START]], [[HIGH]]
14 ; CHECK-NEXT: call void @use(i1 [[T_0]])
15 ; CHECK-NEXT: [[START_1:%.*]] = sub nuw i8 [[START]], 1
16 ; CHECK-NEXT: [[T_1:%.*]] = icmp ult i8 [[START_1]], [[HIGH]]
17 ; CHECK-NEXT: call void @use(i1 [[T_1]])
18 ; CHECK-NEXT: [[START_2:%.*]] = sub nuw i8 [[START]], 2
19 ; CHECK-NEXT: [[T_2:%.*]] = icmp ult i8 [[START_2]], [[HIGH]]
20 ; CHECK-NEXT: call void @use(i1 [[T_2]])
21 ; CHECK-NEXT: [[START_3:%.*]] = sub nuw i8 [[START]], 3
22 ; CHECK-NEXT: call void @use(i1 true)
23 ; CHECK-NEXT: [[START_4:%.*]] = sub nuw i8 [[START]], 4
24 ; CHECK-NEXT: call void @use(i1 true)
25 ; CHECK-NEXT: ret void
28 %sub.ptr.i = sub nuw i8 %start, 3
29 %c.1 = icmp uge i8 %sub.ptr.i, %high
30 br i1 %c.1, label %if.then, label %if.end
32 if.then: ; preds = %entry
35 if.end: ; preds = %entry
36 %t.0 = icmp ult i8 %start, %high
37 call void @use(i1 %t.0)
38 %start.1 = sub nuw i8 %start, 1
39 %t.1 = icmp ult i8 %start.1, %high
40 call void @use(i1 %t.1)
41 %start.2 = sub nuw i8 %start, 2
42 %t.2 = icmp ult i8 %start.2, %high
43 call void @use(i1 %t.2)
44 %start.3 = sub nuw i8 %start, 3
45 %t.3 = icmp ult i8 %start.3, %high
46 call void @use(i1 %t.3)
47 %start.4 = sub nuw i8 %start, 4
48 %c.4 = icmp ult i8 %start.4, %high
49 call void @use(i1 %c.4)
53 define void @test.not.uge.ule(i8 %start, i8 %low, i8 %high) {
54 ; CHECK-LABEL: @test.not.uge.ule(
56 ; CHECK-NEXT: [[SUB_PTR_I:%.*]] = sub nuw i8 [[START:%.*]], 3
57 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[SUB_PTR_I]], [[HIGH:%.*]]
58 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
60 ; CHECK-NEXT: ret void
62 ; CHECK-NEXT: [[T_0:%.*]] = icmp ule i8 [[START]], [[HIGH]]
63 ; CHECK-NEXT: call void @use(i1 [[T_0]])
64 ; CHECK-NEXT: [[START_1:%.*]] = sub nuw i8 [[START]], 1
65 ; CHECK-NEXT: [[T_1:%.*]] = icmp ule i8 [[START_1]], [[HIGH]]
66 ; CHECK-NEXT: call void @use(i1 [[T_1]])
67 ; CHECK-NEXT: [[START_2:%.*]] = sub nuw i8 [[START]], 2
68 ; CHECK-NEXT: call void @use(i1 true)
69 ; CHECK-NEXT: [[START_3:%.*]] = sub nuw i8 [[START]], 3
70 ; CHECK-NEXT: call void @use(i1 true)
71 ; CHECK-NEXT: [[START_4:%.*]] = sub nuw i8 [[START]], 4
72 ; CHECK-NEXT: call void @use(i1 true)
73 ; CHECK-NEXT: [[START_5:%.*]] = sub nuw i8 [[START]], 5
74 ; CHECK-NEXT: call void @use(i1 true)
75 ; CHECK-NEXT: ret void
78 %sub.ptr.i = sub nuw i8 %start, 3
79 %c.1 = icmp uge i8 %sub.ptr.i, %high
80 br i1 %c.1, label %if.then, label %if.end
82 if.then: ; preds = %entry
85 if.end: ; preds = %entry
86 %t.0 = icmp ule i8 %start, %high
87 call void @use(i1 %t.0)
88 %start.1 = sub nuw i8 %start, 1
89 %t.1 = icmp ule i8 %start.1, %high
90 call void @use(i1 %t.1)
91 %start.2 = sub nuw i8 %start, 2
92 %t.2 = icmp ule i8 %start.2, %high
93 call void @use(i1 %t.2)
94 %start.3 = sub nuw i8 %start, 3
95 %t.3 = icmp ule i8 %start.3, %high
96 call void @use(i1 %t.3)
97 %start.4 = sub nuw i8 %start, 4
98 %t.4 = icmp ule i8 %start.4, %high
99 call void @use(i1 %t.4)
101 %start.5 = sub nuw i8 %start, 5
102 %c.5 = icmp ule i8 %start.5, %high
103 call void @use(i1 %c.5)
108 define void @test.not.uge.ugt(i8 %start, i8 %low, i8 %high) {
109 ; CHECK-LABEL: @test.not.uge.ugt(
111 ; CHECK-NEXT: [[SUB_PTR_I:%.*]] = sub nuw i8 [[START:%.*]], 3
112 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[SUB_PTR_I]], [[HIGH:%.*]]
113 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
115 ; CHECK-NEXT: ret void
117 ; CHECK-NEXT: [[F_0:%.*]] = icmp ugt i8 [[START]], [[HIGH]]
118 ; CHECK-NEXT: call void @use(i1 [[F_0]])
119 ; CHECK-NEXT: [[START_1:%.*]] = sub nuw i8 [[START]], 1
120 ; CHECK-NEXT: [[F_1:%.*]] = icmp ugt i8 [[START_1]], [[HIGH]]
121 ; CHECK-NEXT: call void @use(i1 [[F_1]])
122 ; CHECK-NEXT: [[START_2:%.*]] = sub nuw i8 [[START]], 2
123 ; CHECK-NEXT: call void @use(i1 false)
124 ; CHECK-NEXT: [[START_3:%.*]] = sub nuw i8 [[START]], 3
125 ; CHECK-NEXT: call void @use(i1 false)
126 ; CHECK-NEXT: [[START_4:%.*]] = sub nuw i8 [[START]], 4
127 ; CHECK-NEXT: call void @use(i1 false)
128 ; CHECK-NEXT: [[START_5:%.*]] = sub nuw i8 [[START]], 5
129 ; CHECK-NEXT: call void @use(i1 false)
130 ; CHECK-NEXT: ret void
133 %sub.ptr.i = sub nuw i8 %start, 3
134 %c.1 = icmp uge i8 %sub.ptr.i, %high
135 br i1 %c.1, label %if.then, label %if.end
137 if.then: ; preds = %entry
140 if.end: ; preds = %entry
141 %f.0 = icmp ugt i8 %start, %high
142 call void @use(i1 %f.0)
144 %start.1 = sub nuw i8 %start, 1
145 %f.1 = icmp ugt i8 %start.1, %high
146 call void @use(i1 %f.1)
148 %start.2 = sub nuw i8 %start, 2
149 %f.2 = icmp ugt i8 %start.2, %high
150 call void @use(i1 %f.2)
152 %start.3 = sub nuw i8 %start, 3
153 %f.3 = icmp ugt i8 %start.3, %high
154 call void @use(i1 %f.3)
156 %start.4 = sub nuw i8 %start, 4
157 %f.4 = icmp ugt i8 %start.4, %high
158 call void @use(i1 %f.4)
160 %start.5 = sub nuw i8 %start, 5
161 %c.5 = icmp ugt i8 %start.5, %high
162 call void @use(i1 %c.5)
167 define void @test.not.uge.uge(i8 %start, i8 %low, i8 %high) {
168 ; CHECK-LABEL: @test.not.uge.uge(
170 ; CHECK-NEXT: [[SUB_PTR_I:%.*]] = sub nuw i8 [[START:%.*]], 3
171 ; CHECK-NEXT: [[C_1:%.*]] = icmp uge i8 [[SUB_PTR_I]], [[HIGH:%.*]]
172 ; CHECK-NEXT: br i1 [[C_1]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
174 ; CHECK-NEXT: ret void
176 ; CHECK-NEXT: [[F_0:%.*]] = icmp ugt i8 [[START]], [[HIGH]]
177 ; CHECK-NEXT: call void @use(i1 [[F_0]])
178 ; CHECK-NEXT: [[START_1:%.*]] = sub nuw i8 [[START]], 1
179 ; CHECK-NEXT: [[F_1:%.*]] = icmp uge i8 [[START_1]], [[HIGH]]
180 ; CHECK-NEXT: call void @use(i1 [[F_1]])
181 ; CHECK-NEXT: [[START_2:%.*]] = sub nuw i8 [[START]], 2
182 ; CHECK-NEXT: [[F_2:%.*]] = icmp uge i8 [[START_2]], [[HIGH]]
183 ; CHECK-NEXT: call void @use(i1 [[F_2]])
184 ; CHECK-NEXT: [[START_3:%.*]] = sub nuw i8 [[START]], 3
185 ; CHECK-NEXT: call void @use(i1 false)
186 ; CHECK-NEXT: [[START_4:%.*]] = sub nuw i8 [[START]], 4
187 ; CHECK-NEXT: call void @use(i1 false)
188 ; CHECK-NEXT: [[START_5:%.*]] = sub nuw i8 [[START]], 5
189 ; CHECK-NEXT: call void @use(i1 false)
190 ; CHECK-NEXT: ret void
193 %sub.ptr.i = sub nuw i8 %start, 3
194 %c.1 = icmp uge i8 %sub.ptr.i, %high
195 br i1 %c.1, label %if.then, label %if.end
197 if.then: ; preds = %entry
200 if.end: ; preds = %entry
201 %f.0 = icmp ugt i8 %start, %high
202 call void @use(i1 %f.0)
204 %start.1 = sub nuw i8 %start, 1
205 %f.1 = icmp uge i8 %start.1, %high
206 call void @use(i1 %f.1)
208 %start.2 = sub nuw i8 %start, 2
209 %f.2 = icmp uge i8 %start.2, %high
210 call void @use(i1 %f.2)
212 %start.3 = sub nuw i8 %start, 3
213 %f.3 = icmp uge i8 %start.3, %high
214 call void @use(i1 %f.3)
216 %start.4 = sub nuw i8 %start, 4
217 %c.4 = icmp uge i8 %start.4, %high
218 call void @use(i1 %c.4)
220 %start.5 = sub nuw i8 %start, 5
221 %c.5 = icmp uge i8 %start.5, %high
222 call void @use(i1 %c.5)
227 define i16 @test_pr53123_sub_constraint_sign(i16 %v) {
228 ; CHECK-LABEL: @test_pr53123_sub_constraint_sign(
230 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i16 32767, [[V:%.*]]
231 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i16 [[V]], [[SUB]]
232 ; CHECK-NEXT: br i1 [[CMP1]], label [[BB_2:%.*]], label [[BB_1:%.*]]
234 ; CHECK-NEXT: [[ADD:%.*]] = shl nuw nsw i16 [[V]], 1
235 ; CHECK-NEXT: [[SUB9:%.*]] = sub nuw nsw i16 32767, [[ADD]]
236 ; CHECK-NEXT: [[CMP11:%.*]] = icmp ugt i16 [[ADD]], [[SUB9]]
237 ; CHECK-NEXT: br i1 [[CMP11]], label [[BB_3:%.*]], label [[BB_2]]
239 ; CHECK-NEXT: ret i16 1
241 ; CHECK-NEXT: ret i16 0
244 %sub = sub nuw nsw i16 32767, %v
245 %cmp1 = icmp ugt i16 %v, %sub
246 br i1 %cmp1, label %bb.2, label %bb.1
249 %add = shl nuw nsw i16 %v, 1
250 %sub9 = sub nuw nsw i16 32767, %add
251 %cmp11 = icmp ugt i16 %add, %sub9
252 br i1 %cmp11, label %bb.3, label %bb.2
261 declare void @use(i1)
263 define i1 @sub_nuw_i16_simp(i16 %a) {
264 ; CHECK-LABEL: @sub_nuw_i16_simp(
266 ; CHECK-NEXT: [[NEG2:%.*]] = sub nuw i16 [[A:%.*]], 305
267 ; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i16 0, [[NEG2]]
268 ; CHECK-NEXT: br i1 [[C_1]], label [[EXIT_1:%.*]], label [[EXIT_2:%.*]]
270 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i16 [[A]], 0
271 ; CHECK-NEXT: ret i1 [[C_2]]
273 ; CHECK-NEXT: ret i1 true
276 %neg2 = sub nuw i16 %a, 305
277 %c.1 = icmp ugt i16 0, %neg2
278 br i1 %c.1, label %exit.1, label %exit.2
281 %c.2 = icmp ugt i16 %a, 0
285 %c.3 = icmp ugt i16 %a, 0
289 define i1 @sub_nuw_i64_simp(i64 %a) {
290 ; CHECK-LABEL: @sub_nuw_i64_simp(
292 ; CHECK-NEXT: [[NEG2:%.*]] = sub nuw i64 [[A:%.*]], 305
293 ; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i64 0, [[NEG2]]
294 ; CHECK-NEXT: br i1 [[C_1]], label [[EXIT_1:%.*]], label [[EXIT_2:%.*]]
296 ; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i64 [[A]], 0
297 ; CHECK-NEXT: ret i1 [[C_2]]
299 ; CHECK-NEXT: ret i1 true
302 %neg2 = sub nuw i64 %a, 305
303 %c.1 = icmp ugt i64 0, %neg2
304 br i1 %c.1, label %exit.1, label %exit.2
307 %c.2 = icmp ugt i64 %a, 0
311 %c.3 = icmp ugt i64 %a, 0
315 define i1 @sub_nuw_neg_i16(i16 %a) {
316 ; CHECK-LABEL: @sub_nuw_neg_i16(
318 ; CHECK-NEXT: [[NEG2:%.*]] = sub nuw i16 [[A:%.*]], -305
319 ; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i16 0, [[NEG2]]
320 ; CHECK-NEXT: br i1 [[C_1]], label [[EXIT_1:%.*]], label [[EXIT_2:%.*]]
322 ; CHECK-NEXT: ret i1 false
324 ; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i16 [[A]], 0
325 ; CHECK-NEXT: ret i1 [[C_3]]
328 %neg2 = sub nuw i16 %a, -305
329 %c.1 = icmp ugt i16 0, %neg2
330 br i1 %c.1, label %exit.1, label %exit.2
333 %c.2 = icmp ugt i16 %a, 0
337 %c.3 = icmp ugt i16 %a, 0
341 declare void @llvm.assume(i1)
343 define i1 @wrapping_offset_sum(i64 %x) {
344 ; CHECK-LABEL: @wrapping_offset_sum(
345 ; CHECK-NEXT: [[NON_ZERO:%.*]] = icmp ugt i64 [[X:%.*]], 0
346 ; CHECK-NEXT: call void @llvm.assume(i1 [[NON_ZERO]])
347 ; CHECK-NEXT: [[ADD:%.*]] = sub nuw i64 [[X]], 9223372036854775802
348 ; CHECK-NEXT: [[ULT:%.*]] = icmp ugt i64 200, [[ADD]]
349 ; CHECK-NEXT: ret i1 [[ULT]]
351 %non.zero = icmp ugt i64 %x, 0
352 call void @llvm.assume(i1 %non.zero)
353 %add = sub nuw i64 %x, 9223372036854775802
354 %ult = icmp ugt i64 200, %add
358 define i1 @sub_nuw_i64_signed_min(i64 %a) {
359 ; CHECK-LABEL: @sub_nuw_i64_signed_min(
361 ; CHECK-NEXT: [[SUB:%.*]] = sub nuw i64 [[A:%.*]], -9223372036854775808
362 ; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i64 [[A]], [[SUB]]
363 ; CHECK-NEXT: ret i1 [[C_1]]
366 %sub = sub nuw i64 %a, -9223372036854775808
367 %c.1 = icmp ugt i64 %a, %sub
371 define i1 @sub_nuw_i64_signed_min_const(i64 %a) {
372 ; CHECK-LABEL: @sub_nuw_i64_signed_min_const(
374 ; CHECK-NEXT: [[NEG2:%.*]] = sub nuw i64 0, -9223372036854775808
375 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i64 [[NEG2]], 0
376 ; CHECK-NEXT: ret i1 [[C]]
379 %neg2 = sub nuw i64 0, -9223372036854775808
380 %c = icmp ugt i64 %neg2, 0