1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,NOBMI -enable-var-scope
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -verify-machineinstrs -mattr=+bmi | FileCheck %s -check-prefixes=CHECK,BMI -enable-var-scope
5 define i32 @select_and1(i32 %x, i32 %y) {
6 ; CHECK-LABEL: select_and1:
8 ; CHECK-NEXT: xorl %eax, %eax
9 ; CHECK-NEXT: cmpl $11, %edi
10 ; CHECK-NEXT: cmovgel %esi, %eax
12 %c = icmp slt i32 %x, 11
13 %s = select i1 %c, i32 0, i32 -1
18 define i32 @select_and2(i32 %x, i32 %y) {
19 ; CHECK-LABEL: select_and2:
21 ; CHECK-NEXT: xorl %eax, %eax
22 ; CHECK-NEXT: cmpl $11, %edi
23 ; CHECK-NEXT: cmovgel %esi, %eax
25 %c = icmp slt i32 %x, 11
26 %s = select i1 %c, i32 0, i32 -1
31 define i32 @select_and3(i32 %x, i32 %y) {
32 ; CHECK-LABEL: select_and3:
34 ; CHECK-NEXT: xorl %eax, %eax
35 ; CHECK-NEXT: cmpl $11, %edi
36 ; CHECK-NEXT: cmovll %esi, %eax
38 %c = icmp slt i32 %x, 11
39 %s = select i1 %c, i32 -1, i32 0
44 define <4 x i32> @select_and_v4(i32 %x, <4 x i32> %y) {
45 ; CHECK-LABEL: select_and_v4:
47 ; CHECK-NEXT: cmpl $11, %edi
48 ; CHECK-NEXT: xorps %xmm1, %xmm1
49 ; CHECK-NEXT: jl .LBB3_2
50 ; CHECK-NEXT: # %bb.1:
51 ; CHECK-NEXT: movaps %xmm0, %xmm1
52 ; CHECK-NEXT: .LBB3_2:
53 ; CHECK-NEXT: movaps %xmm1, %xmm0
55 %c = icmp slt i32 %x, 11
56 %s = select i1 %c, <4 x i32> zeroinitializer, <4 x i32><i32 -1, i32 -1, i32 -1, i32 -1>
57 %a = and <4 x i32> %s, %y
61 define i32 @select_or1(i32 %x, i32 %y) {
62 ; CHECK-LABEL: select_or1:
64 ; CHECK-NEXT: cmpl $11, %edi
65 ; CHECK-NEXT: movl $-1, %eax
66 ; CHECK-NEXT: cmovll %esi, %eax
68 %c = icmp slt i32 %x, 11
69 %s = select i1 %c, i32 0, i32 -1
74 define i32 @select_or2(i32 %x, i32 %y) {
75 ; CHECK-LABEL: select_or2:
77 ; CHECK-NEXT: cmpl $11, %edi
78 ; CHECK-NEXT: movl $-1, %eax
79 ; CHECK-NEXT: cmovll %esi, %eax
81 %c = icmp slt i32 %x, 11
82 %s = select i1 %c, i32 0, i32 -1
87 define i32 @select_or3(i32 %x, i32 %y) {
88 ; CHECK-LABEL: select_or3:
90 ; CHECK-NEXT: cmpl $11, %edi
91 ; CHECK-NEXT: movl $-1, %eax
92 ; CHECK-NEXT: cmovgel %esi, %eax
94 %c = icmp slt i32 %x, 11
95 %s = select i1 %c, i32 -1, i32 0
100 define <4 x i32> @select_or_v4(i32 %x, <4 x i32> %y) {
101 ; CHECK-LABEL: select_or_v4:
103 ; CHECK-NEXT: cmpl $11, %edi
104 ; CHECK-NEXT: jl .LBB7_2
105 ; CHECK-NEXT: # %bb.1:
106 ; CHECK-NEXT: pcmpeqd %xmm0, %xmm0
107 ; CHECK-NEXT: .LBB7_2:
109 %c = icmp slt i32 %x, 11
110 %s = select i1 %c, <4 x i32> zeroinitializer, <4 x i32><i32 -1, i32 -1, i32 -1, i32 -1>
111 %a = or <4 x i32> %s, %y
115 define i32 @sel_constants_sub_constant_sel_constants(i1 %cond) {
116 ; CHECK-LABEL: sel_constants_sub_constant_sel_constants:
118 ; CHECK-NEXT: testb $1, %dil
119 ; CHECK-NEXT: movl $9, %ecx
120 ; CHECK-NEXT: movl $2, %eax
121 ; CHECK-NEXT: cmovnel %ecx, %eax
123 %sel = select i1 %cond, i32 -4, i32 3
124 %bo = sub i32 5, %sel
128 define i32 @sdiv_constant_sel_constants(i1 %cond) {
129 ; CHECK-LABEL: sdiv_constant_sel_constants:
131 ; CHECK-NEXT: notb %dil
132 ; CHECK-NEXT: movzbl %dil, %eax
133 ; CHECK-NEXT: andl $1, %eax
134 ; CHECK-NEXT: leal (%rax,%rax,4), %eax
136 %sel = select i1 %cond, i32 121, i32 23
137 %bo = sdiv i32 120, %sel
141 define i32 @udiv_constant_sel_constants(i1 %cond) {
142 ; CHECK-LABEL: udiv_constant_sel_constants:
144 ; CHECK-NEXT: notb %dil
145 ; CHECK-NEXT: movzbl %dil, %eax
146 ; CHECK-NEXT: andl $1, %eax
147 ; CHECK-NEXT: leal (%rax,%rax,4), %eax
149 %sel = select i1 %cond, i32 -4, i32 23
150 %bo = udiv i32 120, %sel
154 define i32 @srem_constant_sel_constants(i1 %cond) {
155 ; CHECK-LABEL: srem_constant_sel_constants:
157 ; CHECK-NEXT: testb $1, %dil
158 ; CHECK-NEXT: movl $120, %ecx
159 ; CHECK-NEXT: movl $5, %eax
160 ; CHECK-NEXT: cmovnel %ecx, %eax
162 %sel = select i1 %cond, i32 121, i32 23
163 %bo = srem i32 120, %sel
167 define i32 @urem_constant_sel_constants(i1 %cond) {
168 ; CHECK-LABEL: urem_constant_sel_constants:
170 ; CHECK-NEXT: testb $1, %dil
171 ; CHECK-NEXT: movl $120, %ecx
172 ; CHECK-NEXT: movl $5, %eax
173 ; CHECK-NEXT: cmovnel %ecx, %eax
175 %sel = select i1 %cond, i32 -4, i32 23
176 %bo = urem i32 120, %sel
180 define i32 @sel_constants_shl_constant(i1 %cond) {
181 ; CHECK-LABEL: sel_constants_shl_constant:
183 ; CHECK-NEXT: notb %dil
184 ; CHECK-NEXT: movzbl %dil, %eax
185 ; CHECK-NEXT: andl $1, %eax
186 ; CHECK-NEXT: orl $2, %eax
187 ; CHECK-NEXT: shll $8, %eax
189 %sel = select i1 %cond, i32 2, i32 3
190 %bo = shl i32 %sel, 8
194 define i32 @shl_constant_sel_constants(i1 %cond) {
195 ; CHECK-LABEL: shl_constant_sel_constants:
197 ; CHECK-NEXT: notb %dil
198 ; CHECK-NEXT: movzbl %dil, %eax
199 ; CHECK-NEXT: andl $1, %eax
200 ; CHECK-NEXT: leal 4(,%rax,4), %eax
202 %sel = select i1 %cond, i32 2, i32 3
203 %bo = shl i32 1, %sel
207 define i32 @shl_constant_sel_setcc(i32 %a) {
208 ; CHECK-LABEL: shl_constant_sel_setcc:
210 ; CHECK-NEXT: xorl %eax, %eax
211 ; CHECK-NEXT: testb $1, %dil
212 ; CHECK-NEXT: sete %al
213 ; CHECK-NEXT: leal 4(,%rax,4), %eax
216 %cond = icmp ne i32 %m, 0
217 %sel = select i1 %cond, i32 2, i32 3
218 %bo = shl i32 1, %sel
222 define i32 @lshr_constant_sel_constants(i1 %cond) {
223 ; CHECK-LABEL: lshr_constant_sel_constants:
225 ; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
226 ; CHECK-NEXT: andl $1, %edi
227 ; CHECK-NEXT: leal 8(,%rdi,8), %eax
229 %sel = select i1 %cond, i32 2, i32 3
230 %bo = lshr i32 64, %sel
234 define i32 @lshr_constant_sel_setcc(i32 %a) {
235 ; CHECK-LABEL: lshr_constant_sel_setcc:
237 ; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
238 ; CHECK-NEXT: andl $1, %edi
239 ; CHECK-NEXT: leal 8(,%rdi,8), %eax
242 %cond = icmp ne i32 %m, 0
243 %sel = select i1 %cond, i32 2, i32 3
244 %bo = lshr i32 64, %sel
248 define i32 @ashr_constant_sel_constants(i1 %cond) {
249 ; CHECK-LABEL: ashr_constant_sel_constants:
251 ; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
252 ; CHECK-NEXT: andl $1, %edi
253 ; CHECK-NEXT: shll $4, %edi
254 ; CHECK-NEXT: leal 16(%rdi), %eax
256 %sel = select i1 %cond, i32 2, i32 3
257 %bo = ashr i32 128, %sel
261 define i32 @ashr_constant_sel_setcc(i32 %a) {
262 ; CHECK-LABEL: ashr_constant_sel_setcc:
264 ; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
265 ; CHECK-NEXT: andl $1, %edi
266 ; CHECK-NEXT: shll $4, %edi
267 ; CHECK-NEXT: leal 16(%rdi), %eax
270 %cond = icmp ne i32 %m, 0
271 %sel = select i1 %cond, i32 2, i32 3
272 %bo = ashr i32 128, %sel
276 define double @fsub_constant_sel_constants(i1 %cond) {
277 ; CHECK-LABEL: fsub_constant_sel_constants:
279 ; CHECK-NEXT: testb $1, %dil
280 ; CHECK-NEXT: jne .LBB20_1
281 ; CHECK-NEXT: # %bb.2:
282 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
284 ; CHECK-NEXT: .LBB20_1:
285 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
287 %sel = select i1 %cond, double -4.0, double 23.3
288 %bo = fsub double 5.1, %sel
292 define double @fdiv_constant_sel_constants(i1 %cond) {
293 ; CHECK-LABEL: fdiv_constant_sel_constants:
295 ; CHECK-NEXT: testb $1, %dil
296 ; CHECK-NEXT: jne .LBB21_1
297 ; CHECK-NEXT: # %bb.2:
298 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
300 ; CHECK-NEXT: .LBB21_1:
301 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
303 %sel = select i1 %cond, double -4.0, double 23.3
304 %bo = fdiv double 5.1, %sel
308 define double @frem_constant_sel_constants(i1 %cond) {
309 ; CHECK-LABEL: frem_constant_sel_constants:
311 ; CHECK-NEXT: testb $1, %dil
312 ; CHECK-NEXT: jne .LBB22_1
313 ; CHECK-NEXT: # %bb.2:
314 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
316 ; CHECK-NEXT: .LBB22_1:
317 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
319 %sel = select i1 %cond, double -4.0, double 23.3
320 %bo = frem double 5.1, %sel
324 declare i64 @llvm.cttz.i64(i64, i1)
325 define i64 @cttz_64_eq_select(i64 %v) nounwind {
326 ; NOBMI-LABEL: cttz_64_eq_select:
328 ; NOBMI-NEXT: bsfq %rdi, %rcx
329 ; NOBMI-NEXT: movq $-1, %rax
330 ; NOBMI-NEXT: cmovneq %rcx, %rax
331 ; NOBMI-NEXT: addq $6, %rax
334 ; BMI-LABEL: cttz_64_eq_select:
336 ; BMI-NEXT: tzcntq %rdi, %rcx
337 ; BMI-NEXT: movq $-1, %rax
338 ; BMI-NEXT: cmovaeq %rcx, %rax
339 ; BMI-NEXT: addq $6, %rax
342 %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)
343 %tobool = icmp eq i64 %v, 0
344 %.op = add nuw nsw i64 %cnt, 6
345 %add = select i1 %tobool, i64 5, i64 %.op
349 define i64 @cttz_64_ne_select(i64 %v) nounwind {
350 ; NOBMI-LABEL: cttz_64_ne_select:
352 ; NOBMI-NEXT: bsfq %rdi, %rcx
353 ; NOBMI-NEXT: movq $-1, %rax
354 ; NOBMI-NEXT: cmovneq %rcx, %rax
355 ; NOBMI-NEXT: addq $6, %rax
358 ; BMI-LABEL: cttz_64_ne_select:
360 ; BMI-NEXT: tzcntq %rdi, %rcx
361 ; BMI-NEXT: movq $-1, %rax
362 ; BMI-NEXT: cmovaeq %rcx, %rax
363 ; BMI-NEXT: addq $6, %rax
366 %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)
367 %tobool = icmp ne i64 %v, 0
368 %.op = add nuw nsw i64 %cnt, 6
369 %add = select i1 %tobool, i64 %.op, i64 5
373 declare i32 @llvm.cttz.i32(i32, i1)
374 define i32 @cttz_32_eq_select(i32 %v) nounwind {
375 ; NOBMI-LABEL: cttz_32_eq_select:
377 ; NOBMI-NEXT: bsfl %edi, %ecx
378 ; NOBMI-NEXT: movl $-1, %eax
379 ; NOBMI-NEXT: cmovnel %ecx, %eax
380 ; NOBMI-NEXT: addl $6, %eax
383 ; BMI-LABEL: cttz_32_eq_select:
385 ; BMI-NEXT: tzcntl %edi, %ecx
386 ; BMI-NEXT: movl $-1, %eax
387 ; BMI-NEXT: cmovael %ecx, %eax
388 ; BMI-NEXT: addl $6, %eax
391 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
392 %tobool = icmp eq i32 %v, 0
393 %.op = add nuw nsw i32 %cnt, 6
394 %add = select i1 %tobool, i32 5, i32 %.op
398 define i32 @cttz_32_ne_select(i32 %v) nounwind {
399 ; NOBMI-LABEL: cttz_32_ne_select:
401 ; NOBMI-NEXT: bsfl %edi, %ecx
402 ; NOBMI-NEXT: movl $-1, %eax
403 ; NOBMI-NEXT: cmovnel %ecx, %eax
404 ; NOBMI-NEXT: addl $6, %eax
407 ; BMI-LABEL: cttz_32_ne_select:
409 ; BMI-NEXT: tzcntl %edi, %ecx
410 ; BMI-NEXT: movl $-1, %eax
411 ; BMI-NEXT: cmovael %ecx, %eax
412 ; BMI-NEXT: addl $6, %eax
415 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
416 %tobool = icmp ne i32 %v, 0
417 %.op = add nuw nsw i32 %cnt, 6
418 %add = select i1 %tobool, i32 %.op, i32 5
422 ; This matches the pattern emitted for __builtin_ffs
423 define i32 @cttz_32_eq_select_ffs(i32 %v) nounwind {
424 ; NOBMI-LABEL: cttz_32_eq_select_ffs:
426 ; NOBMI-NEXT: bsfl %edi, %ecx
427 ; NOBMI-NEXT: movl $-1, %eax
428 ; NOBMI-NEXT: cmovnel %ecx, %eax
429 ; NOBMI-NEXT: incl %eax
432 ; BMI-LABEL: cttz_32_eq_select_ffs:
434 ; BMI-NEXT: tzcntl %edi, %ecx
435 ; BMI-NEXT: movl $-1, %eax
436 ; BMI-NEXT: cmovael %ecx, %eax
437 ; BMI-NEXT: incl %eax
440 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
441 %tobool = icmp eq i32 %v, 0
442 %.op = add nuw nsw i32 %cnt, 1
443 %add = select i1 %tobool, i32 0, i32 %.op
447 define i32 @cttz_32_ne_select_ffs(i32 %v) nounwind {
448 ; NOBMI-LABEL: cttz_32_ne_select_ffs:
450 ; NOBMI-NEXT: bsfl %edi, %ecx
451 ; NOBMI-NEXT: movl $-1, %eax
452 ; NOBMI-NEXT: cmovnel %ecx, %eax
453 ; NOBMI-NEXT: incl %eax
456 ; BMI-LABEL: cttz_32_ne_select_ffs:
458 ; BMI-NEXT: tzcntl %edi, %ecx
459 ; BMI-NEXT: movl $-1, %eax
460 ; BMI-NEXT: cmovael %ecx, %eax
461 ; BMI-NEXT: incl %eax
464 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
465 %tobool = icmp ne i32 %v, 0
466 %.op = add nuw nsw i32 %cnt, 1
467 %add = select i1 %tobool, i32 %.op, i32 0
471 ; This matches the pattern emitted for __builtin_ffs - 1
472 define i32 @cttz_32_eq_select_ffs_m1(i32 %v) nounwind {
473 ; NOBMI-LABEL: cttz_32_eq_select_ffs_m1:
475 ; NOBMI-NEXT: bsfl %edi, %ecx
476 ; NOBMI-NEXT: movl $-1, %eax
477 ; NOBMI-NEXT: cmovnel %ecx, %eax
480 ; BMI-LABEL: cttz_32_eq_select_ffs_m1:
482 ; BMI-NEXT: tzcntl %edi, %ecx
483 ; BMI-NEXT: movl $-1, %eax
484 ; BMI-NEXT: cmovael %ecx, %eax
487 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
488 %tobool = icmp eq i32 %v, 0
489 %sel = select i1 %tobool, i32 -1, i32 %cnt
493 define i32 @cttz_32_ne_select_ffs_m1(i32 %v) nounwind {
494 ; NOBMI-LABEL: cttz_32_ne_select_ffs_m1:
496 ; NOBMI-NEXT: bsfl %edi, %ecx
497 ; NOBMI-NEXT: movl $-1, %eax
498 ; NOBMI-NEXT: cmovnel %ecx, %eax
501 ; BMI-LABEL: cttz_32_ne_select_ffs_m1:
503 ; BMI-NEXT: tzcntl %edi, %ecx
504 ; BMI-NEXT: movl $-1, %eax
505 ; BMI-NEXT: cmovael %ecx, %eax
508 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
509 %tobool = icmp ne i32 %v, 0
510 %sel = select i1 %tobool, i32 %cnt, i32 -1