1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=instsimplify < %s -S | FileCheck %s
4 declare void @llvm.assume(i1)
5 declare i8 @llvm.abs.i8(i8, i1)
6 declare i8 @llvm.bitreverse.i8(i8)
7 declare i16 @llvm.bswap.i16(i16)
8 declare i8 @llvm.ctpop.i8(i8)
9 declare <2 x i8> @llvm.uadd.sat.2xi8(<2 x i8>, <2 x i8>)
10 declare i8 @llvm.uadd.sat.i8(i8, i8)
11 declare i8 @llvm.fshr.i8(i8, i8, i8)
12 declare i8 @llvm.fshl.i8(i8, i8, i8)
13 declare i8 @llvm.ctlz.i8(i8, i1)
14 declare i8 @llvm.cttz.i8(i8, i1)
15 declare i8 @llvm.sadd.sat.i8(i8, i8)
16 declare i8 @llvm.smax.i8(i8, i8)
17 declare i8 @llvm.smin.i8(i8, i8)
18 declare i8 @llvm.sshl.sat.i8(i8, i8)
19 declare i8 @llvm.ssub.sat.i8(i8, i8)
20 declare i8 @llvm.umax.i8(i8, i8)
21 declare i8 @llvm.umin.i8(i8, i8)
22 declare i8 @llvm.ushl.sat.i8(i8, i8)
23 declare i8 @llvm.usub.sat.i8(i8, i8)
24 declare float @llvm.maximum.f32(float, float)
26 ;; Throughout use: X > Y || Y == 0 which folds to X > Y iff X known
27 ;; non-zero. Do this because many of the expressions already have
28 ;; hardcoded cases for folding Foo(X) == 0 -> X == 0 and we want to
29 ;; test explicitly that `isKnownNonZero` works.
31 define i1 @check_neg(i8 %x, i8 %y) {
32 ; CHECK-LABEL: @check_neg(
33 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i8 [[X:%.*]], 0
34 ; CHECK-NEXT: call void @llvm.assume(i1 [[NE]])
35 ; CHECK-NEXT: [[Z:%.*]] = sub i8 0, [[X]]
36 ; CHECK-NEXT: [[CMP0:%.*]] = icmp ugt i8 [[Z]], [[Y:%.*]]
37 ; CHECK-NEXT: ret i1 [[CMP0]]
39 %ne = icmp ne i8 %x, 0
40 call void @llvm.assume(i1 %ne)
42 %cmp0 = icmp ugt i8 %z, %y
43 %cmp1 = icmp eq i8 %y, 0
44 %r = or i1 %cmp0, %cmp1
48 define i1 @check_abs(i8 %x, i8 %y) {
49 ; CHECK-LABEL: @check_abs(
50 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i8 [[X:%.*]], 0
51 ; CHECK-NEXT: br i1 [[NE]], label [[TRUE:%.*]], label [[FALSE:%.*]]
53 ; CHECK-NEXT: [[Z:%.*]] = call i8 @llvm.abs.i8(i8 [[X]], i1 true)
54 ; CHECK-NEXT: [[CMP0:%.*]] = icmp ugt i8 [[Z]], [[Y:%.*]]
55 ; CHECK-NEXT: ret i1 [[CMP0]]
57 ; CHECK-NEXT: ret i1 [[NE]]
59 %ne = icmp ne i8 %x, 0
60 br i1 %ne, label %true, label %false
62 %z = call i8 @llvm.abs.i8(i8 %x, i1 true)
63 %cmp0 = icmp ugt i8 %z, %y
64 %cmp1 = icmp eq i8 %y, 0
65 %r = or i1 %cmp0, %cmp1
71 define i1 @check_abs_failish(i8 %x, i8 %y) {
72 ; CHECK-LABEL: @check_abs_failish(
73 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i8 [[X:%.*]], 0
74 ; CHECK-NEXT: br i1 [[NE]], label [[TRUE:%.*]], label [[FALSE:%.*]]
76 ; CHECK-NEXT: [[Z:%.*]] = call i8 @llvm.abs.i8(i8 [[X]], i1 true)
77 ; CHECK-NEXT: [[CMP0:%.*]] = icmp ugt i8 [[Z]], [[Y:%.*]]
78 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[Y]], 0
79 ; CHECK-NEXT: [[R:%.*]] = or i1 [[CMP0]], [[CMP1]]
80 ; CHECK-NEXT: ret i1 [[R]]
82 ; CHECK-NEXT: ret i1 [[NE]]
84 %ne = icmp ne i8 %x, 0
85 br i1 %ne, label %true, label %false
87 %z = call i8 @llvm.abs.i8(i8 %x, i1 true)
88 %cmp0 = icmp ugt i8 %z, %y
89 %cmp1 = icmp eq i8 %y, 0
90 %r = or i1 %cmp0, %cmp1
96 define i1 @check_bitreverse(i8 %x, i8 %y) {
97 ; CHECK-LABEL: @check_bitreverse(
98 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i8 [[X:%.*]], 0
99 ; CHECK-NEXT: call void @llvm.assume(i1 [[NE]])
100 ; CHECK-NEXT: [[Z:%.*]] = call i8 @llvm.bitreverse.i8(i8 [[X]])
101 ; CHECK-NEXT: [[CMP0:%.*]] = icmp ugt i8 [[Z]], [[Y:%.*]]
102 ; CHECK-NEXT: ret i1 [[CMP0]]
104 %ne = icmp ne i8 %x, 0
105 call void @llvm.assume(i1 %ne)
106 %z = call i8 @llvm.bitreverse.i8(i8 %x)
107 %cmp0 = icmp ugt i8 %z, %y
108 %cmp1 = icmp eq i8 %y, 0
109 %r = or i1 %cmp0, %cmp1
113 define i1 @check_bswap(i16 %x, i16 %y) {
114 ; CHECK-LABEL: @check_bswap(
115 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i16 [[X:%.*]], 0
116 ; CHECK-NEXT: call void @llvm.assume(i1 [[NE]])
117 ; CHECK-NEXT: [[Z:%.*]] = call i16 @llvm.bswap.i16(i16 [[X]])
118 ; CHECK-NEXT: [[CMP0:%.*]] = icmp ugt i16 [[Z]], [[Y:%.*]]
119 ; CHECK-NEXT: ret i1 [[CMP0]]
121 %ne = icmp ne i16 %x, 0
122 call void @llvm.assume(i1 %ne)
123 %z = call i16 @llvm.bswap.i16(i16 %x)
124 %cmp0 = icmp ugt i16 %z, %y
125 %cmp1 = icmp eq i16 %y, 0
126 %r = or i1 %cmp0, %cmp1
130 define i1 @check_ctpop(i8 %x, i8 %y) {
131 ; CHECK-LABEL: @check_ctpop(
132 ; CHECK-NEXT: [[NE:%.*]] = icmp eq i8 [[X:%.*]], 0
133 ; CHECK-NEXT: br i1 [[NE]], label [[TRUE:%.*]], label [[FALSE:%.*]]
135 ; CHECK-NEXT: ret i1 [[NE]]
137 ; CHECK-NEXT: [[Z:%.*]] = call i8 @llvm.ctpop.i8(i8 [[X]])
138 ; CHECK-NEXT: [[CMP0:%.*]] = icmp ugt i8 [[Z]], [[Y:%.*]]
139 ; CHECK-NEXT: ret i1 [[CMP0]]
141 %ne = icmp eq i8 %x, 0
142 br i1 %ne, label %true, label %false
146 %z = call i8 @llvm.ctpop.i8(i8 %x)
147 %cmp0 = icmp ugt i8 %z, %y
148 %cmp1 = icmp eq i8 %y, 0
149 %r = or i1 %cmp0, %cmp1
153 define i1 @check_add_sat(i8 %x, i8 %y, i8 %w) {
154 ; CHECK-LABEL: @check_add_sat(
155 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i8 [[X:%.*]], 0
156 ; CHECK-NEXT: call void @llvm.assume(i1 [[NE]])
157 ; CHECK-NEXT: [[Z:%.*]] = call i8 @llvm.uadd.sat.i8(i8 [[X]], i8 [[Y:%.*]])
158 ; CHECK-NEXT: [[CMP0:%.*]] = icmp ugt i8 [[Z]], [[W:%.*]]
159 ; CHECK-NEXT: ret i1 [[CMP0]]
161 %ne = icmp ne i8 %x, 0
162 call void @llvm.assume(i1 %ne)
163 %z = call i8 @llvm.uadd.sat.i8(i8 %x, i8 %y)
164 %cmp0 = icmp ugt i8 %z, %w
165 %cmp1 = icmp eq i8 %w, 0
166 %r = or i1 %cmp0, %cmp1
170 define <2 x i1> @check_add_sat_vec(<2 x i8> %x, <2 x i8> %y, <2 x i8> %w) {
171 ; CHECK-LABEL: @check_add_sat_vec(
172 ; CHECK-NEXT: [[YNZ:%.*]] = or <2 x i8> [[Y:%.*]], <i8 2, i8 1>
173 ; CHECK-NEXT: [[Z:%.*]] = call <2 x i8> @llvm.uadd.sat.v2i8(<2 x i8> [[X:%.*]], <2 x i8> [[YNZ]])
174 ; CHECK-NEXT: [[CMP0:%.*]] = icmp ugt <2 x i8> [[Z]], [[W:%.*]]
175 ; CHECK-NEXT: ret <2 x i1> [[CMP0]]
177 %ynz = or <2 x i8> %y, <i8 2, i8 1>
178 %z = call <2 x i8> @llvm.uadd.sat.2xi8(<2 x i8> %x, <2 x i8> %ynz)
179 %cmp0 = icmp ugt <2 x i8> %z, %w
180 %cmp1 = icmp eq <2 x i8> %w, <i8 0, i8 0>
181 %r = or <2 x i1> %cmp0, %cmp1
185 define <2 x i1> @shl_nz_bounded_cnt_vec(<2 x i32> %x, <2 x i32> %y) {
186 ; CHECK-LABEL: @shl_nz_bounded_cnt_vec(
187 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
189 %cnt = and <2 x i32> %x, <i32 16, i32 24>
190 %val = or <2 x i32> %y, <i32 131088, i32 16>
191 %shl = shl <2 x i32> %val, %cnt
192 %r = icmp eq <2 x i32> %shl, zeroinitializer
196 define i1 @shl_nz_bounded_cnt(i32 %cnt, i32 %y) {
197 ; CHECK-LABEL: @shl_nz_bounded_cnt(
198 ; CHECK-NEXT: [[CNT_ULT4:%.*]] = icmp ult i32 [[CNT:%.*]], 4
199 ; CHECK-NEXT: call void @llvm.assume(i1 [[CNT_ULT4]])
200 ; CHECK-NEXT: ret i1 false
202 %cnt_ult4 = icmp ult i32 %cnt, 4
203 call void @llvm.assume(i1 %cnt_ult4)
204 %val = or i32 %y, 131072
205 %shl = shl i32 %val, %cnt
206 %r = icmp eq i32 %shl, 0
210 define <2 x i1> @shl_nz_bounded_cnt_vec_todo_no_common_bit(<2 x i32> %x, <2 x i32> %y) {
211 ; CHECK-LABEL: @shl_nz_bounded_cnt_vec_todo_no_common_bit(
212 ; CHECK-NEXT: [[CNT:%.*]] = and <2 x i32> [[X:%.*]], <i32 16, i32 32>
213 ; CHECK-NEXT: [[VAL:%.*]] = or <2 x i32> [[Y:%.*]], <i32 16, i32 16>
214 ; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i32> [[VAL]], [[CNT]]
215 ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i32> [[SHL]], zeroinitializer
216 ; CHECK-NEXT: ret <2 x i1> [[R]]
218 %cnt = and <2 x i32> %x, <i32 16, i32 32>
219 %val = or <2 x i32> %y, <i32 16, i32 16>
220 %shl = shl <2 x i32> %val, %cnt
221 %r = icmp eq <2 x i32> %shl, zeroinitializer
225 define i1 @shl_maybe_zero_bounded_cnt_fail(i32 %x, i32 %y) {
226 ; CHECK-LABEL: @shl_maybe_zero_bounded_cnt_fail(
227 ; CHECK-NEXT: [[CNT:%.*]] = and i32 [[X:%.*]], 16
228 ; CHECK-NEXT: [[VAL:%.*]] = or i32 [[Y:%.*]], 65536
229 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[VAL]], [[CNT]]
230 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[SHL]], 0
231 ; CHECK-NEXT: ret i1 [[R]]
233 %cnt = and i32 %x, 16
234 %val = or i32 %y, 65536
235 %shl = shl i32 %val, %cnt
236 %r = icmp eq i32 %shl, 0
240 define i1 @shl_non_zero_nsw(i8 %s, i8 %cnt) {
241 ; CHECK-LABEL: @shl_non_zero_nsw(
242 ; CHECK-NEXT: [[NZ:%.*]] = icmp ne i8 [[S:%.*]], 0
243 ; CHECK-NEXT: call void @llvm.assume(i1 [[NZ]])
244 ; CHECK-NEXT: ret i1 false
246 %nz = icmp ne i8 %s, 0
247 call void @llvm.assume(i1 %nz)
248 %v = shl nsw i8 %s, %cnt
249 %r = icmp eq i8 %v, 0
253 define i1 @shl_maybe_zero_nsw_fail(i8 %s, i8 %cnt) {
254 ; CHECK-LABEL: @shl_maybe_zero_nsw_fail(
255 ; CHECK-NEXT: [[V:%.*]] = shl nsw i8 [[S:%.*]], [[CNT:%.*]]
256 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[V]], 0
257 ; CHECK-NEXT: ret i1 [[R]]
259 %v = shl nsw i8 %s, %cnt
260 %r = icmp eq i8 %v, 0
264 define i1 @shl_out_of_range_is_poison(i32 %v, i32 %c) {
265 ; CHECK-LABEL: @shl_out_of_range_is_poison(
266 ; CHECK-NEXT: ret i1 poison
268 %sval = or i32 %v, 32
269 %shl = shl i32 %c, %sval
270 %z = icmp eq i32 %shl, 0
274 define i1 @lshr_nz_bounded_cnt(i32 %cnt, i32 %y) {
275 ; CHECK-LABEL: @lshr_nz_bounded_cnt(
276 ; CHECK-NEXT: [[CNT_ULT4:%.*]] = icmp ult i32 [[CNT:%.*]], 4
277 ; CHECK-NEXT: call void @llvm.assume(i1 [[CNT_ULT4]])
278 ; CHECK-NEXT: ret i1 false
280 %cnt_ult4 = icmp ult i32 %cnt, 4
281 call void @llvm.assume(i1 %cnt_ult4)
283 %shl = lshr i32 %val, %cnt
284 %r = icmp eq i32 %shl, 0
288 define <2 x i1> @ashr_nz_bounded_cnt_vec(<2 x i32> %x, <2 x i32> %y) {
289 ; CHECK-LABEL: @ashr_nz_bounded_cnt_vec(
290 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
292 %cnt = and <2 x i32> %x, <i32 16, i32 24>
293 %val = or <2 x i32> %y, <i32 402784272, i32 268697601>
294 %shl = ashr <2 x i32> %val, %cnt
295 %r = icmp eq <2 x i32> %shl, zeroinitializer
299 define i1 @lshr_nz_bounded_cnt_fail(i32 %cnt, i32 %y) {
300 ; CHECK-LABEL: @lshr_nz_bounded_cnt_fail(
301 ; CHECK-NEXT: [[CNT_ULT:%.*]] = icmp ult i32 [[CNT:%.*]], 20
302 ; CHECK-NEXT: call void @llvm.assume(i1 [[CNT_ULT]])
303 ; CHECK-NEXT: [[VAL:%.*]] = or i32 [[Y:%.*]], 131072
304 ; CHECK-NEXT: [[SHL:%.*]] = lshr i32 [[VAL]], [[CNT]]
305 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[SHL]], 0
306 ; CHECK-NEXT: ret i1 [[R]]
308 %cnt_ult = icmp ult i32 %cnt, 20
309 call void @llvm.assume(i1 %cnt_ult)
310 %val = or i32 %y, 131072
311 %shl = lshr i32 %val, %cnt
312 %r = icmp eq i32 %shl, 0
316 define <2 x i1> @ashr_nz_bounded_cnt_vec_fail(<2 x i32> %x, <2 x i32> %y) {
317 ; CHECK-LABEL: @ashr_nz_bounded_cnt_vec_fail(
318 ; CHECK-NEXT: [[CNT:%.*]] = and <2 x i32> [[X:%.*]], <i32 24, i32 24>
319 ; CHECK-NEXT: [[VAL:%.*]] = or <2 x i32> [[Y:%.*]], <i32 131088, i32 268697601>
320 ; CHECK-NEXT: [[SHL:%.*]] = ashr <2 x i32> [[VAL]], [[CNT]]
321 ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i32> [[SHL]], zeroinitializer
322 ; CHECK-NEXT: ret <2 x i1> [[R]]
324 %cnt = and <2 x i32> %x, <i32 24, i32 24>
325 %val = or <2 x i32> %y, <i32 131088, i32 268697601>
326 %shl = ashr <2 x i32> %val, %cnt
327 %r = icmp eq <2 x i32> %shl, zeroinitializer
331 define i1 @lshr_nonzero_and_shift_out_zeros(i32 %cnt, i32 %y) {
332 ; CHECK-LABEL: @lshr_nonzero_and_shift_out_zeros(
333 ; CHECK-NEXT: [[CNT_ULT:%.*]] = icmp ult i32 [[CNT:%.*]], 4
334 ; CHECK-NEXT: call void @llvm.assume(i1 [[CNT_ULT]])
335 ; CHECK-NEXT: [[VAL:%.*]] = and i32 [[Y:%.*]], -131072
336 ; CHECK-NEXT: [[VAL_NZ:%.*]] = icmp ne i32 [[VAL]], 0
337 ; CHECK-NEXT: call void @llvm.assume(i1 [[VAL_NZ]])
338 ; CHECK-NEXT: ret i1 false
340 %cnt_ult = icmp ult i32 %cnt, 4
341 call void @llvm.assume(i1 %cnt_ult)
342 %val = and i32 %y, -131072
343 %val_nz = icmp ne i32 %val, 0
344 call void @llvm.assume(i1 %val_nz)
345 %shl = lshr i32 %val, %cnt
346 %r = icmp eq i32 %shl, 0
350 define i1 @ashr_nonzero_and_shift_out_zeros(i32 %ccnt, i32 %y) {
351 ; CHECK-LABEL: @ashr_nonzero_and_shift_out_zeros(
352 ; CHECK-NEXT: [[VAL:%.*]] = and i32 [[Y:%.*]], -131072
353 ; CHECK-NEXT: [[VAL_NZ:%.*]] = icmp ne i32 [[VAL]], 0
354 ; CHECK-NEXT: call void @llvm.assume(i1 [[VAL_NZ]])
355 ; CHECK-NEXT: ret i1 false
357 %cnt = and i32 %ccnt, 7
358 %val = and i32 %y, -131072
359 %val_nz = icmp ne i32 %val, 0
360 call void @llvm.assume(i1 %val_nz)
361 %shl = ashr i32 %val, %cnt
362 %r = icmp eq i32 %shl, 0
366 define i1 @shl_nonzero_and_shift_out_zeros(i32 %ccnt, i32 %y) {
367 ; CHECK-LABEL: @shl_nonzero_and_shift_out_zeros(
368 ; CHECK-NEXT: [[VAL:%.*]] = and i32 [[Y:%.*]], 131071
369 ; CHECK-NEXT: [[VAL_NZ:%.*]] = icmp ne i32 [[VAL]], 0
370 ; CHECK-NEXT: call void @llvm.assume(i1 [[VAL_NZ]])
371 ; CHECK-NEXT: ret i1 false
373 %cnt = and i32 %ccnt, 6
374 %val = and i32 %y, 131071
375 %val_nz = icmp ne i32 %val, 0
376 call void @llvm.assume(i1 %val_nz)
377 %shl = shl i32 %val, %cnt
378 %r = icmp eq i32 %shl, 0
382 define i1 @lshr_nonzero_and_shift_out_zeros_fail(i32 %cnt, i32 %y) {
383 ; CHECK-LABEL: @lshr_nonzero_and_shift_out_zeros_fail(
384 ; CHECK-NEXT: [[CNT_ULT:%.*]] = icmp ult i32 [[CNT:%.*]], 19
385 ; CHECK-NEXT: call void @llvm.assume(i1 [[CNT_ULT]])
386 ; CHECK-NEXT: [[VAL:%.*]] = and i32 [[Y:%.*]], -131072
387 ; CHECK-NEXT: [[VAL_NZ:%.*]] = icmp ne i32 [[VAL]], 0
388 ; CHECK-NEXT: call void @llvm.assume(i1 [[VAL_NZ]])
389 ; CHECK-NEXT: [[SHL:%.*]] = lshr i32 [[VAL]], [[CNT]]
390 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[SHL]], 0
391 ; CHECK-NEXT: ret i1 [[R]]
393 %cnt_ult = icmp ult i32 %cnt, 19
394 call void @llvm.assume(i1 %cnt_ult)
395 %val = and i32 %y, -131072
396 %val_nz = icmp ne i32 %val, 0
397 call void @llvm.assume(i1 %val_nz)
398 %shl = lshr i32 %val, %cnt
399 %r = icmp eq i32 %shl, 0
403 define i1 @ashr_nonzero_and_shift_out_zeros_fail(i32 %ccnt, i32 %y) {
404 ; CHECK-LABEL: @ashr_nonzero_and_shift_out_zeros_fail(
405 ; CHECK-NEXT: [[CNT:%.*]] = and i32 [[CCNT:%.*]], 18
406 ; CHECK-NEXT: [[VAL:%.*]] = and i32 [[Y:%.*]], -131072
407 ; CHECK-NEXT: [[VAL_NZ:%.*]] = icmp ne i32 [[VAL]], 0
408 ; CHECK-NEXT: call void @llvm.assume(i1 [[VAL_NZ]])
409 ; CHECK-NEXT: [[SHL:%.*]] = ashr i32 [[VAL]], [[CNT]]
410 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[SHL]], 0
411 ; CHECK-NEXT: ret i1 [[R]]
413 %cnt = and i32 %ccnt, 18
414 %val = and i32 %y, -131072
415 %val_nz = icmp ne i32 %val, 0
416 call void @llvm.assume(i1 %val_nz)
417 %shl = ashr i32 %val, %cnt
418 %r = icmp eq i32 %shl, 0
422 define i1 @shl_nonzero_and_shift_out_zeros_fail(i32 %ccnt, i32 %y) {
423 ; CHECK-LABEL: @shl_nonzero_and_shift_out_zeros_fail(
424 ; CHECK-NEXT: [[CNT:%.*]] = and i32 [[CCNT:%.*]], 6
425 ; CHECK-NEXT: [[VAL:%.*]] = and i32 [[Y:%.*]], 268435455
426 ; CHECK-NEXT: [[VAL_NZ:%.*]] = icmp ne i32 [[VAL]], 0
427 ; CHECK-NEXT: call void @llvm.assume(i1 [[VAL_NZ]])
428 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[VAL]], [[CNT]]
429 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[SHL]], 0
430 ; CHECK-NEXT: ret i1 [[R]]
432 %cnt = and i32 %ccnt, 6
433 %val = and i32 %y, 268435455
434 %val_nz = icmp ne i32 %val, 0
435 call void @llvm.assume(i1 %val_nz)
436 %shl = shl i32 %val, %cnt
437 %r = icmp eq i32 %shl, 0
441 define i1 @sub_nonzero_ops_ne(i8 %xx, i8 %yy, i8 %z) {
442 ; CHECK-LABEL: @sub_nonzero_ops_ne(
443 ; CHECK-NEXT: ret i1 false
449 %r = icmp eq i8 %exp, 0
453 define i1 @sub_nonzero_ops_ne_fail(i8 %xx, i8 %yy, i8 %z) {
454 ; CHECK-LABEL: @sub_nonzero_ops_ne_fail(
455 ; CHECK-NEXT: [[X:%.*]] = and i8 [[XX:%.*]], -64
456 ; CHECK-NEXT: [[Y:%.*]] = or i8 [[YY:%.*]], 64
457 ; CHECK-NEXT: [[S:%.*]] = sub i8 [[X]], [[Y]]
458 ; CHECK-NEXT: [[EXP:%.*]] = or i8 [[Z:%.*]], [[S]]
459 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[EXP]], 0
460 ; CHECK-NEXT: ret i1 [[R]]
466 %r = icmp eq i8 %exp, 0
470 define i1 @add_nonzero_nuw(i8 %x, i8 %y) {
471 ; CHECK-LABEL: @add_nonzero_nuw(
472 ; CHECK-NEXT: [[X_NZ:%.*]] = icmp ne i8 [[X:%.*]], 0
473 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NZ]])
474 ; CHECK-NEXT: ret i1 false
476 %x_nz = icmp ne i8 %x, 0
477 call void @llvm.assume(i1 %x_nz)
478 %a = add nuw i8 %x, %y
479 %r = icmp eq i8 %a, 0
483 define i1 @add_nonzero_nsw_fail(i8 %x, i8 %y) {
484 ; CHECK-LABEL: @add_nonzero_nsw_fail(
485 ; CHECK-NEXT: [[X_NZ:%.*]] = icmp ne i8 [[X:%.*]], 0
486 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NZ]])
487 ; CHECK-NEXT: [[A:%.*]] = add nsw i8 [[X]], [[Y:%.*]]
488 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[A]], 0
489 ; CHECK-NEXT: ret i1 [[R]]
491 %x_nz = icmp ne i8 %x, 0
492 call void @llvm.assume(i1 %x_nz)
493 %a = add nsw i8 %x, %y
494 %r = icmp eq i8 %a, 0
498 define i1 @udiv_y_le_x(i8 %xx, i8 %yy, i8 %z) {
499 ; CHECK-LABEL: @udiv_y_le_x(
500 ; CHECK-NEXT: ret i1 false
506 %r = icmp eq i8 %o, 0
510 define i1 @udiv_y_le_x_fail(i8 %xx, i8 %yy, i8 %z) {
511 ; CHECK-LABEL: @udiv_y_le_x_fail(
512 ; CHECK-NEXT: [[X:%.*]] = or i8 [[XX:%.*]], 6
513 ; CHECK-NEXT: [[Y:%.*]] = and i8 [[YY:%.*]], 7
514 ; CHECK-NEXT: [[D:%.*]] = udiv i8 [[X]], [[Y]]
515 ; CHECK-NEXT: [[O:%.*]] = or i8 [[D]], [[Z:%.*]]
516 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[O]], 0
517 ; CHECK-NEXT: ret i1 [[R]]
523 %r = icmp eq i8 %o, 0
527 define i1 @fshr_non_zero(i8 %x, i8 %y, i8 %z) {
528 ; CHECK-LABEL: @fshr_non_zero(
529 ; CHECK-NEXT: [[PRED0:%.*]] = icmp ne i8 [[X:%.*]], 0
530 ; CHECK-NEXT: call void @llvm.assume(i1 [[PRED0]])
531 ; CHECK-NEXT: ret i1 false
533 %pred0 = icmp ne i8 %x, 0
534 call void @llvm.assume(i1 %pred0)
535 %v = tail call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 %y)
537 %r = icmp eq i8 %or, 0
541 define i1 @fshr_non_zero_fail(i8 %x, i8 %y, i8 %z, i8 %w) {
542 ; CHECK-LABEL: @fshr_non_zero_fail(
543 ; CHECK-NEXT: [[PRED0:%.*]] = icmp ne i8 [[X:%.*]], 0
544 ; CHECK-NEXT: call void @llvm.assume(i1 [[PRED0]])
545 ; CHECK-NEXT: [[PRED1:%.*]] = icmp ne i8 [[W:%.*]], 0
546 ; CHECK-NEXT: call void @llvm.assume(i1 [[PRED1]])
547 ; CHECK-NEXT: [[V:%.*]] = tail call i8 @llvm.fshr.i8(i8 [[X]], i8 [[W]], i8 [[Y:%.*]])
548 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[V]], [[Z:%.*]]
549 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[OR]], 0
550 ; CHECK-NEXT: ret i1 [[R]]
552 %pred0 = icmp ne i8 %x, 0
553 call void @llvm.assume(i1 %pred0)
554 %pred1 = icmp ne i8 %w, 0
555 call void @llvm.assume(i1 %pred1)
556 %v = tail call i8 @llvm.fshr.i8(i8 %x, i8 %w, i8 %y)
558 %r = icmp eq i8 %or, 0
562 define i1 @fshl_non_zero(i8 %x, i8 %y, i8 %z) {
563 ; CHECK-LABEL: @fshl_non_zero(
564 ; CHECK-NEXT: [[PRED0:%.*]] = icmp ne i8 [[X:%.*]], 0
565 ; CHECK-NEXT: call void @llvm.assume(i1 [[PRED0]])
566 ; CHECK-NEXT: ret i1 false
568 %pred0 = icmp ne i8 %x, 0
569 call void @llvm.assume(i1 %pred0)
570 %v = tail call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 %y)
572 %r = icmp eq i8 %or, 0
576 define i1 @fshl_non_zero_fail(i8 %x, i8 %y, i8 %z, i8 %w) {
577 ; CHECK-LABEL: @fshl_non_zero_fail(
578 ; CHECK-NEXT: [[PRED0:%.*]] = icmp ne i8 [[X:%.*]], 0
579 ; CHECK-NEXT: call void @llvm.assume(i1 [[PRED0]])
580 ; CHECK-NEXT: [[PRED1:%.*]] = icmp ne i8 [[W:%.*]], 0
581 ; CHECK-NEXT: call void @llvm.assume(i1 [[PRED1]])
582 ; CHECK-NEXT: [[V:%.*]] = tail call i8 @llvm.fshl.i8(i8 [[X]], i8 [[W]], i8 [[Y:%.*]])
583 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[V]], [[Z:%.*]]
584 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[OR]], 0
585 ; CHECK-NEXT: ret i1 [[R]]
587 %pred0 = icmp ne i8 %x, 0
588 call void @llvm.assume(i1 %pred0)
589 %pred1 = icmp ne i8 %w, 0
590 call void @llvm.assume(i1 %pred1)
591 %v = tail call i8 @llvm.fshl.i8(i8 %x, i8 %w, i8 %y)
593 %r = icmp eq i8 %or, 0
597 define i1 @bitcast_nonzero(<2 x i8> %xx, i16 %ind) {
598 ; CHECK-LABEL: @bitcast_nonzero(
599 ; CHECK-NEXT: ret i1 false
601 %xa = add nuw nsw <2 x i8> %xx, <i8 1, i8 1>
602 %x = bitcast <2 x i8> %xa to i16
604 %r = icmp eq i16 %z, 0
608 define i1 @bitcast_todo_partial_nonzero_vec_to_int(<2 x i8> %xx, i16 %ind) {
609 ; CHECK-LABEL: @bitcast_todo_partial_nonzero_vec_to_int(
610 ; CHECK-NEXT: [[XA:%.*]] = add nuw nsw <2 x i8> [[XX:%.*]], <i8 1, i8 0>
611 ; CHECK-NEXT: [[X:%.*]] = bitcast <2 x i8> [[XA]] to i16
612 ; CHECK-NEXT: [[Z:%.*]] = or i16 [[X]], [[IND:%.*]]
613 ; CHECK-NEXT: [[R:%.*]] = icmp eq i16 [[Z]], 0
614 ; CHECK-NEXT: ret i1 [[R]]
616 %xa = add nuw nsw <2 x i8> %xx, <i8 1, i8 0>
617 %x = bitcast <2 x i8> %xa to i16
619 %r = icmp eq i16 %z, 0
623 define <2 x i1> @bitcast_fail_nonzero_int_to_vec(i16 %xx, <2 x i8> %ind) {
624 ; CHECK-LABEL: @bitcast_fail_nonzero_int_to_vec(
625 ; CHECK-NEXT: [[XA:%.*]] = add nuw nsw i16 [[XX:%.*]], 1
626 ; CHECK-NEXT: [[X:%.*]] = bitcast i16 [[XA]] to <2 x i8>
627 ; CHECK-NEXT: [[Z:%.*]] = or <2 x i8> [[X]], [[IND:%.*]]
628 ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[Z]], zeroinitializer
629 ; CHECK-NEXT: ret <2 x i1> [[R]]
631 %xa = add nuw nsw i16 %xx, 1
632 %x = bitcast i16 %xa to <2 x i8>
633 %z = or <2 x i8> %x, %ind
634 %r = icmp eq <2 x i8> %z, zeroinitializer
638 define <2 x i1> @bitcast_veci8_to_veci16(<4 x i8> %xx, <2 x i16> %ind) {
639 ; CHECK-LABEL: @bitcast_veci8_to_veci16(
640 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
642 %xa = add nuw nsw <4 x i8> %xx, <i8 1, i8 1, i8 1, i8 1>
643 %x = bitcast <4 x i8> %xa to <2 x i16>
644 %z = or <2 x i16> %x, %ind
645 %r = icmp eq <2 x i16> %z, zeroinitializer
649 define <3 x i1> @bitcast_veci3_to_veci4_fail_not_multiple(<4 x i3> %xx, <3 x i4> %ind) {
650 ; CHECK-LABEL: @bitcast_veci3_to_veci4_fail_not_multiple(
651 ; CHECK-NEXT: [[XA:%.*]] = add nuw nsw <4 x i3> [[XX:%.*]], <i3 1, i3 1, i3 1, i3 1>
652 ; CHECK-NEXT: [[X:%.*]] = bitcast <4 x i3> [[XA]] to <3 x i4>
653 ; CHECK-NEXT: [[Z:%.*]] = or <3 x i4> [[X]], [[IND:%.*]]
654 ; CHECK-NEXT: [[R:%.*]] = icmp eq <3 x i4> [[Z]], zeroinitializer
655 ; CHECK-NEXT: ret <3 x i1> [[R]]
657 %xa = add nuw nsw <4 x i3> %xx, <i3 1, i3 1, i3 1, i3 1>
658 %x = bitcast <4 x i3> %xa to <3 x i4>
659 %z = or <3 x i4> %x, %ind
660 %r = icmp eq <3 x i4> %z, zeroinitializer
664 define <4 x i1> @bitcast_fail_veci16_to_veci8(<2 x i16> %xx, <4 x i8> %ind) {
665 ; CHECK-LABEL: @bitcast_fail_veci16_to_veci8(
666 ; CHECK-NEXT: [[XA:%.*]] = add nuw nsw <2 x i16> [[XX:%.*]], <i16 1, i16 1>
667 ; CHECK-NEXT: [[X:%.*]] = bitcast <2 x i16> [[XA]] to <4 x i8>
668 ; CHECK-NEXT: [[Z:%.*]] = or <4 x i8> [[X]], [[IND:%.*]]
669 ; CHECK-NEXT: [[R:%.*]] = icmp eq <4 x i8> [[Z]], zeroinitializer
670 ; CHECK-NEXT: ret <4 x i1> [[R]]
672 %xa = add nuw nsw <2 x i16> %xx, <i16 1, i16 1>
673 %x = bitcast <2 x i16> %xa to <4 x i8>
674 %z = or <4 x i8> %x, %ind
675 %r = icmp eq <4 x i8> %z, zeroinitializer
679 define i1 @bitcast_nonzero_fail_dont_check_float(float %xx, i32 %ind) {
680 ; CHECK-LABEL: @bitcast_nonzero_fail_dont_check_float(
681 ; CHECK-NEXT: [[XA:%.*]] = call float @llvm.maximum.f32(float [[XX:%.*]], float 1.000000e+00)
682 ; CHECK-NEXT: [[X:%.*]] = bitcast float [[XA]] to i32
683 ; CHECK-NEXT: [[Z:%.*]] = or i32 [[X]], [[IND:%.*]]
684 ; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[Z]], 0
685 ; CHECK-NEXT: ret i1 [[R]]
687 %xa = call float @llvm.maximum.f32(float %xx, float 1.000000e+00)
688 %x = bitcast float %xa to i32
690 %r = icmp eq i32 %z, 0
694 define i1 @ctlz_true_nonzero(i8 %xx, i8 %ind) {
695 ; CHECK-LABEL: @ctlz_true_nonzero(
696 ; CHECK-NEXT: ret i1 false
699 %x = call i8 @llvm.ctlz.i8(i8 %xs, i1 true)
701 %r = icmp eq i8 %z, 0
705 define i1 @ctlz_false_nonzero(i8 %xx, i8 %ind) {
706 ; CHECK-LABEL: @ctlz_false_nonzero(
707 ; CHECK-NEXT: ret i1 false
709 %xa = and i8 %xx, 127
710 %x = call i8 @llvm.ctlz.i8(i8 %xa, i1 true)
712 %r = icmp eq i8 %z, 0
716 define i1 @ctlz_nonzero_fail_maybe_neg(i8 %xx, i8 %ind) {
717 ; CHECK-LABEL: @ctlz_nonzero_fail_maybe_neg(
718 ; CHECK-NEXT: [[XS:%.*]] = ashr i8 [[XX:%.*]], 1
719 ; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.ctlz.i8(i8 [[XS]], i1 true)
720 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
721 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
722 ; CHECK-NEXT: ret i1 [[R]]
725 %x = call i8 @llvm.ctlz.i8(i8 %xs, i1 true)
727 %r = icmp eq i8 %z, 0
731 define i1 @cttz_true_nonzero(i8 %xx, i8 %ind) {
732 ; CHECK-LABEL: @cttz_true_nonzero(
733 ; CHECK-NEXT: ret i1 false
736 %x = call i8 @llvm.cttz.i8(i8 %xs, i1 true)
738 %r = icmp eq i8 %z, 0
742 define i1 @cttz_false_nonzero(i8 %xx, i8 %ind) {
743 ; CHECK-LABEL: @cttz_false_nonzero(
744 ; CHECK-NEXT: ret i1 false
747 %x = call i8 @llvm.cttz.i8(i8 %xa, i1 true)
749 %r = icmp eq i8 %z, 0
753 define i1 @cttz_nonzero_fail_maybe_odd(i8 %xx, i8 %cnt, i8 %ind) {
754 ; CHECK-LABEL: @cttz_nonzero_fail_maybe_odd(
755 ; CHECK-NEXT: [[XS:%.*]] = shl i8 [[XX:%.*]], [[CNT:%.*]]
756 ; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.cttz.i8(i8 [[XS]], i1 true)
757 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
758 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
759 ; CHECK-NEXT: ret i1 [[R]]
761 %xs = shl i8 %xx, %cnt
762 %x = call i8 @llvm.cttz.i8(i8 %xs, i1 true)
764 %r = icmp eq i8 %z, 0
768 define i1 @mul_nonzero_odd(i8 %xx, i8 %y, i8 %ind) {
769 ; CHECK-LABEL: @mul_nonzero_odd(
770 ; CHECK-NEXT: [[Y_NZ:%.*]] = icmp ne i8 [[Y:%.*]], 0
771 ; CHECK-NEXT: call void @llvm.assume(i1 [[Y_NZ]])
772 ; CHECK-NEXT: ret i1 false
775 %y_nz = icmp ne i8 %y, 0
776 call void @llvm.assume(i1 %y_nz)
779 %r = icmp eq i8 %z, 0
783 define i1 @mul_nonzero_odd_fail_y_maybe_zero(i8 %xx, i8 %y, i8 %ind) {
784 ; CHECK-LABEL: @mul_nonzero_odd_fail_y_maybe_zero(
785 ; CHECK-NEXT: [[XO:%.*]] = or i8 [[XX:%.*]], 1
786 ; CHECK-NEXT: [[X:%.*]] = mul i8 [[XO]], [[Y:%.*]]
787 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
788 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
789 ; CHECK-NEXT: ret i1 [[R]]
794 %r = icmp eq i8 %z, 0
798 define i1 @sshl_nonzero(i8 %xx, i8 %y, i8 %ind) {
799 ; CHECK-LABEL: @sshl_nonzero(
800 ; CHECK-NEXT: [[X_NZ:%.*]] = icmp ne i8 [[XX:%.*]], 0
801 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NZ]])
802 ; CHECK-NEXT: ret i1 false
804 %x_nz = icmp ne i8 %xx, 0
805 call void @llvm.assume(i1 %x_nz)
806 %x = call i8 @llvm.sshl.sat.i8(i8 %xx, i8 %y)
808 %r = icmp eq i8 %z, 0
812 define i1 @sshl_nonzero_fail_x_maybe_z(i8 %xx, i8 %y, i8 %ind) {
813 ; CHECK-LABEL: @sshl_nonzero_fail_x_maybe_z(
814 ; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.sshl.sat.i8(i8 [[XX:%.*]], i8 [[Y:%.*]])
815 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
816 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
817 ; CHECK-NEXT: ret i1 [[R]]
819 %x = call i8 @llvm.sshl.sat.i8(i8 %xx, i8 %y)
821 %r = icmp eq i8 %z, 0
825 define i1 @ushl_nonzero(i8 %xx, i8 %y, i8 %ind) {
826 ; CHECK-LABEL: @ushl_nonzero(
827 ; CHECK-NEXT: [[X_NZ:%.*]] = icmp ne i8 [[XX:%.*]], 0
828 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NZ]])
829 ; CHECK-NEXT: ret i1 false
831 %x_nz = icmp ne i8 %xx, 0
832 call void @llvm.assume(i1 %x_nz)
833 %x = call i8 @llvm.ushl.sat.i8(i8 %xx, i8 %y)
835 %r = icmp eq i8 %z, 0
839 define i1 @ushl_nonzero_fail_x_maybe_z(i8 %xx, i8 %y, i8 %ind) {
840 ; CHECK-LABEL: @ushl_nonzero_fail_x_maybe_z(
841 ; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.ushl.sat.i8(i8 [[XX:%.*]], i8 [[Y:%.*]])
842 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
843 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
844 ; CHECK-NEXT: ret i1 [[R]]
846 %x = call i8 @llvm.ushl.sat.i8(i8 %xx, i8 %y)
848 %r = icmp eq i8 %z, 0
852 define i1 @ssub_sat_nonzero(i8 %xx, i8 %yy, i8 %ind) {
853 ; CHECK-LABEL: @ssub_sat_nonzero(
854 ; CHECK-NEXT: ret i1 false
856 %xa = and i8 %xx, 191
858 %x = call i8 @llvm.ssub.sat.i8(i8 %xa, i8 %yo)
860 %r = icmp eq i8 %z, 0
864 define i1 @ssub_sat_nonzero_ne_known_bits_fail_overlap(i8 %xx, i8 %yy, i8 %ind) {
865 ; CHECK-LABEL: @ssub_sat_nonzero_ne_known_bits_fail_overlap(
866 ; CHECK-NEXT: [[XA:%.*]] = and i8 [[XX:%.*]], -64
867 ; CHECK-NEXT: [[YO:%.*]] = or i8 [[YY:%.*]], 64
868 ; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.ssub.sat.i8(i8 [[XA]], i8 [[YO]])
869 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
870 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
871 ; CHECK-NEXT: ret i1 [[R]]
873 %xa = and i8 %xx, 192
875 %x = call i8 @llvm.ssub.sat.i8(i8 %xa, i8 %yo)
877 %r = icmp eq i8 %z, 0
881 define i1 @usub_sat_nonzero(i8 %xx, i8 %yy, i8 %ind) {
882 ; CHECK-LABEL: @usub_sat_nonzero(
883 ; CHECK-NEXT: [[Y_ULT_31:%.*]] = icmp ult i8 [[YY:%.*]], 31
884 ; CHECK-NEXT: call void @llvm.assume(i1 [[Y_ULT_31]])
885 ; CHECK-NEXT: [[XO:%.*]] = or i8 [[XX:%.*]], 34
886 ; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[XO]], i8 [[YY]])
887 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
888 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
889 ; CHECK-NEXT: ret i1 [[R]]
891 %y_ult_31 = icmp ult i8 %yy, 31
892 call void @llvm.assume(i1 %y_ult_31)
894 %x = call i8 @llvm.usub.sat.i8(i8 %xo, i8 %yy)
896 %r = icmp eq i8 %z, 0
900 define i1 @usub_sat_nonzero_fail(i8 %xx, i8 %yy, i8 %ind) {
901 ; CHECK-LABEL: @usub_sat_nonzero_fail(
902 ; CHECK-NEXT: [[XA:%.*]] = and i8 [[XX:%.*]], 16
903 ; CHECK-NEXT: [[YO:%.*]] = or i8 [[YY:%.*]], 7
904 ; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[XA]], i8 [[YO]])
905 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
906 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
907 ; CHECK-NEXT: ret i1 [[R]]
911 %x = call i8 @llvm.usub.sat.i8(i8 %xa, i8 %yo)
913 %r = icmp eq i8 %z, 0
917 define i1 @sadd_sat_nonzero(i8 %xx, i8 %yy, i8 %ind) {
918 ; CHECK-LABEL: @sadd_sat_nonzero(
919 ; CHECK-NEXT: [[X_STRICT_POS:%.*]] = icmp sgt i8 [[XX:%.*]], 0
920 ; CHECK-NEXT: [[Y_POS:%.*]] = icmp sge i8 [[YY:%.*]], 0
921 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_STRICT_POS]])
922 ; CHECK-NEXT: call void @llvm.assume(i1 [[Y_POS]])
923 ; CHECK-NEXT: ret i1 false
925 %x_strict_pos = icmp sgt i8 %xx, 0
926 %y_pos = icmp sge i8 %yy, 0
927 call void @llvm.assume(i1 %x_strict_pos)
928 call void @llvm.assume(i1 %y_pos)
929 %x = call i8 @llvm.sadd.sat.i8(i8 %xx, i8 %yy)
931 %r = icmp eq i8 %z, 0
935 define i1 @sadd_sat_nonzero_fail_maybe_zz(i8 %xx, i8 %yy, i8 %ind) {
936 ; CHECK-LABEL: @sadd_sat_nonzero_fail_maybe_zz(
937 ; CHECK-NEXT: [[X_POS:%.*]] = icmp sge i8 [[XX:%.*]], 0
938 ; CHECK-NEXT: [[Y_POS:%.*]] = icmp sge i8 [[YY:%.*]], 0
939 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_POS]])
940 ; CHECK-NEXT: call void @llvm.assume(i1 [[Y_POS]])
941 ; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.sadd.sat.i8(i8 [[XX]], i8 [[YY]])
942 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
943 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
944 ; CHECK-NEXT: ret i1 [[R]]
946 %x_pos = icmp sge i8 %xx, 0
947 %y_pos = icmp sge i8 %yy, 0
948 call void @llvm.assume(i1 %x_pos)
949 call void @llvm.assume(i1 %y_pos)
950 %x = call i8 @llvm.sadd.sat.i8(i8 %xx, i8 %yy)
952 %r = icmp eq i8 %z, 0
956 define i1 @umax_nonzero(i8 %xx, i8 %yy, i8 %ind) {
957 ; CHECK-LABEL: @umax_nonzero(
958 ; CHECK-NEXT: [[X_NZ:%.*]] = icmp ne i8 [[XX:%.*]], 0
959 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NZ]])
960 ; CHECK-NEXT: ret i1 false
962 %x_nz = icmp ne i8 %xx, 0
963 call void @llvm.assume(i1 %x_nz)
964 %x = call i8 @llvm.umax.i8(i8 %xx, i8 %yy)
966 %r = icmp eq i8 %z, 0
970 define i1 @umax_nonzero_fail_x_maybe_z(i8 %xx, i8 %yy, i8 %ind) {
971 ; CHECK-LABEL: @umax_nonzero_fail_x_maybe_z(
972 ; CHECK-NEXT: [[X_NZ:%.*]] = icmp sge i8 [[XX:%.*]], 0
973 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NZ]])
974 ; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.umax.i8(i8 [[XX]], i8 [[YY:%.*]])
975 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
976 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
977 ; CHECK-NEXT: ret i1 [[R]]
979 %x_nz = icmp sge i8 %xx, 0
980 call void @llvm.assume(i1 %x_nz)
981 %x = call i8 @llvm.umax.i8(i8 %xx, i8 %yy)
983 %r = icmp eq i8 %z, 0
987 define i1 @umin_nonzero(i8 %xx, i8 %yy, i8 %ind) {
988 ; CHECK-LABEL: @umin_nonzero(
989 ; CHECK-NEXT: [[X_NZ:%.*]] = icmp ne i8 [[XX:%.*]], 0
990 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NZ]])
991 ; CHECK-NEXT: [[Y_NZ:%.*]] = icmp ne i8 [[YY:%.*]], 0
992 ; CHECK-NEXT: call void @llvm.assume(i1 [[Y_NZ]])
993 ; CHECK-NEXT: ret i1 false
995 %x_nz = icmp ne i8 %xx, 0
996 call void @llvm.assume(i1 %x_nz)
997 %y_nz = icmp ne i8 %yy, 0
998 call void @llvm.assume(i1 %y_nz)
999 %x = call i8 @llvm.umin.i8(i8 %xx, i8 %yy)
1001 %r = icmp eq i8 %z, 0
1005 define i1 @umin_nonzero_fail_y_maybe_z(i8 %xx, i8 %yy, i8 %ind) {
1006 ; CHECK-LABEL: @umin_nonzero_fail_y_maybe_z(
1007 ; CHECK-NEXT: [[X_NZ:%.*]] = icmp ne i8 [[XX:%.*]], 0
1008 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NZ]])
1009 ; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.umin.i8(i8 [[XX]], i8 [[YY:%.*]])
1010 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
1011 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
1012 ; CHECK-NEXT: ret i1 [[R]]
1014 %x_nz = icmp ne i8 %xx, 0
1015 call void @llvm.assume(i1 %x_nz)
1016 %x = call i8 @llvm.umin.i8(i8 %xx, i8 %yy)
1018 %r = icmp eq i8 %z, 0
1022 define i1 @smin_nonzero(i8 %xx, i8 %yy, i8 %ind) {
1023 ; CHECK-LABEL: @smin_nonzero(
1024 ; CHECK-NEXT: [[X_NZ:%.*]] = icmp ne i8 [[XX:%.*]], 0
1025 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NZ]])
1026 ; CHECK-NEXT: [[Y_NZ:%.*]] = icmp ne i8 [[YY:%.*]], 0
1027 ; CHECK-NEXT: call void @llvm.assume(i1 [[Y_NZ]])
1028 ; CHECK-NEXT: ret i1 false
1030 %x_nz = icmp ne i8 %xx, 0
1031 call void @llvm.assume(i1 %x_nz)
1032 %y_nz = icmp ne i8 %yy, 0
1033 call void @llvm.assume(i1 %y_nz)
1034 %x = call i8 @llvm.umin.i8(i8 %xx, i8 %yy)
1036 %r = icmp eq i8 %z, 0
1040 define i1 @smin_nonzero_neg_arg(i8 %xx, i8 %yy, i8 %ind) {
1041 ; CHECK-LABEL: @smin_nonzero_neg_arg(
1042 ; CHECK-NEXT: [[X_NEG:%.*]] = icmp slt i8 [[XX:%.*]], 0
1043 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NEG]])
1044 ; CHECK-NEXT: ret i1 false
1046 %x_neg = icmp slt i8 %xx, 0
1047 call void @llvm.assume(i1 %x_neg)
1048 %x = call i8 @llvm.smin.i8(i8 %xx, i8 %yy)
1050 %r = icmp eq i8 %z, 0
1054 define i1 @smin_nonzero_fail_y_maybe_z(i8 %xx, i8 %yy, i8 %ind) {
1055 ; CHECK-LABEL: @smin_nonzero_fail_y_maybe_z(
1056 ; CHECK-NEXT: [[X_NZ:%.*]] = icmp sle i8 [[XX:%.*]], 0
1057 ; CHECK-NEXT: call void @llvm.assume(i1 [[X_NZ]])
1058 ; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.smin.i8(i8 [[XX]], i8 [[YY:%.*]])
1059 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
1060 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
1061 ; CHECK-NEXT: ret i1 [[R]]
1063 %x_nz = icmp sle i8 %xx, 0
1064 call void @llvm.assume(i1 %x_nz)
1065 %x = call i8 @llvm.smin.i8(i8 %xx, i8 %yy)
1067 %r = icmp eq i8 %z, 0
1071 define i1 @smax_nonzero_pos_arg(i8 %xx, i8 %yy, i8 %ind) {
1072 ; CHECK-LABEL: @smax_nonzero_pos_arg(
1073 ; CHECK-NEXT: ret i1 false
1075 %ya = and i8 %yy, 127
1077 %x = call i8 @llvm.smax.i8(i8 %xx, i8 %yo)
1079 %r = icmp eq i8 %z, 0
1083 define i1 @smax_nonzero_pos_arg_fail_nonstrict_pos(i8 %xx, i8 %yy, i8 %ind) {
1084 ; CHECK-LABEL: @smax_nonzero_pos_arg_fail_nonstrict_pos(
1085 ; CHECK-NEXT: [[Y_POS:%.*]] = icmp sge i8 [[YY:%.*]], 0
1086 ; CHECK-NEXT: call void @llvm.assume(i1 [[Y_POS]])
1087 ; CHECK-NEXT: [[X:%.*]] = call i8 @llvm.smax.i8(i8 [[XX:%.*]], i8 [[YY]])
1088 ; CHECK-NEXT: [[Z:%.*]] = or i8 [[X]], [[IND:%.*]]
1089 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[Z]], 0
1090 ; CHECK-NEXT: ret i1 [[R]]
1092 %y_pos = icmp sge i8 %yy, 0
1093 call void @llvm.assume(i1 %y_pos)
1094 %x = call i8 @llvm.smax.i8(i8 %xx, i8 %yy)
1096 %r = icmp eq i8 %z, 0
1100 define i1 @mul_nonzero_contains_nonzero_mul(i8 %x, i8 %y) {
1101 ; CHECK-LABEL: @mul_nonzero_contains_nonzero_mul(
1102 ; CHECK-NEXT: ret i1 true
1106 %xy = mul i8 %xx, %yy
1107 %nz = icmp ne i8 %xy, 0
1111 define i1 @src_mul_maybe_zero_no_nonzero_mul(i8 %x, i8 %y) {
1112 ; CHECK-LABEL: @src_mul_maybe_zero_no_nonzero_mul(
1113 ; CHECK-NEXT: [[XX:%.*]] = or i8 [[X:%.*]], 96
1114 ; CHECK-NEXT: [[YY:%.*]] = or i8 [[Y:%.*]], 8
1115 ; CHECK-NEXT: [[XY:%.*]] = mul i8 [[XX]], [[YY]]
1116 ; CHECK-NEXT: [[NZ:%.*]] = icmp ne i8 [[XY]], 0
1117 ; CHECK-NEXT: ret i1 [[NZ]]
1121 %xy = mul i8 %xx, %yy
1122 %nz = icmp ne i8 %xy, 0
1126 define i1 @sdiv_known_non_zero(i8 %x, i8 %y) {
1127 ; CHECK-LABEL: @sdiv_known_non_zero(
1128 ; CHECK-NEXT: ret i1 true
1130 %xx0 = or i8 %x, 135
1131 %xx = and i8 %xx0, -2
1132 %xy = sdiv i8 %xx, -2
1133 %nz = icmp ne i8 %xy, 0
1137 define i1 @sdiv_known_non_zero2(i8 %x, i8 %y) {
1138 ; CHECK-LABEL: @sdiv_known_non_zero2(
1139 ; CHECK-NEXT: ret i1 true
1142 %xx = and i8 %xx0, -4
1144 %xy = sdiv i8 %xx, %yy
1145 %nz = icmp ne i8 %xy, 0
1149 define i1 @sdiv_known_non_zero_fail(i8 %x, i8 %y) {
1150 ; CHECK-LABEL: @sdiv_known_non_zero_fail(
1151 ; CHECK-NEXT: [[XX:%.*]] = or i8 [[X:%.*]], 15
1152 ; CHECK-NEXT: [[YY:%.*]] = and i8 [[Y:%.*]], 3
1153 ; CHECK-NEXT: [[XY:%.*]] = sdiv i8 [[XX]], [[YY]]
1154 ; CHECK-NEXT: [[NZ:%.*]] = icmp ne i8 [[XY]], 0
1155 ; CHECK-NEXT: ret i1 [[NZ]]
1159 %xy = sdiv i8 %xx, %yy
1160 %nz = icmp ne i8 %xy, 0
1164 define <2 x i1> @cmp_excludes_zero_with_nonsplat_vec(<2 x i8> %a, <2 x i8> %b) {
1165 ; CHECK-LABEL: @cmp_excludes_zero_with_nonsplat_vec(
1166 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
1168 %c = icmp sge <2 x i8> %a, <i8 1, i8 4>
1169 %s = select <2 x i1> %c, <2 x i8> %a, <2 x i8> <i8 4, i8 5>
1170 %and = or <2 x i8> %s, %b
1171 %r = icmp eq <2 x i8> %and, zeroinitializer
1175 define <2 x i1> @cmp_excludes_zero_with_nonsplat_vec_wundef(<2 x i8> %a, <2 x i8> %b) {
1176 ; CHECK-LABEL: @cmp_excludes_zero_with_nonsplat_vec_wundef(
1177 ; CHECK-NEXT: [[C:%.*]] = icmp sge <2 x i8> [[A:%.*]], <i8 1, i8 undef>
1178 ; CHECK-NEXT: [[S:%.*]] = select <2 x i1> [[C]], <2 x i8> [[A]], <2 x i8> <i8 4, i8 5>
1179 ; CHECK-NEXT: [[AND:%.*]] = or <2 x i8> [[S]], [[B:%.*]]
1180 ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[AND]], zeroinitializer
1181 ; CHECK-NEXT: ret <2 x i1> [[R]]
1183 %c = icmp sge <2 x i8> %a, <i8 1, i8 undef>
1184 %s = select <2 x i1> %c, <2 x i8> %a, <2 x i8> <i8 4, i8 5>
1185 %and = or <2 x i8> %s, %b
1186 %r = icmp eq <2 x i8> %and, zeroinitializer
1190 define <2 x i1> @cmp_excludes_zero_with_nonsplat_vec_wpoison(<2 x i8> %a, <2 x i8> %b) {
1191 ; CHECK-LABEL: @cmp_excludes_zero_with_nonsplat_vec_wpoison(
1192 ; CHECK-NEXT: [[C:%.*]] = icmp sge <2 x i8> [[A:%.*]], <i8 1, i8 poison>
1193 ; CHECK-NEXT: [[S:%.*]] = select <2 x i1> [[C]], <2 x i8> [[A]], <2 x i8> <i8 4, i8 5>
1194 ; CHECK-NEXT: [[AND:%.*]] = or <2 x i8> [[S]], [[B:%.*]]
1195 ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[AND]], zeroinitializer
1196 ; CHECK-NEXT: ret <2 x i1> [[R]]
1198 %c = icmp sge <2 x i8> %a, <i8 1, i8 poison>
1199 %s = select <2 x i1> %c, <2 x i8> %a, <2 x i8> <i8 4, i8 5>
1200 %and = or <2 x i8> %s, %b
1201 %r = icmp eq <2 x i8> %and, zeroinitializer
1206 define <2 x i1> @cmp_excludes_zero_with_nonsplat_vec_fail(<2 x i8> %a, <2 x i8> %b) {
1207 ; CHECK-LABEL: @cmp_excludes_zero_with_nonsplat_vec_fail(
1208 ; CHECK-NEXT: [[C:%.*]] = icmp sge <2 x i8> [[A:%.*]], <i8 0, i8 4>
1209 ; CHECK-NEXT: [[S:%.*]] = select <2 x i1> [[C]], <2 x i8> [[A]], <2 x i8> <i8 4, i8 5>
1210 ; CHECK-NEXT: [[AND:%.*]] = or <2 x i8> [[S]], [[B:%.*]]
1211 ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[AND]], zeroinitializer
1212 ; CHECK-NEXT: ret <2 x i1> [[R]]
1214 %c = icmp sge <2 x i8> %a, <i8 0, i8 4>
1215 %s = select <2 x i1> %c, <2 x i8> %a, <2 x i8> <i8 4, i8 5>
1216 %and = or <2 x i8> %s, %b
1217 %r = icmp eq <2 x i8> %and, zeroinitializer
1221 define i1 @sub_via_non_eq(i8 %x, i8 %y) {
1222 ; CHECK-LABEL: @sub_via_non_eq(
1223 ; CHECK-NEXT: [[NE:%.*]] = icmp ne i8 [[X:%.*]], 0
1224 ; CHECK-NEXT: call void @llvm.assume(i1 [[NE]])
1225 ; CHECK-NEXT: ret i1 false
1227 %ne = icmp ne i8 %x, 0
1228 call void @llvm.assume(i1 %ne)
1229 %shl = shl nuw i8 %x, 3
1230 %sub = sub i8 %x, %shl
1231 %cmp = icmp eq i8 %sub, 0
1235 ; Test mismatch of ptrtoints type and pointer size
1236 define i1 @recursiveGEP_orcmp_truncPtr(ptr %val1, i32 %val2) {
1237 ; CHECK-LABEL: @recursiveGEP_orcmp_truncPtr(
1238 ; CHECK-NEXT: entry:
1239 ; CHECK-NEXT: br label [[WHILE_COND_I:%.*]]
1240 ; CHECK: while.cond.i:
1241 ; CHECK-NEXT: [[A_PN_I:%.*]] = phi ptr [ [[TEST_0_I:%.*]], [[WHILE_COND_I]] ], [ [[VAL1:%.*]], [[ENTRY:%.*]] ]
1242 ; CHECK-NEXT: [[TEST_0_I]] = getelementptr inbounds i8, ptr [[A_PN_I]], i64 1
1243 ; CHECK-NEXT: [[TMP0:%.*]] = load i8, ptr [[TEST_0_I]], align 2
1244 ; CHECK-NEXT: [[CMP3_NOT_I:%.*]] = icmp eq i8 [[TMP0]], 0
1245 ; CHECK-NEXT: br i1 [[CMP3_NOT_I]], label [[WHILE_END_I:%.*]], label [[WHILE_COND_I]]
1246 ; CHECK: while.end.i:
1247 ; CHECK-NEXT: [[SUB_PTR_LHS_CAST_I:%.*]] = ptrtoint ptr [[TEST_0_I]] to i32
1248 ; CHECK-NEXT: [[SUB_PTR_RHS_CAST_I:%.*]] = ptrtoint ptr [[VAL1]] to i32
1249 ; CHECK-NEXT: [[SUB_PTR_SUB_I:%.*]] = sub i32 [[SUB_PTR_LHS_CAST_I]], [[SUB_PTR_RHS_CAST_I]]
1250 ; CHECK-NEXT: [[ORVAL:%.*]] = or i32 [[VAL2:%.*]], [[SUB_PTR_SUB_I]]
1251 ; CHECK-NEXT: [[BOOL:%.*]] = icmp eq i32 [[ORVAL]], 0
1252 ; CHECK-NEXT: ret i1 [[BOOL]]
1255 br label %while.cond.i
1258 %a.pn.i = phi ptr [ %test.0.i, %while.cond.i ], [ %val1, %entry ]
1259 %test.0.i = getelementptr inbounds i8, ptr %a.pn.i, i64 1
1260 %0 = load i8, ptr %test.0.i, align 2
1261 %cmp3.not.i = icmp eq i8 %0, 0
1262 br i1 %cmp3.not.i, label %while.end.i, label %while.cond.i
1265 %sub.ptr.lhs.cast.i = ptrtoint ptr %test.0.i to i32
1266 %sub.ptr.rhs.cast.i = ptrtoint ptr %val1 to i32
1267 %sub.ptr.sub.i = sub i32 %sub.ptr.lhs.cast.i, %sub.ptr.rhs.cast.i
1268 %orval = or i32 %val2, %sub.ptr.sub.i
1269 %bool = icmp eq i32 %orval, 0