1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 ; This is a specialization of generic folds for min/max values targeted to the
6 ; Related tests for non-pointer types should be included in another file.
8 ; There are 6 basic patterns (or 3 with DeMorganized equivalent) with
9 ; 2 (commute logic op) *
10 ; 2 (swap compare operands) *
11 ; variations for a total of 24 tests.
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15 ; (X == null) && (X > Y) --> false
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 define i1 @ugt_and_min(ptr %x, ptr %y) {
20 ; CHECK-LABEL: @ugt_and_min(
21 ; CHECK-NEXT: ret i1 false
23 %cmp = icmp ugt ptr %x, %y
24 %cmpeq = icmp eq ptr %x, null
25 %r = and i1 %cmp, %cmpeq
29 define i1 @ugt_and_min_logical(ptr %x, ptr %y) {
30 ; CHECK-LABEL: @ugt_and_min_logical(
31 ; CHECK-NEXT: ret i1 false
33 %cmp = icmp ugt ptr %x, %y
34 %cmpeq = icmp eq ptr %x, null
35 %r = select i1 %cmp, i1 %cmpeq, i1 false
39 define i1 @ugt_and_min_commute(ptr %x, ptr %y) {
40 ; CHECK-LABEL: @ugt_and_min_commute(
41 ; CHECK-NEXT: ret i1 false
43 %cmp = icmp ugt ptr %x, %y
44 %cmpeq = icmp eq ptr %x, null
45 %r = and i1 %cmpeq, %cmp
49 define i1 @ugt_and_min_commute_logical(ptr %x, ptr %y) {
50 ; CHECK-LABEL: @ugt_and_min_commute_logical(
51 ; CHECK-NEXT: ret i1 false
53 %cmp = icmp ugt ptr %x, %y
54 %cmpeq = icmp eq ptr %x, null
55 %r = select i1 %cmpeq, i1 %cmp, i1 false
59 define i1 @ugt_swap_and_min(ptr %x, ptr %y) {
60 ; CHECK-LABEL: @ugt_swap_and_min(
61 ; CHECK-NEXT: ret i1 false
63 %cmp = icmp ult ptr %y, %x
64 %cmpeq = icmp eq ptr %x, null
65 %r = and i1 %cmp, %cmpeq
69 define i1 @ugt_swap_and_min_logical(ptr %x, ptr %y) {
70 ; CHECK-LABEL: @ugt_swap_and_min_logical(
71 ; CHECK-NEXT: ret i1 false
73 %cmp = icmp ult ptr %y, %x
74 %cmpeq = icmp eq ptr %x, null
75 %r = select i1 %cmp, i1 %cmpeq, i1 false
79 define i1 @ugt_swap_and_min_commute(ptr %x, ptr %y) {
80 ; CHECK-LABEL: @ugt_swap_and_min_commute(
81 ; CHECK-NEXT: ret i1 false
83 %cmp = icmp ult ptr %y, %x
84 %cmpeq = icmp eq ptr %x, null
85 %r = and i1 %cmpeq, %cmp
89 define i1 @ugt_swap_and_min_commute_logical(ptr %x, ptr %y) {
90 ; CHECK-LABEL: @ugt_swap_and_min_commute_logical(
91 ; CHECK-NEXT: ret i1 false
93 %cmp = icmp ult ptr %y, %x
94 %cmpeq = icmp eq ptr %x, null
95 %r = select i1 %cmpeq, i1 %cmp, i1 false
99 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
101 ; (X != null) || (X <= Y) --> true
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
105 define i1 @ule_or_not_min(ptr %x, ptr %y) {
106 ; CHECK-LABEL: @ule_or_not_min(
107 ; CHECK-NEXT: ret i1 true
109 %cmp = icmp ule ptr %x, %y
110 %cmpeq = icmp ne ptr %x, null
111 %r = or i1 %cmp, %cmpeq
115 define i1 @ule_or_not_min_logical(ptr %x, ptr %y) {
116 ; CHECK-LABEL: @ule_or_not_min_logical(
117 ; CHECK-NEXT: ret i1 true
119 %cmp = icmp ule ptr %x, %y
120 %cmpeq = icmp ne ptr %x, null
121 %r = select i1 %cmp, i1 true, i1 %cmpeq
125 define i1 @ule_or_not_min_commute(ptr %x, ptr %y) {
126 ; CHECK-LABEL: @ule_or_not_min_commute(
127 ; CHECK-NEXT: ret i1 true
129 %cmp = icmp ule ptr %x, %y
130 %cmpeq = icmp ne ptr %x, null
131 %r = or i1 %cmpeq, %cmp
135 define i1 @ule_or_not_min_commute_logical(ptr %x, ptr %y) {
136 ; CHECK-LABEL: @ule_or_not_min_commute_logical(
137 ; CHECK-NEXT: ret i1 true
139 %cmp = icmp ule ptr %x, %y
140 %cmpeq = icmp ne ptr %x, null
141 %r = select i1 %cmpeq, i1 true, i1 %cmp
145 define i1 @ule_swap_or_not_min(ptr %x, ptr %y) {
146 ; CHECK-LABEL: @ule_swap_or_not_min(
147 ; CHECK-NEXT: ret i1 true
149 %cmp = icmp uge ptr %y, %x
150 %cmpeq = icmp ne ptr %x, null
151 %r = or i1 %cmp, %cmpeq
155 define i1 @ule_swap_or_not_min_logical(ptr %x, ptr %y) {
156 ; CHECK-LABEL: @ule_swap_or_not_min_logical(
157 ; CHECK-NEXT: ret i1 true
159 %cmp = icmp uge ptr %y, %x
160 %cmpeq = icmp ne ptr %x, null
161 %r = select i1 %cmp, i1 true, i1 %cmpeq
165 define i1 @ule_swap_or_not_min_commute(ptr %x, ptr %y) {
166 ; CHECK-LABEL: @ule_swap_or_not_min_commute(
167 ; CHECK-NEXT: ret i1 true
169 %cmp = icmp uge ptr %y, %x
170 %cmpeq = icmp ne ptr %x, null
171 %r = or i1 %cmpeq, %cmp
175 define i1 @ule_swap_or_not_min_commute_logical(ptr %x, ptr %y) {
176 ; CHECK-LABEL: @ule_swap_or_not_min_commute_logical(
177 ; CHECK-NEXT: ret i1 true
179 %cmp = icmp uge ptr %y, %x
180 %cmpeq = icmp ne ptr %x, null
181 %r = select i1 %cmpeq, i1 true, i1 %cmp
185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 ; (X == null) && (X <= Y) --> X == null
189 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
191 define i1 @ule_and_min(ptr %x, ptr %y) {
192 ; CHECK-LABEL: @ule_and_min(
193 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
194 ; CHECK-NEXT: ret i1 [[CMPEQ]]
196 %cmp = icmp ule ptr %x, %y
197 %cmpeq = icmp eq ptr %x, null
198 %r = and i1 %cmp, %cmpeq
202 define i1 @ule_and_min_logical(ptr %x, ptr %y) {
203 ; CHECK-LABEL: @ule_and_min_logical(
204 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
205 ; CHECK-NEXT: ret i1 [[CMPEQ]]
207 %cmp = icmp ule ptr %x, %y
208 %cmpeq = icmp eq ptr %x, null
209 %r = select i1 %cmp, i1 %cmpeq, i1 false
213 define i1 @ule_and_min_commute(ptr %x, ptr %y) {
214 ; CHECK-LABEL: @ule_and_min_commute(
215 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
216 ; CHECK-NEXT: ret i1 [[CMPEQ]]
218 %cmp = icmp ule ptr %x, %y
219 %cmpeq = icmp eq ptr %x, null
220 %r = and i1 %cmpeq, %cmp
224 define i1 @ule_and_min_commute_logical(ptr %x, ptr %y) {
225 ; CHECK-LABEL: @ule_and_min_commute_logical(
226 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
227 ; CHECK-NEXT: ret i1 [[CMPEQ]]
229 %cmp = icmp ule ptr %x, %y
230 %cmpeq = icmp eq ptr %x, null
231 %r = select i1 %cmpeq, i1 %cmp, i1 false
235 define i1 @ule_swap_and_min(ptr %x, ptr %y) {
236 ; CHECK-LABEL: @ule_swap_and_min(
237 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
238 ; CHECK-NEXT: ret i1 [[CMPEQ]]
240 %cmp = icmp uge ptr %y, %x
241 %cmpeq = icmp eq ptr %x, null
242 %r = and i1 %cmp, %cmpeq
246 define i1 @ule_swap_and_min_logical(ptr %x, ptr %y) {
247 ; CHECK-LABEL: @ule_swap_and_min_logical(
248 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
249 ; CHECK-NEXT: ret i1 [[CMPEQ]]
251 %cmp = icmp uge ptr %y, %x
252 %cmpeq = icmp eq ptr %x, null
253 %r = select i1 %cmp, i1 %cmpeq, i1 false
257 define i1 @ule_swap_and_min_commute(ptr %x, ptr %y) {
258 ; CHECK-LABEL: @ule_swap_and_min_commute(
259 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
260 ; CHECK-NEXT: ret i1 [[CMPEQ]]
262 %cmp = icmp uge ptr %y, %x
263 %cmpeq = icmp eq ptr %x, null
264 %r = and i1 %cmpeq, %cmp
268 define i1 @ule_swap_and_min_commute_logical(ptr %x, ptr %y) {
269 ; CHECK-LABEL: @ule_swap_and_min_commute_logical(
270 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
271 ; CHECK-NEXT: ret i1 [[CMPEQ]]
273 %cmp = icmp uge ptr %y, %x
274 %cmpeq = icmp eq ptr %x, null
275 %r = select i1 %cmpeq, i1 %cmp, i1 false
279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
281 ; (X == null) || (X <= Y) --> X <= Y
283 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
285 define i1 @ule_or_min(ptr %x, ptr %y) {
286 ; CHECK-LABEL: @ule_or_min(
287 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule ptr [[X:%.*]], [[Y:%.*]]
288 ; CHECK-NEXT: ret i1 [[CMP]]
290 %cmp = icmp ule ptr %x, %y
291 %cmpeq = icmp eq ptr %x, null
292 %r = or i1 %cmp, %cmpeq
296 define i1 @ule_or_min_logical(ptr %x, ptr %y) {
297 ; CHECK-LABEL: @ule_or_min_logical(
298 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule ptr [[X:%.*]], [[Y:%.*]]
299 ; CHECK-NEXT: ret i1 [[CMP]]
301 %cmp = icmp ule ptr %x, %y
302 %cmpeq = icmp eq ptr %x, null
303 %r = select i1 %cmp, i1 true, i1 %cmpeq
307 define i1 @ule_or_min_commute(ptr %x, ptr %y) {
308 ; CHECK-LABEL: @ule_or_min_commute(
309 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule ptr [[X:%.*]], [[Y:%.*]]
310 ; CHECK-NEXT: ret i1 [[CMP]]
312 %cmp = icmp ule ptr %x, %y
313 %cmpeq = icmp eq ptr %x, null
314 %r = or i1 %cmpeq, %cmp
318 define i1 @ule_or_min_commute_logical(ptr %x, ptr %y) {
319 ; CHECK-LABEL: @ule_or_min_commute_logical(
320 ; CHECK-NEXT: [[CMP:%.*]] = icmp ule ptr [[X:%.*]], [[Y:%.*]]
321 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X]], null
322 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMPEQ]], i1 true, i1 [[CMP]]
323 ; CHECK-NEXT: ret i1 [[R]]
325 %cmp = icmp ule ptr %x, %y
326 %cmpeq = icmp eq ptr %x, null
327 %r = select i1 %cmpeq, i1 true, i1 %cmp
331 define i1 @ule_swap_or_min(ptr %x, ptr %y) {
332 ; CHECK-LABEL: @ule_swap_or_min(
333 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge ptr [[Y:%.*]], [[X:%.*]]
334 ; CHECK-NEXT: ret i1 [[CMP]]
336 %cmp = icmp uge ptr %y, %x
337 %cmpeq = icmp eq ptr %x, null
338 %r = or i1 %cmp, %cmpeq
342 define i1 @ule_swap_or_min_logical(ptr %x, ptr %y) {
343 ; CHECK-LABEL: @ule_swap_or_min_logical(
344 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge ptr [[Y:%.*]], [[X:%.*]]
345 ; CHECK-NEXT: ret i1 [[CMP]]
347 %cmp = icmp uge ptr %y, %x
348 %cmpeq = icmp eq ptr %x, null
349 %r = select i1 %cmp, i1 true, i1 %cmpeq
353 define i1 @ule_swap_or_min_commute(ptr %x, ptr %y) {
354 ; CHECK-LABEL: @ule_swap_or_min_commute(
355 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge ptr [[Y:%.*]], [[X:%.*]]
356 ; CHECK-NEXT: ret i1 [[CMP]]
358 %cmp = icmp uge ptr %y, %x
359 %cmpeq = icmp eq ptr %x, null
360 %r = or i1 %cmpeq, %cmp
364 define i1 @ule_swap_or_min_commute_logical(ptr %x, ptr %y) {
365 ; CHECK-LABEL: @ule_swap_or_min_commute_logical(
366 ; CHECK-NEXT: [[CMP:%.*]] = icmp uge ptr [[Y:%.*]], [[X:%.*]]
367 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X]], null
368 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMPEQ]], i1 true, i1 [[CMP]]
369 ; CHECK-NEXT: ret i1 [[R]]
371 %cmp = icmp uge ptr %y, %x
372 %cmpeq = icmp eq ptr %x, null
373 %r = select i1 %cmpeq, i1 true, i1 %cmp
377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
379 ; (X != null) && (X > Y) --> X > Y
381 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
383 define i1 @ugt_and_not_min(ptr %x, ptr %y) {
384 ; CHECK-LABEL: @ugt_and_not_min(
385 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt ptr [[X:%.*]], [[Y:%.*]]
386 ; CHECK-NEXT: ret i1 [[CMP]]
388 %cmp = icmp ugt ptr %x, %y
389 %cmpeq = icmp ne ptr %x, null
390 %r = and i1 %cmp, %cmpeq
394 define i1 @ugt_and_not_min_logical(ptr %x, ptr %y) {
395 ; CHECK-LABEL: @ugt_and_not_min_logical(
396 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt ptr [[X:%.*]], [[Y:%.*]]
397 ; CHECK-NEXT: ret i1 [[CMP]]
399 %cmp = icmp ugt ptr %x, %y
400 %cmpeq = icmp ne ptr %x, null
401 %r = select i1 %cmp, i1 %cmpeq, i1 false
405 define i1 @ugt_and_not_min_commute(ptr %x, ptr %y) {
406 ; CHECK-LABEL: @ugt_and_not_min_commute(
407 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt ptr [[X:%.*]], [[Y:%.*]]
408 ; CHECK-NEXT: ret i1 [[CMP]]
410 %cmp = icmp ugt ptr %x, %y
411 %cmpeq = icmp ne ptr %x, null
412 %r = and i1 %cmpeq, %cmp
416 define i1 @ugt_and_not_min_commute_logical(ptr %x, ptr %y) {
417 ; CHECK-LABEL: @ugt_and_not_min_commute_logical(
418 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt ptr [[X:%.*]], [[Y:%.*]]
419 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X]], null
420 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMPEQ]], i1 [[CMP]], i1 false
421 ; CHECK-NEXT: ret i1 [[R]]
423 %cmp = icmp ugt ptr %x, %y
424 %cmpeq = icmp ne ptr %x, null
425 %r = select i1 %cmpeq, i1 %cmp, i1 false
429 define i1 @ugt_swap_and_not_min(ptr %x, ptr %y) {
430 ; CHECK-LABEL: @ugt_swap_and_not_min(
431 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult ptr [[Y:%.*]], [[X:%.*]]
432 ; CHECK-NEXT: ret i1 [[CMP]]
434 %cmp = icmp ult ptr %y, %x
435 %cmpeq = icmp ne ptr %x, null
436 %r = and i1 %cmp, %cmpeq
440 define i1 @ugt_swap_and_not_min_logical(ptr %x, ptr %y) {
441 ; CHECK-LABEL: @ugt_swap_and_not_min_logical(
442 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult ptr [[Y:%.*]], [[X:%.*]]
443 ; CHECK-NEXT: ret i1 [[CMP]]
445 %cmp = icmp ult ptr %y, %x
446 %cmpeq = icmp ne ptr %x, null
447 %r = select i1 %cmp, i1 %cmpeq, i1 false
451 define i1 @ugt_swap_and_not_min_commute(ptr %x, ptr %y) {
452 ; CHECK-LABEL: @ugt_swap_and_not_min_commute(
453 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult ptr [[Y:%.*]], [[X:%.*]]
454 ; CHECK-NEXT: ret i1 [[CMP]]
456 %cmp = icmp ult ptr %y, %x
457 %cmpeq = icmp ne ptr %x, null
458 %r = and i1 %cmpeq, %cmp
462 define i1 @ugt_swap_and_not_min_commute_logical(ptr %x, ptr %y) {
463 ; CHECK-LABEL: @ugt_swap_and_not_min_commute_logical(
464 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult ptr [[Y:%.*]], [[X:%.*]]
465 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X]], null
466 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMPEQ]], i1 [[CMP]], i1 false
467 ; CHECK-NEXT: ret i1 [[R]]
469 %cmp = icmp ult ptr %y, %x
470 %cmpeq = icmp ne ptr %x, null
471 %r = select i1 %cmpeq, i1 %cmp, i1 false
475 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
477 ; (X != null) || (X > Y) --> X != null
479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
481 define i1 @ugt_or_not_min(ptr %x, ptr %y) {
482 ; CHECK-LABEL: @ugt_or_not_min(
483 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
484 ; CHECK-NEXT: ret i1 [[CMPEQ]]
486 %cmp = icmp ugt ptr %x, %y
487 %cmpeq = icmp ne ptr %x, null
488 %r = or i1 %cmp, %cmpeq
492 define i1 @ugt_or_not_min_logical(ptr %x, ptr %y) {
493 ; CHECK-LABEL: @ugt_or_not_min_logical(
494 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
495 ; CHECK-NEXT: ret i1 [[CMPEQ]]
497 %cmp = icmp ugt ptr %x, %y
498 %cmpeq = icmp ne ptr %x, null
499 %r = select i1 %cmp, i1 true, i1 %cmpeq
503 define i1 @ugt_or_not_min_commute(ptr %x, ptr %y) {
504 ; CHECK-LABEL: @ugt_or_not_min_commute(
505 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
506 ; CHECK-NEXT: ret i1 [[CMPEQ]]
508 %cmp = icmp ugt ptr %x, %y
509 %cmpeq = icmp ne ptr %x, null
510 %r = or i1 %cmpeq, %cmp
514 define i1 @ugt_or_not_min_commute_logical(ptr %x, ptr %y) {
515 ; CHECK-LABEL: @ugt_or_not_min_commute_logical(
516 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
517 ; CHECK-NEXT: ret i1 [[CMPEQ]]
519 %cmp = icmp ugt ptr %x, %y
520 %cmpeq = icmp ne ptr %x, null
521 %r = select i1 %cmpeq, i1 true, i1 %cmp
525 define i1 @ugt_swap_or_not_min(ptr %x, ptr %y) {
526 ; CHECK-LABEL: @ugt_swap_or_not_min(
527 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
528 ; CHECK-NEXT: ret i1 [[CMPEQ]]
530 %cmp = icmp ult ptr %y, %x
531 %cmpeq = icmp ne ptr %x, null
532 %r = or i1 %cmp, %cmpeq
536 define i1 @ugt_swap_or_not_min_logical(ptr %x, ptr %y) {
537 ; CHECK-LABEL: @ugt_swap_or_not_min_logical(
538 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
539 ; CHECK-NEXT: ret i1 [[CMPEQ]]
541 %cmp = icmp ult ptr %y, %x
542 %cmpeq = icmp ne ptr %x, null
543 %r = select i1 %cmp, i1 true, i1 %cmpeq
547 define i1 @ugt_swap_or_not_min_commute(ptr %x, ptr %y) {
548 ; CHECK-LABEL: @ugt_swap_or_not_min_commute(
549 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
550 ; CHECK-NEXT: ret i1 [[CMPEQ]]
552 %cmp = icmp ult ptr %y, %x
553 %cmpeq = icmp ne ptr %x, null
554 %r = or i1 %cmpeq, %cmp
558 define i1 @ugt_swap_or_not_min_commute_logical(ptr %x, ptr %y) {
559 ; CHECK-LABEL: @ugt_swap_or_not_min_commute_logical(
560 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
561 ; CHECK-NEXT: ret i1 [[CMPEQ]]
563 %cmp = icmp ult ptr %y, %x
564 %cmpeq = icmp ne ptr %x, null
565 %r = select i1 %cmpeq, i1 true, i1 %cmp
569 define i1 @sgt_and_min(ptr %x, ptr %y) {
570 ; CHECK-LABEL: @sgt_and_min(
571 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
572 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt ptr [[Y:%.*]], null
573 ; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[TMP1]]
574 ; CHECK-NEXT: ret i1 [[R]]
576 %cmp = icmp sgt ptr %x, %y
577 %cmpeq = icmp eq ptr %x, null
578 %r = and i1 %cmp, %cmpeq
582 define i1 @sgt_and_min_logical(ptr %x, ptr %y) {
583 ; CHECK-LABEL: @sgt_and_min_logical(
584 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
585 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt ptr [[Y:%.*]], null
586 ; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[TMP1]]
587 ; CHECK-NEXT: ret i1 [[R]]
589 %cmp = icmp sgt ptr %x, %y
590 %cmpeq = icmp eq ptr %x, null
591 %r = select i1 %cmp, i1 %cmpeq, i1 false
595 define i1 @sgt_and_min_logical_samesign(ptr %x, ptr %y) {
596 ; CHECK-LABEL: @sgt_and_min_logical_samesign(
597 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
598 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt ptr [[Y:%.*]], null
599 ; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[TMP1]]
600 ; CHECK-NEXT: ret i1 [[R]]
602 %cmp = icmp sgt ptr %x, %y
603 %cmpeq = icmp samesign eq ptr %x, null
604 %r = select i1 %cmp, i1 %cmpeq, i1 false
608 define i1 @sle_or_not_min(ptr %x, ptr %y) {
609 ; CHECK-LABEL: @sle_or_not_min(
610 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
611 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sge ptr [[Y:%.*]], null
612 ; CHECK-NEXT: [[R:%.*]] = or i1 [[CMPEQ]], [[TMP1]]
613 ; CHECK-NEXT: ret i1 [[R]]
615 %cmp = icmp sle ptr %x, %y
616 %cmpeq = icmp ne ptr %x, null
617 %r = or i1 %cmp, %cmpeq
621 define i1 @sle_or_not_min_logical(ptr %x, ptr %y) {
622 ; CHECK-LABEL: @sle_or_not_min_logical(
623 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
624 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sge ptr [[Y:%.*]], null
625 ; CHECK-NEXT: [[R:%.*]] = or i1 [[CMPEQ]], [[TMP1]]
626 ; CHECK-NEXT: ret i1 [[R]]
628 %cmp = icmp sle ptr %x, %y
629 %cmpeq = icmp ne ptr %x, null
630 %r = select i1 %cmp, i1 true, i1 %cmpeq
634 define i1 @sle_and_min(ptr %x, ptr %y) {
635 ; CHECK-LABEL: @sle_and_min(
636 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
637 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sge ptr [[Y:%.*]], null
638 ; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[TMP1]]
639 ; CHECK-NEXT: ret i1 [[R]]
641 %cmp = icmp sle ptr %x, %y
642 %cmpeq = icmp eq ptr %x, null
643 %r = and i1 %cmp, %cmpeq
647 define i1 @sle_and_min_logical(ptr %x, ptr %y) {
648 ; CHECK-LABEL: @sle_and_min_logical(
649 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[X:%.*]], null
650 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sge ptr [[Y:%.*]], null
651 ; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[TMP1]]
652 ; CHECK-NEXT: ret i1 [[R]]
654 %cmp = icmp sle ptr %x, %y
655 %cmpeq = icmp eq ptr %x, null
656 %r = select i1 %cmp, i1 %cmpeq, i1 false
660 define i1 @sgt_and_not_min(ptr %x, ptr %y) {
661 ; CHECK-LABEL: @sgt_and_not_min(
662 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt ptr [[X:%.*]], [[Y:%.*]]
663 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X]], null
664 ; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
665 ; CHECK-NEXT: ret i1 [[R]]
667 %cmp = icmp sgt ptr %x, %y
668 %cmpeq = icmp ne ptr %x, null
669 %r = and i1 %cmp, %cmpeq
673 define i1 @sgt_and_not_min_logical(ptr %x, ptr %y) {
674 ; CHECK-LABEL: @sgt_and_not_min_logical(
675 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt ptr [[X:%.*]], [[Y:%.*]]
676 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X]], null
677 ; CHECK-NEXT: [[R:%.*]] = and i1 [[CMP]], [[CMPEQ]]
678 ; CHECK-NEXT: ret i1 [[R]]
680 %cmp = icmp sgt ptr %x, %y
681 %cmpeq = icmp ne ptr %x, null
682 %r = select i1 %cmp, i1 %cmpeq, i1 false
686 define i1 @sgt_or_not_min(ptr %x, ptr %y) {
687 ; CHECK-LABEL: @sgt_or_not_min(
688 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
689 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt ptr [[Y:%.*]], null
690 ; CHECK-NEXT: [[R:%.*]] = or i1 [[CMPEQ]], [[TMP1]]
691 ; CHECK-NEXT: ret i1 [[R]]
693 %cmp = icmp sgt ptr %x, %y
694 %cmpeq = icmp ne ptr %x, null
695 %r = or i1 %cmp, %cmpeq
699 define i1 @sgt_or_not_min_logical(ptr %x, ptr %y) {
700 ; CHECK-LABEL: @sgt_or_not_min_logical(
701 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp ne ptr [[X:%.*]], null
702 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt ptr [[Y:%.*]], null
703 ; CHECK-NEXT: [[R:%.*]] = or i1 [[CMPEQ]], [[TMP1]]
704 ; CHECK-NEXT: ret i1 [[R]]
706 %cmp = icmp sgt ptr %x, %y
707 %cmpeq = icmp ne ptr %x, null
708 %r = select i1 %cmp, i1 true, i1 %cmpeq
712 define i1 @slt_and_min(ptr %a, ptr %b) {
713 ; CHECK-LABEL: @slt_and_min(
714 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[A:%.*]], null
715 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt ptr [[B:%.*]], null
716 ; CHECK-NEXT: [[R:%.*]] = and i1 [[CMPEQ]], [[TMP1]]
717 ; CHECK-NEXT: ret i1 [[R]]
719 %cmpeq = icmp eq ptr %a, null
720 %cmp = icmp slt ptr %a, %b
721 %r = and i1 %cmpeq, %cmp
725 define i1 @slt_and_min_logical(ptr %a, ptr %b) {
726 ; CHECK-LABEL: @slt_and_min_logical(
727 ; CHECK-NEXT: [[CMPEQ:%.*]] = icmp eq ptr [[A:%.*]], null
728 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt ptr [[B:%.*]], null
729 ; CHECK-NEXT: [[R:%.*]] = select i1 [[CMPEQ]], i1 [[TMP1]], i1 false
730 ; CHECK-NEXT: ret i1 [[R]]
732 %cmpeq = icmp eq ptr %a, null
733 %cmp = icmp slt ptr %a, %b
734 %r = select i1 %cmpeq, i1 %cmp, i1 false