1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s --check-prefixes=X86
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=-slow-incdec | FileCheck %s --check-prefixes=X64,X64-FASTINC
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+slow-incdec | FileCheck %s --check-prefixes=X64,X64-SLOWINC
6 ; Select of constants: control flow / conditional moves can always be replaced by logic+math (but may not be worth it?).
7 ; Test the zeroext/signext variants of each pattern to see if that makes a difference.
9 ; select Cond, 0, 1 --> zext (!Cond)
11 define i32 @select_0_or_1(i1 %cond) {
12 ; X86-LABEL: select_0_or_1:
14 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
16 ; X86-NEXT: movzbl %al, %eax
17 ; X86-NEXT: andl $1, %eax
20 ; X64-LABEL: select_0_or_1:
23 ; X64-NEXT: movzbl %dil, %eax
24 ; X64-NEXT: andl $1, %eax
26 %sel = select i1 %cond, i32 0, i32 1
30 define i32 @select_0_or_1_zeroext(i1 zeroext %cond) {
31 ; X86-LABEL: select_0_or_1_zeroext:
33 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
34 ; X86-NEXT: xorb $1, %al
35 ; X86-NEXT: movzbl %al, %eax
38 ; X64-LABEL: select_0_or_1_zeroext:
40 ; X64-NEXT: xorb $1, %dil
41 ; X64-NEXT: movzbl %dil, %eax
43 %sel = select i1 %cond, i32 0, i32 1
47 define i32 @select_0_or_1_signext(i1 signext %cond) {
48 ; X86-LABEL: select_0_or_1_signext:
50 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
52 ; X86-NEXT: movzbl %al, %eax
53 ; X86-NEXT: andl $1, %eax
56 ; X64-LABEL: select_0_or_1_signext:
59 ; X64-NEXT: movzbl %dil, %eax
60 ; X64-NEXT: andl $1, %eax
62 %sel = select i1 %cond, i32 0, i32 1
66 ; select Cond, 1, 0 --> zext (Cond)
68 define i32 @select_1_or_0(i1 %cond) {
69 ; X86-LABEL: select_1_or_0:
71 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
72 ; X86-NEXT: andl $1, %eax
75 ; X64-LABEL: select_1_or_0:
77 ; X64-NEXT: movl %edi, %eax
78 ; X64-NEXT: andl $1, %eax
80 %sel = select i1 %cond, i32 1, i32 0
84 define i32 @select_1_or_0_zeroext(i1 zeroext %cond) {
85 ; X86-LABEL: select_1_or_0_zeroext:
87 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
90 ; X64-LABEL: select_1_or_0_zeroext:
92 ; X64-NEXT: movl %edi, %eax
94 %sel = select i1 %cond, i32 1, i32 0
98 define i32 @select_1_or_0_signext(i1 signext %cond) {
99 ; X86-LABEL: select_1_or_0_signext:
101 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
102 ; X86-NEXT: andl $1, %eax
105 ; X64-LABEL: select_1_or_0_signext:
107 ; X64-NEXT: movl %edi, %eax
108 ; X64-NEXT: andl $1, %eax
110 %sel = select i1 %cond, i32 1, i32 0
114 ; select Cond, 0, -1 --> sext (!Cond)
116 define i32 @select_0_or_neg1(i1 %cond) {
117 ; X86-LABEL: select_0_or_neg1:
119 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
120 ; X86-NEXT: andl $1, %eax
121 ; X86-NEXT: decl %eax
124 ; X64-LABEL: select_0_or_neg1:
126 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
127 ; X64-NEXT: andl $1, %edi
128 ; X64-NEXT: leal -1(%rdi), %eax
130 %sel = select i1 %cond, i32 0, i32 -1
134 define i32 @select_0_or_neg1_zeroext(i1 zeroext %cond) {
135 ; X86-LABEL: select_0_or_neg1_zeroext:
137 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
138 ; X86-NEXT: decl %eax
141 ; X64-LABEL: select_0_or_neg1_zeroext:
143 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
144 ; X64-NEXT: leal -1(%rdi), %eax
146 %sel = select i1 %cond, i32 0, i32 -1
150 define i32 @select_0_or_neg1_signext(i1 signext %cond) {
151 ; X86-LABEL: select_0_or_neg1_signext:
153 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
154 ; X86-NEXT: andl $1, %eax
155 ; X86-NEXT: decl %eax
158 ; X64-LABEL: select_0_or_neg1_signext:
160 ; X64-NEXT: movl %edi, %eax
161 ; X64-NEXT: notl %eax
163 %sel = select i1 %cond, i32 0, i32 -1
167 ; select Cond, -1, 0 --> sext (Cond)
169 define i32 @select_neg1_or_0(i1 %cond) {
170 ; X86-LABEL: select_neg1_or_0:
172 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
173 ; X86-NEXT: andl $1, %eax
174 ; X86-NEXT: negl %eax
177 ; X64-LABEL: select_neg1_or_0:
179 ; X64-NEXT: movl %edi, %eax
180 ; X64-NEXT: andl $1, %eax
181 ; X64-NEXT: negl %eax
183 %sel = select i1 %cond, i32 -1, i32 0
187 define i32 @select_neg1_or_0_zeroext(i1 zeroext %cond) {
188 ; X86-LABEL: select_neg1_or_0_zeroext:
190 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
191 ; X86-NEXT: negl %eax
194 ; X64-LABEL: select_neg1_or_0_zeroext:
196 ; X64-NEXT: movl %edi, %eax
197 ; X64-NEXT: negl %eax
199 %sel = select i1 %cond, i32 -1, i32 0
203 define i32 @select_neg1_or_0_signext(i1 signext %cond) {
204 ; X86-LABEL: select_neg1_or_0_signext:
206 ; X86-NEXT: movsbl {{[0-9]+}}(%esp), %eax
209 ; X64-LABEL: select_neg1_or_0_signext:
211 ; X64-NEXT: movl %edi, %eax
213 %sel = select i1 %cond, i32 -1, i32 0
217 ; select Cond, C+1, C --> add (zext Cond), C
219 define i32 @select_Cplus1_C(i1 %cond) {
220 ; X86-LABEL: select_Cplus1_C:
222 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
223 ; X86-NEXT: andl $1, %eax
224 ; X86-NEXT: addl $41, %eax
227 ; X64-LABEL: select_Cplus1_C:
229 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
230 ; X64-NEXT: andl $1, %edi
231 ; X64-NEXT: leal 41(%rdi), %eax
233 %sel = select i1 %cond, i32 42, i32 41
237 define i32 @select_Cplus1_C_zeroext(i1 zeroext %cond) {
238 ; X86-LABEL: select_Cplus1_C_zeroext:
240 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
241 ; X86-NEXT: addl $41, %eax
244 ; X64-LABEL: select_Cplus1_C_zeroext:
246 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
247 ; X64-NEXT: leal 41(%rdi), %eax
249 %sel = select i1 %cond, i32 42, i32 41
253 define i32 @select_Cplus1_C_signext(i1 signext %cond) {
254 ; X86-LABEL: select_Cplus1_C_signext:
256 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
257 ; X86-NEXT: andl $1, %eax
258 ; X86-NEXT: addl $41, %eax
261 ; X64-LABEL: select_Cplus1_C_signext:
263 ; X64-NEXT: movl $41, %eax
264 ; X64-NEXT: subl %edi, %eax
266 %sel = select i1 %cond, i32 42, i32 41
270 ; select Cond, C, C+1 --> add (sext Cond), C
272 define i32 @select_C_Cplus1(i1 %cond) {
273 ; X86-LABEL: select_C_Cplus1:
275 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
276 ; X86-NEXT: andl $1, %ecx
277 ; X86-NEXT: movl $42, %eax
278 ; X86-NEXT: subl %ecx, %eax
281 ; X64-LABEL: select_C_Cplus1:
283 ; X64-NEXT: andl $1, %edi
284 ; X64-NEXT: movl $42, %eax
285 ; X64-NEXT: subl %edi, %eax
287 %sel = select i1 %cond, i32 41, i32 42
291 define i32 @select_C_Cplus1_zeroext(i1 zeroext %cond) {
292 ; X86-LABEL: select_C_Cplus1_zeroext:
294 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
295 ; X86-NEXT: movl $42, %eax
296 ; X86-NEXT: subl %ecx, %eax
299 ; X64-LABEL: select_C_Cplus1_zeroext:
301 ; X64-NEXT: movl $42, %eax
302 ; X64-NEXT: subl %edi, %eax
304 %sel = select i1 %cond, i32 41, i32 42
308 define i32 @select_C_Cplus1_signext(i1 signext %cond) {
309 ; X86-LABEL: select_C_Cplus1_signext:
311 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
312 ; X86-NEXT: andl $1, %ecx
313 ; X86-NEXT: movl $42, %eax
314 ; X86-NEXT: subl %ecx, %eax
317 ; X64-LABEL: select_C_Cplus1_signext:
319 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
320 ; X64-NEXT: leal 42(%rdi), %eax
322 %sel = select i1 %cond, i32 41, i32 42
326 ; If the constants differ by a small multiplier, use LEA.
327 ; select Cond, C1, C2 --> add (mul (zext Cond), C1-C2), C2 --> LEA C2(Cond * (C1-C2))
329 define i32 @select_lea_2(i1 zeroext %cond) {
330 ; X86-LABEL: select_lea_2:
332 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
333 ; X86-NEXT: negl %eax
334 ; X86-NEXT: orl $1, %eax
337 ; X64-LABEL: select_lea_2:
339 ; X64-NEXT: movl %edi, %eax
340 ; X64-NEXT: negl %eax
341 ; X64-NEXT: orl $1, %eax
343 %sel = select i1 %cond, i32 -1, i32 1
347 define i64 @select_lea_3(i1 zeroext %cond) {
348 ; X86-LABEL: select_lea_3:
350 ; X86-NEXT: cmpb $0, {{[0-9]+}}(%esp)
351 ; X86-NEXT: movl $-2, %eax
352 ; X86-NEXT: je .LBB19_1
354 ; X86-NEXT: movl $-1, %edx
355 ; X86-NEXT: je .LBB19_3
356 ; X86-NEXT: .LBB19_4:
358 ; X86-NEXT: .LBB19_1:
359 ; X86-NEXT: movl $1, %eax
360 ; X86-NEXT: movl $-1, %edx
361 ; X86-NEXT: jne .LBB19_4
362 ; X86-NEXT: .LBB19_3:
363 ; X86-NEXT: xorl %edx, %edx
366 ; X64-LABEL: select_lea_3:
368 ; X64-NEXT: xorb $1, %dil
369 ; X64-NEXT: movzbl %dil, %eax
370 ; X64-NEXT: leaq -2(%rax,%rax,2), %rax
372 %sel = select i1 %cond, i64 -2, i64 1
376 define i32 @select_lea_5(i1 zeroext %cond) {
377 ; X86-LABEL: select_lea_5:
379 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
380 ; X86-NEXT: xorb $1, %al
381 ; X86-NEXT: movzbl %al, %eax
382 ; X86-NEXT: leal -2(%eax,%eax,4), %eax
385 ; X64-LABEL: select_lea_5:
387 ; X64-NEXT: xorb $1, %dil
388 ; X64-NEXT: movzbl %dil, %eax
389 ; X64-NEXT: leal -2(%rax,%rax,4), %eax
391 %sel = select i1 %cond, i32 -2, i32 3
395 define i64 @select_lea_9(i1 zeroext %cond) {
396 ; X86-LABEL: select_lea_9:
398 ; X86-NEXT: cmpb $0, {{[0-9]+}}(%esp)
399 ; X86-NEXT: movl $-7, %eax
400 ; X86-NEXT: je .LBB21_1
402 ; X86-NEXT: movl $-1, %edx
403 ; X86-NEXT: je .LBB21_3
404 ; X86-NEXT: .LBB21_4:
406 ; X86-NEXT: .LBB21_1:
407 ; X86-NEXT: movl $2, %eax
408 ; X86-NEXT: movl $-1, %edx
409 ; X86-NEXT: jne .LBB21_4
410 ; X86-NEXT: .LBB21_3:
411 ; X86-NEXT: xorl %edx, %edx
414 ; X64-LABEL: select_lea_9:
416 ; X64-NEXT: xorb $1, %dil
417 ; X64-NEXT: movzbl %dil, %eax
418 ; X64-NEXT: leaq -7(%rax,%rax,8), %rax
420 %sel = select i1 %cond, i64 -7, i64 2
424 ; Should this be 'sbb x,x' or 'sbb 0,x' with simpler LEA or add?
426 define i64 @sel_1_2(i64 %x, i64 %y) {
427 ; X86-LABEL: sel_1_2:
429 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
430 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
431 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
432 ; X86-NEXT: cmpl $42, {{[0-9]+}}(%esp)
433 ; X86-NEXT: sbbl $0, %ecx
434 ; X86-NEXT: sbbl $0, %eax
435 ; X86-NEXT: sbbl $0, %edx
436 ; X86-NEXT: addl $2, %eax
437 ; X86-NEXT: adcl $0, %edx
440 ; X64-LABEL: sel_1_2:
442 ; X64-NEXT: cmpq $42, %rdi
443 ; X64-NEXT: sbbq $0, %rsi
444 ; X64-NEXT: leaq 2(%rsi), %rax
446 %cmp = icmp ult i64 %x, 42
447 %sel = select i1 %cmp, i64 1, i64 2
448 %sub = add i64 %sel, %y
452 ; No LEA with 8-bit, but this shouldn't need branches or cmov.
454 define i8 @sel_1_neg1(i32 %x) {
455 ; X86-LABEL: sel_1_neg1:
457 ; X86-NEXT: cmpl $43, {{[0-9]+}}(%esp)
460 ; X86-NEXT: orb $3, %al
463 ; X64-LABEL: sel_1_neg1:
465 ; X64-NEXT: cmpl $43, %edi
468 ; X64-NEXT: orb $3, %al
470 %cmp = icmp sgt i32 %x, 42
471 %sel = select i1 %cmp, i8 3, i8 -1
475 ; We get an LEA for 16-bit because we ignore the high-bits.
477 define i16 @sel_neg1_1(i32 %x) {
478 ; X86-LABEL: sel_neg1_1:
480 ; X86-NEXT: xorl %eax, %eax
481 ; X86-NEXT: cmpl $43, {{[0-9]+}}(%esp)
483 ; X86-NEXT: leal -1(,%eax,4), %eax
484 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
487 ; X64-LABEL: sel_neg1_1:
489 ; X64-NEXT: xorl %eax, %eax
490 ; X64-NEXT: cmpl $43, %edi
492 ; X64-NEXT: leal -1(,%rax,4), %eax
493 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
495 %cmp = icmp sgt i32 %x, 42
496 %sel = select i1 %cmp, i16 -1, i16 3
500 ; If the comparison is available, the predicate can be inverted.
502 define i32 @sel_1_neg1_32(i32 %x) {
503 ; X86-LABEL: sel_1_neg1_32:
505 ; X86-NEXT: xorl %eax, %eax
506 ; X86-NEXT: cmpl $43, {{[0-9]+}}(%esp)
507 ; X86-NEXT: setge %al
508 ; X86-NEXT: leal -1(%eax,%eax,8), %eax
511 ; X64-LABEL: sel_1_neg1_32:
513 ; X64-NEXT: xorl %eax, %eax
514 ; X64-NEXT: cmpl $43, %edi
515 ; X64-NEXT: setge %al
516 ; X64-NEXT: leal -1(%rax,%rax,8), %eax
518 %cmp = icmp sgt i32 %x, 42
519 %sel = select i1 %cmp, i32 8, i32 -1
523 define i32 @sel_neg1_1_32(i32 %x) {
524 ; X86-LABEL: sel_neg1_1_32:
526 ; X86-NEXT: xorl %eax, %eax
527 ; X86-NEXT: cmpl $43, {{[0-9]+}}(%esp)
529 ; X86-NEXT: leal -7(%eax,%eax,8), %eax
532 ; X64-LABEL: sel_neg1_1_32:
534 ; X64-NEXT: xorl %eax, %eax
535 ; X64-NEXT: cmpl $43, %edi
537 ; X64-NEXT: leal -7(%rax,%rax,8), %eax
539 %cmp = icmp sgt i32 %x, 42
540 %sel = select i1 %cmp, i32 -7, i32 2
545 ; If the constants differ by a large power-of-2, that can be a shift of the difference plus the smaller constant.
546 ; select Cond, C1, C2 --> add (mul (zext Cond), C1-C2), C2
548 define i8 @select_pow2_diff(i1 zeroext %cond) {
549 ; X86-LABEL: select_pow2_diff:
551 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
552 ; X86-NEXT: shlb $4, %al
553 ; X86-NEXT: orb $3, %al
556 ; X64-LABEL: select_pow2_diff:
558 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
559 ; X64-NEXT: shlb $4, %dil
560 ; X64-NEXT: leal 3(%rdi), %eax
561 ; X64-NEXT: # kill: def $al killed $al killed $eax
563 %sel = select i1 %cond, i8 19, i8 3
567 define i16 @select_pow2_diff_invert(i1 zeroext %cond) {
568 ; X86-LABEL: select_pow2_diff_invert:
570 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
571 ; X86-NEXT: xorb $1, %al
572 ; X86-NEXT: movzbl %al, %eax
573 ; X86-NEXT: shll $6, %eax
574 ; X86-NEXT: orl $7, %eax
575 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
578 ; X64-LABEL: select_pow2_diff_invert:
580 ; X64-NEXT: xorb $1, %dil
581 ; X64-NEXT: movzbl %dil, %eax
582 ; X64-NEXT: shll $6, %eax
583 ; X64-NEXT: orl $7, %eax
584 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
586 %sel = select i1 %cond, i16 7, i16 71
590 define i32 @select_pow2_diff_neg(i1 zeroext %cond) {
591 ; X86-LABEL: select_pow2_diff_neg:
593 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
594 ; X86-NEXT: shll $4, %eax
595 ; X86-NEXT: orl $-25, %eax
598 ; X64-LABEL: select_pow2_diff_neg:
600 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
601 ; X64-NEXT: shll $4, %edi
602 ; X64-NEXT: leal -25(%rdi), %eax
604 %sel = select i1 %cond, i32 -9, i32 -25
608 define i64 @select_pow2_diff_neg_invert(i1 zeroext %cond) {
609 ; X86-LABEL: select_pow2_diff_neg_invert:
611 ; X86-NEXT: cmpb $0, {{[0-9]+}}(%esp)
612 ; X86-NEXT: movl $-99, %eax
613 ; X86-NEXT: je .LBB30_1
615 ; X86-NEXT: movl $-1, %edx
616 ; X86-NEXT: je .LBB30_3
617 ; X86-NEXT: .LBB30_4:
619 ; X86-NEXT: .LBB30_1:
620 ; X86-NEXT: movl $29, %eax
621 ; X86-NEXT: movl $-1, %edx
622 ; X86-NEXT: jne .LBB30_4
623 ; X86-NEXT: .LBB30_3:
624 ; X86-NEXT: xorl %edx, %edx
627 ; X64-LABEL: select_pow2_diff_neg_invert:
629 ; X64-NEXT: xorb $1, %dil
630 ; X64-NEXT: movzbl %dil, %eax
631 ; X64-NEXT: shll $7, %eax
632 ; X64-NEXT: addq $-99, %rax
634 %sel = select i1 %cond, i64 -99, i64 29
638 ; This doesn't need a branch, but don't do the wrong thing if subtraction of the constants overflows.
640 define i8 @sel_67_neg125(i32 %x) {
641 ; X86-LABEL: sel_67_neg125:
643 ; X86-NEXT: cmpl $43, {{[0-9]+}}(%esp)
644 ; X86-NEXT: movb $67, %al
645 ; X86-NEXT: jge .LBB31_2
647 ; X86-NEXT: movb $-125, %al
648 ; X86-NEXT: .LBB31_2:
651 ; X64-LABEL: sel_67_neg125:
653 ; X64-NEXT: cmpl $43, %edi
654 ; X64-NEXT: movl $67, %ecx
655 ; X64-NEXT: movl $131, %eax
656 ; X64-NEXT: cmovgel %ecx, %eax
657 ; X64-NEXT: # kill: def $al killed $al killed $eax
659 %cmp = icmp sgt i32 %x, 42
660 %sel = select i1 %cmp, i8 67, i8 -125
665 ; In general, select of 2 constants could be:
666 ; select Cond, C1, C2 --> add (mul (zext Cond), C1-C2), C2 --> add (and (sext Cond), C1-C2), C2
668 define i32 @select_C1_C2(i1 %cond) {
669 ; X86-LABEL: select_C1_C2:
671 ; X86-NEXT: testb $1, {{[0-9]+}}(%esp)
672 ; X86-NEXT: movl $421, %eax # imm = 0x1A5
673 ; X86-NEXT: jne .LBB32_2
675 ; X86-NEXT: movl $42, %eax
676 ; X86-NEXT: .LBB32_2:
679 ; X64-LABEL: select_C1_C2:
681 ; X64-NEXT: testb $1, %dil
682 ; X64-NEXT: movl $421, %ecx # imm = 0x1A5
683 ; X64-NEXT: movl $42, %eax
684 ; X64-NEXT: cmovnel %ecx, %eax
686 %sel = select i1 %cond, i32 421, i32 42
690 define i32 @select_C1_C2_zeroext(i1 zeroext %cond) {
691 ; X86-LABEL: select_C1_C2_zeroext:
693 ; X86-NEXT: cmpb $0, {{[0-9]+}}(%esp)
694 ; X86-NEXT: movl $421, %eax # imm = 0x1A5
695 ; X86-NEXT: jne .LBB33_2
697 ; X86-NEXT: movl $42, %eax
698 ; X86-NEXT: .LBB33_2:
701 ; X64-LABEL: select_C1_C2_zeroext:
703 ; X64-NEXT: testl %edi, %edi
704 ; X64-NEXT: movl $421, %ecx # imm = 0x1A5
705 ; X64-NEXT: movl $42, %eax
706 ; X64-NEXT: cmovnel %ecx, %eax
708 %sel = select i1 %cond, i32 421, i32 42
712 define i32 @select_C1_C2_signext(i1 signext %cond) {
713 ; X86-LABEL: select_C1_C2_signext:
715 ; X86-NEXT: testb $1, {{[0-9]+}}(%esp)
716 ; X86-NEXT: movl $421, %eax # imm = 0x1A5
717 ; X86-NEXT: jne .LBB34_2
719 ; X86-NEXT: movl $42, %eax
720 ; X86-NEXT: .LBB34_2:
723 ; X64-LABEL: select_C1_C2_signext:
725 ; X64-NEXT: testb $1, %dil
726 ; X64-NEXT: movl $421, %ecx # imm = 0x1A5
727 ; X64-NEXT: movl $42, %eax
728 ; X64-NEXT: cmovnel %ecx, %eax
730 %sel = select i1 %cond, i32 421, i32 42
734 define i32 @select_n_or_minus1(i1 signext %cond) {
735 ; X86-LABEL: select_n_or_minus1:
737 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
738 ; X86-NEXT: andl $1, %eax
739 ; X86-NEXT: decl %eax
740 ; X86-NEXT: orl $12414, %eax # imm = 0x307E
743 ; X64-LABEL: select_n_or_minus1:
745 ; X64-NEXT: movl %edi, %eax
746 ; X64-NEXT: notl %eax
747 ; X64-NEXT: orl $12414, %eax # imm = 0x307E
749 %sel = select i1 %cond, i32 12414, i32 -1
753 ; select (x == 2), 2, (x + 1) --> select (x == 2), x, (x + 1)
755 define i64 @select_2_or_inc(i64 %x) {
756 ; X86-LABEL: select_2_or_inc:
758 ; X86-NEXT: pushl %edi
759 ; X86-NEXT: .cfi_def_cfa_offset 8
760 ; X86-NEXT: pushl %esi
761 ; X86-NEXT: .cfi_def_cfa_offset 12
762 ; X86-NEXT: .cfi_offset %esi, -12
763 ; X86-NEXT: .cfi_offset %edi, -8
764 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
765 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
766 ; X86-NEXT: movl %ecx, %edi
767 ; X86-NEXT: xorl $2, %edi
768 ; X86-NEXT: addl $1, %ecx
769 ; X86-NEXT: movl %esi, %eax
770 ; X86-NEXT: adcl $0, %eax
771 ; X86-NEXT: xorl %edx, %edx
772 ; X86-NEXT: orl %esi, %edi
773 ; X86-NEXT: je .LBB36_2
775 ; X86-NEXT: movl %eax, %edx
776 ; X86-NEXT: .LBB36_2:
777 ; X86-NEXT: movl $2, %eax
778 ; X86-NEXT: je .LBB36_4
780 ; X86-NEXT: movl %ecx, %eax
781 ; X86-NEXT: .LBB36_4:
782 ; X86-NEXT: popl %esi
783 ; X86-NEXT: .cfi_def_cfa_offset 8
784 ; X86-NEXT: popl %edi
785 ; X86-NEXT: .cfi_def_cfa_offset 4
788 ; X64-LABEL: select_2_or_inc:
790 ; X64-NEXT: leaq 1(%rdi), %rax
791 ; X64-NEXT: cmpq $2, %rdi
792 ; X64-NEXT: cmoveq %rdi, %rax
794 %cmp = icmp eq i64 %x, 2
796 %retval.0 = select i1 %cmp, i64 2, i64 %add
800 define <4 x i32> @sel_constants_add_constant_vec(i1 %cond) {
801 ; X86-LABEL: sel_constants_add_constant_vec:
803 ; X86-NEXT: pushl %ebx
804 ; X86-NEXT: .cfi_def_cfa_offset 8
805 ; X86-NEXT: pushl %edi
806 ; X86-NEXT: .cfi_def_cfa_offset 12
807 ; X86-NEXT: pushl %esi
808 ; X86-NEXT: .cfi_def_cfa_offset 16
809 ; X86-NEXT: .cfi_offset %esi, -16
810 ; X86-NEXT: .cfi_offset %edi, -12
811 ; X86-NEXT: .cfi_offset %ebx, -8
812 ; X86-NEXT: testb $1, {{[0-9]+}}(%esp)
813 ; X86-NEXT: movl $-3, %ecx
814 ; X86-NEXT: jne .LBB37_2
816 ; X86-NEXT: movl $12, %ecx
817 ; X86-NEXT: .LBB37_2:
818 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
819 ; X86-NEXT: movl $4, %esi
820 ; X86-NEXT: movl $4, %edx
821 ; X86-NEXT: jne .LBB37_4
823 ; X86-NEXT: movl $14, %edx
824 ; X86-NEXT: .LBB37_4:
825 ; X86-NEXT: jne .LBB37_6
827 ; X86-NEXT: movl $15, %esi
828 ; X86-NEXT: .LBB37_6:
829 ; X86-NEXT: setne %bl
830 ; X86-NEXT: movzbl %bl, %edi
831 ; X86-NEXT: addl $13, %edi
832 ; X86-NEXT: movl %esi, 12(%eax)
833 ; X86-NEXT: movl %edx, 8(%eax)
834 ; X86-NEXT: movl %edi, 4(%eax)
835 ; X86-NEXT: movl %ecx, (%eax)
836 ; X86-NEXT: popl %esi
837 ; X86-NEXT: .cfi_def_cfa_offset 12
838 ; X86-NEXT: popl %edi
839 ; X86-NEXT: .cfi_def_cfa_offset 8
840 ; X86-NEXT: popl %ebx
841 ; X86-NEXT: .cfi_def_cfa_offset 4
844 ; X64-LABEL: sel_constants_add_constant_vec:
846 ; X64-NEXT: testb $1, %dil
847 ; X64-NEXT: jne .LBB37_1
849 ; X64-NEXT: movaps {{.*#+}} xmm0 = [12,13,14,15]
851 ; X64-NEXT: .LBB37_1:
852 ; X64-NEXT: movaps {{.*#+}} xmm0 = [4294967293,14,4,4]
854 %sel = select i1 %cond, <4 x i32> <i32 -4, i32 12, i32 1, i32 0>, <4 x i32> <i32 11, i32 11, i32 11, i32 11>
855 %bo = add <4 x i32> %sel, <i32 1, i32 2, i32 3, i32 4>
859 define <2 x double> @sel_constants_fmul_constant_vec(i1 %cond) {
860 ; X86-LABEL: sel_constants_fmul_constant_vec:
862 ; X86-NEXT: testb $1, {{[0-9]+}}(%esp)
863 ; X86-NEXT: fldl {{\.?LCPI[0-9]+_[0-9]+}}
864 ; X86-NEXT: fldl {{\.?LCPI[0-9]+_[0-9]+}}
865 ; X86-NEXT: jne .LBB38_2
867 ; X86-NEXT: fstp %st(1)
869 ; X86-NEXT: .LBB38_2:
870 ; X86-NEXT: fstp %st(0)
871 ; X86-NEXT: fldl {{\.?LCPI[0-9]+_[0-9]+}}
872 ; X86-NEXT: fldl {{\.?LCPI[0-9]+_[0-9]+}}
873 ; X86-NEXT: jne .LBB38_4
875 ; X86-NEXT: fstp %st(1)
877 ; X86-NEXT: .LBB38_4:
878 ; X86-NEXT: fstp %st(0)
881 ; X64-LABEL: sel_constants_fmul_constant_vec:
883 ; X64-NEXT: testb $1, %dil
884 ; X64-NEXT: jne .LBB38_1
886 ; X64-NEXT: movaps {{.*#+}} xmm0 = [1.1883E+2,3.4539999999999999E+1]
888 ; X64-NEXT: .LBB38_1:
889 ; X64-NEXT: movaps {{.*#+}} xmm0 = [-2.0399999999999999E+1,3.768E+1]
891 %sel = select i1 %cond, <2 x double> <double -4.0, double 12.0>, <2 x double> <double 23.3, double 11.0>
892 %bo = fmul <2 x double> %sel, <double 5.1, double 3.14>
896 ; 4294967297 = 0x100000001.
897 ; This becomes an opaque constant via ConstantHoisting, so we don't fold it into the select.
899 define i64 @opaque_constant(i1 %cond, i64 %x) {
900 ; X86-LABEL: opaque_constant:
902 ; X86-NEXT: pushl %ebx
903 ; X86-NEXT: .cfi_def_cfa_offset 8
904 ; X86-NEXT: pushl %esi
905 ; X86-NEXT: .cfi_def_cfa_offset 12
906 ; X86-NEXT: .cfi_offset %esi, -12
907 ; X86-NEXT: .cfi_offset %ebx, -8
908 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
909 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
910 ; X86-NEXT: testb $1, {{[0-9]+}}(%esp)
911 ; X86-NEXT: movl $-4, %eax
912 ; X86-NEXT: jne .LBB39_2
914 ; X86-NEXT: movl $23, %eax
915 ; X86-NEXT: .LBB39_2:
916 ; X86-NEXT: setne %dl
917 ; X86-NEXT: movzbl %dl, %edx
918 ; X86-NEXT: andl $1, %eax
919 ; X86-NEXT: xorl $1, %esi
920 ; X86-NEXT: xorl $1, %ecx
921 ; X86-NEXT: xorl %ebx, %ebx
922 ; X86-NEXT: orl %esi, %ecx
924 ; X86-NEXT: subl %ebx, %eax
925 ; X86-NEXT: sbbl $0, %edx
926 ; X86-NEXT: popl %esi
927 ; X86-NEXT: .cfi_def_cfa_offset 8
928 ; X86-NEXT: popl %ebx
929 ; X86-NEXT: .cfi_def_cfa_offset 4
932 ; X64-LABEL: opaque_constant:
934 ; X64-NEXT: testb $1, %dil
935 ; X64-NEXT: movq $-4, %rcx
936 ; X64-NEXT: movl $23, %eax
937 ; X64-NEXT: cmovneq %rcx, %rax
938 ; X64-NEXT: movabsq $4294967297, %rcx # imm = 0x100000001
939 ; X64-NEXT: andq %rcx, %rax
940 ; X64-NEXT: xorl %edx, %edx
941 ; X64-NEXT: cmpq %rcx, %rsi
943 ; X64-NEXT: subq %rdx, %rax
945 %sel = select i1 %cond, i64 -4, i64 23
946 %bo = and i64 %sel, 4294967297
947 %cmp = icmp eq i64 %x, 4294967297
948 %sext = sext i1 %cmp to i64
949 %add = add i64 %bo, %sext
953 define float @select_undef_fp(float %x) {
954 ; X86-LABEL: select_undef_fp:
956 ; X86-NEXT: flds {{\.?LCPI[0-9]+_[0-9]+}}
959 ; X64-LABEL: select_undef_fp:
961 ; X64-NEXT: movss {{.*#+}} xmm0 = [4.0E+0,0.0E+0,0.0E+0,0.0E+0]
963 %f = select i1 undef, float 4.0, float %x
967 define i32 @select_eq0_3_2(i32 %X) {
968 ; X86-LABEL: select_eq0_3_2:
970 ; X86-NEXT: xorl %eax, %eax
971 ; X86-NEXT: cmpl $1, {{[0-9]+}}(%esp)
972 ; X86-NEXT: adcl $2, %eax
975 ; X64-LABEL: select_eq0_3_2:
977 ; X64-NEXT: xorl %eax, %eax
978 ; X64-NEXT: cmpl $1, %edi
979 ; X64-NEXT: adcl $2, %eax
981 %cmp = icmp eq i32 %X, 0
982 %sel = select i1 %cmp, i32 3, i32 2
986 define i32 @select_ugt3_2_3(i32 %X) {
987 ; X86-LABEL: select_ugt3_2_3:
989 ; X86-NEXT: xorl %eax, %eax
990 ; X86-NEXT: cmpl $4, {{[0-9]+}}(%esp)
991 ; X86-NEXT: adcl $2, %eax
994 ; X64-LABEL: select_ugt3_2_3:
996 ; X64-NEXT: xorl %eax, %eax
997 ; X64-NEXT: cmpl $4, %edi
998 ; X64-NEXT: adcl $2, %eax
1000 %cmp = icmp ugt i32 %X, 3
1001 %sel = select i1 %cmp, i32 2, i32 3
1005 define i32 @select_ult9_7_6(i32 %X) {
1006 ; X86-LABEL: select_ult9_7_6:
1008 ; X86-NEXT: xorl %eax, %eax
1009 ; X86-NEXT: cmpl $9, {{[0-9]+}}(%esp)
1010 ; X86-NEXT: adcl $6, %eax
1013 ; X64-LABEL: select_ult9_7_6:
1015 ; X64-NEXT: xorl %eax, %eax
1016 ; X64-NEXT: cmpl $9, %edi
1017 ; X64-NEXT: adcl $6, %eax
1019 %cmp = icmp ult i32 %X, 9
1020 %sel = select i1 %cmp, i32 7, i32 6
1024 define i32 @select_ult2_2_3(i32 %X) {
1025 ; X86-LABEL: select_ult2_2_3:
1027 ; X86-NEXT: cmpl $2, {{[0-9]+}}(%esp)
1028 ; X86-NEXT: movl $3, %eax
1029 ; X86-NEXT: sbbl $0, %eax
1032 ; X64-LABEL: select_ult2_2_3:
1034 ; X64-NEXT: cmpl $2, %edi
1035 ; X64-NEXT: movl $3, %eax
1036 ; X64-NEXT: sbbl $0, %eax
1038 %cmp = icmp ult i32 %X, 2
1039 %cond = select i1 %cmp, i32 2, i32 3
1043 define i32 @select_ugt3_3_2(i32 %X) {
1044 ; X86-LABEL: select_ugt3_3_2:
1046 ; X86-NEXT: cmpl $4, {{[0-9]+}}(%esp)
1047 ; X86-NEXT: movl $2, %eax
1048 ; X86-NEXT: sbbl $-1, %eax
1051 ; X64-LABEL: select_ugt3_3_2:
1053 ; X64-NEXT: cmpl $4, %edi
1054 ; X64-NEXT: movl $2, %eax
1055 ; X64-NEXT: sbbl $-1, %eax
1057 %cmp.inv = icmp ugt i32 %X, 3
1058 %cond = select i1 %cmp.inv, i32 3, i32 2
1062 define i32 @select_eq_1_2(i32 %a, i32 %b) {
1063 ; X86-LABEL: select_eq_1_2:
1065 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
1066 ; X86-NEXT: xorl %eax, %eax
1067 ; X86-NEXT: cmpl {{[0-9]+}}(%esp), %ecx
1068 ; X86-NEXT: setne %al
1069 ; X86-NEXT: incl %eax
1072 ; X64-FASTINC-LABEL: select_eq_1_2:
1073 ; X64-FASTINC: # %bb.0:
1074 ; X64-FASTINC-NEXT: xorl %eax, %eax
1075 ; X64-FASTINC-NEXT: cmpl %esi, %edi
1076 ; X64-FASTINC-NEXT: setne %al
1077 ; X64-FASTINC-NEXT: incl %eax
1078 ; X64-FASTINC-NEXT: retq
1080 ; X64-SLOWINC-LABEL: select_eq_1_2:
1081 ; X64-SLOWINC: # %bb.0:
1082 ; X64-SLOWINC-NEXT: xorl %eax, %eax
1083 ; X64-SLOWINC-NEXT: cmpl %esi, %edi
1084 ; X64-SLOWINC-NEXT: setne %al
1085 ; X64-SLOWINC-NEXT: addl $1, %eax
1086 ; X64-SLOWINC-NEXT: retq
1088 %cmp = icmp eq i32 %a, %b
1089 %cond = select i1 %cmp, i32 1, i32 2