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: movl %edi, %ecx
198 ; CHECK-NEXT: andb $1, %cl
199 ; CHECK-NEXT: xorb $3, %cl
200 ; CHECK-NEXT: movl $1, %eax
201 ; CHECK-NEXT: # kill: def $cl killed $cl killed $ecx
202 ; CHECK-NEXT: shll %cl, %eax
204 %sel = select i1 %cond, i32 2, i32 3
205 %bo = shl i32 1, %sel
209 define i32 @lshr_constant_sel_constants(i1 %cond) {
210 ; CHECK-LABEL: lshr_constant_sel_constants:
212 ; CHECK-NEXT: movl %edi, %ecx
213 ; CHECK-NEXT: andb $1, %cl
214 ; CHECK-NEXT: xorb $3, %cl
215 ; CHECK-NEXT: movl $64, %eax
216 ; CHECK-NEXT: # kill: def $cl killed $cl killed $ecx
217 ; CHECK-NEXT: shrl %cl, %eax
219 %sel = select i1 %cond, i32 2, i32 3
220 %bo = lshr i32 64, %sel
224 define i32 @ashr_constant_sel_constants(i1 %cond) {
225 ; CHECK-LABEL: ashr_constant_sel_constants:
227 ; CHECK-NEXT: movl %edi, %ecx
228 ; CHECK-NEXT: andb $1, %cl
229 ; CHECK-NEXT: xorb $3, %cl
230 ; CHECK-NEXT: movl $128, %eax
231 ; CHECK-NEXT: # kill: def $cl killed $cl killed $ecx
232 ; CHECK-NEXT: shrl %cl, %eax
234 %sel = select i1 %cond, i32 2, i32 3
235 %bo = ashr i32 128, %sel
239 define double @fsub_constant_sel_constants(i1 %cond) {
240 ; CHECK-LABEL: fsub_constant_sel_constants:
242 ; CHECK-NEXT: testb $1, %dil
243 ; CHECK-NEXT: jne .LBB17_1
244 ; CHECK-NEXT: # %bb.2:
245 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
247 ; CHECK-NEXT: .LBB17_1:
248 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
250 %sel = select i1 %cond, double -4.0, double 23.3
251 %bo = fsub double 5.1, %sel
255 define double @fdiv_constant_sel_constants(i1 %cond) {
256 ; CHECK-LABEL: fdiv_constant_sel_constants:
258 ; CHECK-NEXT: testb $1, %dil
259 ; CHECK-NEXT: jne .LBB18_1
260 ; CHECK-NEXT: # %bb.2:
261 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
263 ; CHECK-NEXT: .LBB18_1:
264 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
266 %sel = select i1 %cond, double -4.0, double 23.3
267 %bo = fdiv double 5.1, %sel
271 define double @frem_constant_sel_constants(i1 %cond) {
272 ; CHECK-LABEL: frem_constant_sel_constants:
274 ; CHECK-NEXT: testb $1, %dil
275 ; CHECK-NEXT: jne .LBB19_1
276 ; CHECK-NEXT: # %bb.2:
277 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
279 ; CHECK-NEXT: .LBB19_1:
280 ; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
282 %sel = select i1 %cond, double -4.0, double 23.3
283 %bo = frem double 5.1, %sel
287 declare i64 @llvm.cttz.i64(i64, i1)
288 define i64 @cttz_64_eq_select(i64 %v) nounwind {
289 ; NOBMI-LABEL: cttz_64_eq_select:
291 ; NOBMI-NEXT: bsfq %rdi, %rcx
292 ; NOBMI-NEXT: movq $-1, %rax
293 ; NOBMI-NEXT: cmovneq %rcx, %rax
294 ; NOBMI-NEXT: addq $6, %rax
297 ; BMI-LABEL: cttz_64_eq_select:
299 ; BMI-NEXT: tzcntq %rdi, %rcx
300 ; BMI-NEXT: movq $-1, %rax
301 ; BMI-NEXT: cmovaeq %rcx, %rax
302 ; BMI-NEXT: addq $6, %rax
305 %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)
306 %tobool = icmp eq i64 %v, 0
307 %.op = add nuw nsw i64 %cnt, 6
308 %add = select i1 %tobool, i64 5, i64 %.op
312 define i64 @cttz_64_ne_select(i64 %v) nounwind {
313 ; NOBMI-LABEL: cttz_64_ne_select:
315 ; NOBMI-NEXT: bsfq %rdi, %rcx
316 ; NOBMI-NEXT: movq $-1, %rax
317 ; NOBMI-NEXT: cmovneq %rcx, %rax
318 ; NOBMI-NEXT: addq $6, %rax
321 ; BMI-LABEL: cttz_64_ne_select:
323 ; BMI-NEXT: tzcntq %rdi, %rcx
324 ; BMI-NEXT: movq $-1, %rax
325 ; BMI-NEXT: cmovaeq %rcx, %rax
326 ; BMI-NEXT: addq $6, %rax
329 %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)
330 %tobool = icmp ne i64 %v, 0
331 %.op = add nuw nsw i64 %cnt, 6
332 %add = select i1 %tobool, i64 %.op, i64 5
336 declare i32 @llvm.cttz.i32(i32, i1)
337 define i32 @cttz_32_eq_select(i32 %v) nounwind {
338 ; NOBMI-LABEL: cttz_32_eq_select:
340 ; NOBMI-NEXT: bsfl %edi, %ecx
341 ; NOBMI-NEXT: movl $-1, %eax
342 ; NOBMI-NEXT: cmovnel %ecx, %eax
343 ; NOBMI-NEXT: addl $6, %eax
346 ; BMI-LABEL: cttz_32_eq_select:
348 ; BMI-NEXT: tzcntl %edi, %ecx
349 ; BMI-NEXT: movl $-1, %eax
350 ; BMI-NEXT: cmovael %ecx, %eax
351 ; BMI-NEXT: addl $6, %eax
354 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
355 %tobool = icmp eq i32 %v, 0
356 %.op = add nuw nsw i32 %cnt, 6
357 %add = select i1 %tobool, i32 5, i32 %.op
361 define i32 @cttz_32_ne_select(i32 %v) nounwind {
362 ; NOBMI-LABEL: cttz_32_ne_select:
364 ; NOBMI-NEXT: bsfl %edi, %ecx
365 ; NOBMI-NEXT: movl $-1, %eax
366 ; NOBMI-NEXT: cmovnel %ecx, %eax
367 ; NOBMI-NEXT: addl $6, %eax
370 ; BMI-LABEL: cttz_32_ne_select:
372 ; BMI-NEXT: tzcntl %edi, %ecx
373 ; BMI-NEXT: movl $-1, %eax
374 ; BMI-NEXT: cmovael %ecx, %eax
375 ; BMI-NEXT: addl $6, %eax
378 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
379 %tobool = icmp ne i32 %v, 0
380 %.op = add nuw nsw i32 %cnt, 6
381 %add = select i1 %tobool, i32 %.op, i32 5
385 ; This matches the pattern emitted for __builtin_ffs
386 define i32 @cttz_32_eq_select_ffs(i32 %v) nounwind {
387 ; NOBMI-LABEL: cttz_32_eq_select_ffs:
389 ; NOBMI-NEXT: bsfl %edi, %ecx
390 ; NOBMI-NEXT: movl $-1, %eax
391 ; NOBMI-NEXT: cmovnel %ecx, %eax
392 ; NOBMI-NEXT: incl %eax
395 ; BMI-LABEL: cttz_32_eq_select_ffs:
397 ; BMI-NEXT: tzcntl %edi, %ecx
398 ; BMI-NEXT: movl $-1, %eax
399 ; BMI-NEXT: cmovael %ecx, %eax
400 ; BMI-NEXT: incl %eax
403 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
404 %tobool = icmp eq i32 %v, 0
405 %.op = add nuw nsw i32 %cnt, 1
406 %add = select i1 %tobool, i32 0, i32 %.op
410 define i32 @cttz_32_ne_select_ffs(i32 %v) nounwind {
411 ; NOBMI-LABEL: cttz_32_ne_select_ffs:
413 ; NOBMI-NEXT: bsfl %edi, %ecx
414 ; NOBMI-NEXT: movl $-1, %eax
415 ; NOBMI-NEXT: cmovnel %ecx, %eax
416 ; NOBMI-NEXT: incl %eax
419 ; BMI-LABEL: cttz_32_ne_select_ffs:
421 ; BMI-NEXT: tzcntl %edi, %ecx
422 ; BMI-NEXT: movl $-1, %eax
423 ; BMI-NEXT: cmovael %ecx, %eax
424 ; BMI-NEXT: incl %eax
427 %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)
428 %tobool = icmp ne i32 %v, 0
429 %.op = add nuw nsw i32 %cnt, 1
430 %add = select i1 %tobool, i32 %.op, i32 0