1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+cmov,+bmi | FileCheck %s --check-prefix=X86
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+cmov,+bmi | FileCheck %s --check-prefix=X64
5 define i32 @blsmsk_used2(i32 %a) nounwind {
6 ; X86-LABEL: blsmsk_used2:
7 ; X86: # %bb.0: # %entry
8 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
9 ; X86-NEXT: leal -1(%eax), %ecx
10 ; X86-NEXT: xorl %ecx, %eax
11 ; X86-NEXT: imull %ecx, %eax
14 ; X64-LABEL: blsmsk_used2:
15 ; X64: # %bb.0: # %entry
16 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
17 ; X64-NEXT: leal -1(%rdi), %eax
18 ; X64-NEXT: xorl %eax, %edi
19 ; X64-NEXT: imull %edi, %eax
23 %xor = xor i32 %sub, %a
24 %mul = mul i32 %xor, %sub
28 define i64 @blsmask_through1(i64 %a, i64 %b) nounwind {
29 ; X86-LABEL: blsmask_through1:
30 ; X86: # %bb.0: # %entry
31 ; X86-NEXT: pushl %esi
32 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
33 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
34 ; X86-NEXT: movl %ecx, %eax
35 ; X86-NEXT: addl $-1, %eax
36 ; X86-NEXT: movl %esi, %edx
37 ; X86-NEXT: adcl $-1, %edx
38 ; X86-NEXT: xorl {{[0-9]+}}(%esp), %edx
39 ; X86-NEXT: xorl {{[0-9]+}}(%esp), %eax
40 ; X86-NEXT: xorl %ecx, %eax
41 ; X86-NEXT: xorl %esi, %edx
45 ; X64-LABEL: blsmask_through1:
46 ; X64: # %bb.0: # %entry
47 ; X64-NEXT: blsmskq %rsi, %rax
48 ; X64-NEXT: xorq %rdi, %rax
53 %xor1 = xor i64 %0, %b
57 define i32 @blsmask_through2(i32 %a, i32 %b, i32 %c) nounwind {
58 ; X86-LABEL: blsmask_through2:
59 ; X86: # %bb.0: # %entry
60 ; X86-NEXT: blsmskl {{[0-9]+}}(%esp), %eax
61 ; X86-NEXT: xorl {{[0-9]+}}(%esp), %eax
62 ; X86-NEXT: xorl {{[0-9]+}}(%esp), %eax
65 ; X64-LABEL: blsmask_through2:
66 ; X64: # %bb.0: # %entry
67 ; X64-NEXT: blsmskl %esi, %eax
68 ; X64-NEXT: xorl %edx, %edi
69 ; X64-NEXT: xorl %edi, %eax
72 %sub = add nsw i32 %b, -1
75 %xor2 = xor i32 %1, %b
79 define i64 @blsmask_through3(i64 %a, i64 %b, i64 %c, i64 %d) nounwind {
80 ; X86-LABEL: blsmask_through3:
81 ; X86: # %bb.0: # %entry
82 ; X86-NEXT: pushl %esi
83 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
84 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
85 ; X86-NEXT: movl %esi, %eax
86 ; X86-NEXT: addl $-1, %eax
87 ; X86-NEXT: movl %ecx, %edx
88 ; X86-NEXT: adcl $-1, %edx
89 ; X86-NEXT: xorl {{[0-9]+}}(%esp), %edx
90 ; X86-NEXT: xorl {{[0-9]+}}(%esp), %eax
91 ; X86-NEXT: xorl {{[0-9]+}}(%esp), %edx
92 ; X86-NEXT: xorl {{[0-9]+}}(%esp), %eax
93 ; X86-NEXT: xorl {{[0-9]+}}(%esp), %edx
94 ; X86-NEXT: xorl {{[0-9]+}}(%esp), %eax
95 ; X86-NEXT: xorl %esi, %eax
96 ; X86-NEXT: xorl %ecx, %edx
100 ; X64-LABEL: blsmask_through3:
101 ; X64: # %bb.0: # %entry
102 ; X64-NEXT: leaq -1(%rsi), %rax
103 ; X64-NEXT: xorq %rdx, %rdi
104 ; X64-NEXT: xorq %rdi, %rax
105 ; X64-NEXT: xorq %rsi, %rcx
106 ; X64-NEXT: xorq %rcx, %rax
109 %sub = add nsw i64 %b, -1
110 %0 = xor i64 %sub, %a
113 %xor3 = xor i64 %2, %b
117 define i32 @blsmask_through1_used1(i32 %a, i32 %b) nounwind {
118 ; X86-LABEL: blsmask_through1_used1:
119 ; X86: # %bb.0: # %entry
120 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
121 ; X86-NEXT: leal -1(%ecx), %eax
122 ; X86-NEXT: xorl {{[0-9]+}}(%esp), %eax
123 ; X86-NEXT: xorl %eax, %ecx
124 ; X86-NEXT: incl %eax
125 ; X86-NEXT: orl %ecx, %eax
128 ; X64-LABEL: blsmask_through1_used1:
129 ; X64: # %bb.0: # %entry
130 ; X64-NEXT: # kill: def $esi killed $esi def $rsi
131 ; X64-NEXT: leal -1(%rsi), %eax
132 ; X64-NEXT: xorl %edi, %eax
133 ; X64-NEXT: xorl %eax, %esi
134 ; X64-NEXT: incl %eax
135 ; X64-NEXT: orl %esi, %eax
138 %sub = add i32 %b, -1
139 %xor = xor i32 %sub, %a
140 %xor1 = xor i32 %xor, %b
141 %add = add i32 %xor, 1
142 %or = or i32 %add, %xor1
146 define i64 @blsmask_through1_used2(i64 %a, i64 %b) nounwind {
147 ; X86-LABEL: blsmask_through1_used2:
148 ; X86: # %bb.0: # %entry
149 ; X86-NEXT: pushl %ebp
150 ; X86-NEXT: pushl %ebx
151 ; X86-NEXT: pushl %edi
152 ; X86-NEXT: pushl %esi
153 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
154 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
155 ; X86-NEXT: movl %ecx, %edi
156 ; X86-NEXT: addl $-1, %edi
157 ; X86-NEXT: movl %esi, %ebp
158 ; X86-NEXT: adcl $-1, %ebp
159 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ebx
160 ; X86-NEXT: xorl %ebp, %ebx
161 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
162 ; X86-NEXT: xorl %edi, %eax
163 ; X86-NEXT: xorl %ebx, %esi
164 ; X86-NEXT: xorl %eax, %ecx
165 ; X86-NEXT: imull %eax, %ebp
166 ; X86-NEXT: mull %edi
167 ; X86-NEXT: addl %ebp, %edx
168 ; X86-NEXT: imull %edi, %ebx
169 ; X86-NEXT: addl %ebx, %edx
170 ; X86-NEXT: orl %esi, %edx
171 ; X86-NEXT: orl %ecx, %eax
172 ; X86-NEXT: popl %esi
173 ; X86-NEXT: popl %edi
174 ; X86-NEXT: popl %ebx
175 ; X86-NEXT: popl %ebp
178 ; X64-LABEL: blsmask_through1_used2:
179 ; X64: # %bb.0: # %entry
180 ; X64-NEXT: leaq -1(%rsi), %rax
181 ; X64-NEXT: xorq %rax, %rdi
182 ; X64-NEXT: xorq %rdi, %rsi
183 ; X64-NEXT: imulq %rdi, %rax
184 ; X64-NEXT: orq %rsi, %rax
187 %sub = add i64 %b, -1
188 %xor = xor i64 %sub, %a
189 %xor1 = xor i64 %xor, %b
190 %mul = mul i64 %xor, %sub
191 %or = or i64 %mul, %xor1
195 define i32 @blsi_used2(i32 %a) nounwind {
196 ; X86-LABEL: blsi_used2:
197 ; X86: # %bb.0: # %entry
198 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
199 ; X86-NEXT: movl %eax, %ecx
200 ; X86-NEXT: negl %ecx
201 ; X86-NEXT: andl %ecx, %eax
202 ; X86-NEXT: imull %ecx, %eax
205 ; X64-LABEL: blsi_used2:
206 ; X64: # %bb.0: # %entry
207 ; X64-NEXT: movl %edi, %eax
208 ; X64-NEXT: negl %eax
209 ; X64-NEXT: andl %eax, %edi
210 ; X64-NEXT: imull %edi, %eax
213 %sub = sub nsw i32 0, %a
214 %and = and i32 %sub, %a
215 %mul = mul nsw i32 %and, %sub
219 define i64 @blsi_through1(i64 %a, i64 %b) nounwind {
220 ; X86-LABEL: blsi_through1:
221 ; X86: # %bb.0: # %entry
222 ; X86-NEXT: pushl %esi
223 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
224 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
225 ; X86-NEXT: xorl %edx, %edx
226 ; X86-NEXT: movl %ecx, %eax
227 ; X86-NEXT: negl %eax
228 ; X86-NEXT: sbbl %esi, %edx
229 ; X86-NEXT: andl {{[0-9]+}}(%esp), %edx
230 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
231 ; X86-NEXT: andl %esi, %edx
232 ; X86-NEXT: andl %ecx, %eax
233 ; X86-NEXT: popl %esi
236 ; X64-LABEL: blsi_through1:
237 ; X64: # %bb.0: # %entry
238 ; X64-NEXT: blsiq %rsi, %rax
239 ; X64-NEXT: andq %rdi, %rax
242 %sub = sub nsw i64 0, %b
243 %and = and i64 %sub, %a
244 %and1 = and i64 %and, %b
248 define i32 @blsi_through2(i32 %a, i32 %b, i32 %c) nounwind {
249 ; X86-LABEL: blsi_through2:
250 ; X86: # %bb.0: # %entry
251 ; X86-NEXT: blsil {{[0-9]+}}(%esp), %eax
252 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
253 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
256 ; X64-LABEL: blsi_through2:
257 ; X64: # %bb.0: # %entry
258 ; X64-NEXT: blsil %esi, %eax
259 ; X64-NEXT: andl %edx, %edi
260 ; X64-NEXT: andl %edi, %eax
264 %and = and i32 %sub, %a
265 %0 = and i32 %and, %c
266 %and2 = and i32 %0, %b
270 define i64 @blsi_through3(i64 %a, i64 %b, i64 %c) nounwind {
271 ; X86-LABEL: blsi_through3:
272 ; X86: # %bb.0: # %entry
273 ; X86-NEXT: pushl %esi
274 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
275 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
276 ; X86-NEXT: xorl %edx, %edx
277 ; X86-NEXT: movl %ecx, %eax
278 ; X86-NEXT: negl %eax
279 ; X86-NEXT: sbbl %esi, %edx
280 ; X86-NEXT: andl {{[0-9]+}}(%esp), %edx
281 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
282 ; X86-NEXT: andl {{[0-9]+}}(%esp), %edx
283 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
284 ; X86-NEXT: andl %esi, %edx
285 ; X86-NEXT: andl %ecx, %eax
286 ; X86-NEXT: popl %esi
289 ; X64-LABEL: blsi_through3:
290 ; X64: # %bb.0: # %entry
291 ; X64-NEXT: blsiq %rsi, %rax
292 ; X64-NEXT: andq %rdx, %rdi
293 ; X64-NEXT: andq %rdi, %rax
297 %and = and i64 %sub, %a
298 %0 = and i64 %and, %c
299 %and3 = and i64 %0, %b
303 define i32 @blsi_through1_used1(i32 %a, i32 %b) nounwind {
304 ; X86-LABEL: blsi_through1_used1:
305 ; X86: # %bb.0: # %entry
306 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
307 ; X86-NEXT: movl %ecx, %eax
308 ; X86-NEXT: negl %eax
309 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
310 ; X86-NEXT: andl %eax, %ecx
311 ; X86-NEXT: incl %eax
312 ; X86-NEXT: orl %ecx, %eax
315 ; X64-LABEL: blsi_through1_used1:
316 ; X64: # %bb.0: # %entry
317 ; X64-NEXT: movl %esi, %eax
318 ; X64-NEXT: negl %eax
319 ; X64-NEXT: andl %edi, %eax
320 ; X64-NEXT: andl %eax, %esi
321 ; X64-NEXT: incl %eax
322 ; X64-NEXT: orl %esi, %eax
325 %sub = sub nsw i32 0, %b
326 %and = and i32 %sub, %a
327 %and1 = and i32 %and, %b
328 %add = add nsw i32 %and, 1
329 %or = or i32 %add, %and1
333 define i64 @blsi_through1_used2(i64 %a, i64 %b) nounwind {
334 ; X86-LABEL: blsi_through1_used2:
335 ; X86: # %bb.0: # %entry
336 ; X86-NEXT: pushl %ebx
337 ; X86-NEXT: pushl %edi
338 ; X86-NEXT: pushl %esi
339 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
340 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
341 ; X86-NEXT: xorl %edi, %edi
342 ; X86-NEXT: movl %ecx, %edx
343 ; X86-NEXT: negl %edx
344 ; X86-NEXT: sbbl %esi, %edi
345 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ebx
346 ; X86-NEXT: andl %edi, %ebx
347 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
348 ; X86-NEXT: andl %edx, %eax
349 ; X86-NEXT: andl %ebx, %esi
350 ; X86-NEXT: andl %eax, %ecx
351 ; X86-NEXT: imull %edx, %ebx
352 ; X86-NEXT: imull %eax, %edi
353 ; X86-NEXT: mull %edx
354 ; X86-NEXT: addl %edi, %edx
355 ; X86-NEXT: addl %ebx, %edx
356 ; X86-NEXT: orl %esi, %edx
357 ; X86-NEXT: orl %ecx, %eax
358 ; X86-NEXT: popl %esi
359 ; X86-NEXT: popl %edi
360 ; X86-NEXT: popl %ebx
363 ; X64-LABEL: blsi_through1_used2:
364 ; X64: # %bb.0: # %entry
365 ; X64-NEXT: movq %rsi, %rax
366 ; X64-NEXT: negq %rax
367 ; X64-NEXT: andq %rax, %rdi
368 ; X64-NEXT: andq %rdi, %rsi
369 ; X64-NEXT: imulq %rdi, %rax
370 ; X64-NEXT: orq %rsi, %rax
373 %sub = sub nsw i64 0, %b
374 %and = and i64 %sub, %a
375 %and1 = and i64 %and, %b
376 %mul = mul nsw i64 %and, %sub
377 %or = or i64 %mul, %and1
381 define i32 @blsr_used2(i32 %a) nounwind {
382 ; X86-LABEL: blsr_used2:
383 ; X86: # %bb.0: # %entry
384 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
385 ; X86-NEXT: leal -1(%eax), %ecx
386 ; X86-NEXT: andl %ecx, %eax
387 ; X86-NEXT: imull %ecx, %eax
390 ; X64-LABEL: blsr_used2:
391 ; X64: # %bb.0: # %entry
392 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
393 ; X64-NEXT: leal -1(%rdi), %eax
394 ; X64-NEXT: andl %eax, %edi
395 ; X64-NEXT: imull %edi, %eax
398 %sub = add i32 %a, -1
399 %and = and i32 %sub, %a
400 %mul = mul i32 %and, %sub
404 define i64 @blsr_through1(i64 %a, i64 %b) nounwind {
405 ; X86-LABEL: blsr_through1:
406 ; X86: # %bb.0: # %entry
407 ; X86-NEXT: pushl %esi
408 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
409 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
410 ; X86-NEXT: movl %ecx, %eax
411 ; X86-NEXT: addl $-1, %eax
412 ; X86-NEXT: movl %esi, %edx
413 ; X86-NEXT: adcl $-1, %edx
414 ; X86-NEXT: andl {{[0-9]+}}(%esp), %edx
415 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
416 ; X86-NEXT: andl %ecx, %eax
417 ; X86-NEXT: andl %esi, %edx
418 ; X86-NEXT: popl %esi
421 ; X64-LABEL: blsr_through1:
422 ; X64: # %bb.0: # %entry
423 ; X64-NEXT: blsrq %rsi, %rax
424 ; X64-NEXT: andq %rdi, %rax
427 %sub = add i64 %b, -1
428 %0 = and i64 %sub, %a
429 %and1 = and i64 %0, %b
433 define i32 @blsr_through2(i32 %a, i32 %b, i32 %c) nounwind {
434 ; X86-LABEL: blsr_through2:
435 ; X86: # %bb.0: # %entry
436 ; X86-NEXT: blsrl {{[0-9]+}}(%esp), %eax
437 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
438 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
441 ; X64-LABEL: blsr_through2:
442 ; X64: # %bb.0: # %entry
443 ; X64-NEXT: blsrl %esi, %eax
444 ; X64-NEXT: andl %edx, %edi
445 ; X64-NEXT: andl %edi, %eax
448 %sub = add nsw i32 %b, -1
449 %0 = and i32 %sub, %a
451 %and2 = and i32 %1, %b
455 define i64 @blsr_through3(i64 %a, i64 %b, i64 %c, i64 %d) nounwind {
456 ; X86-LABEL: blsr_through3:
457 ; X86: # %bb.0: # %entry
458 ; X86-NEXT: pushl %esi
459 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
460 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
461 ; X86-NEXT: xorl %edx, %edx
462 ; X86-NEXT: movl %ecx, %eax
463 ; X86-NEXT: negl %eax
464 ; X86-NEXT: sbbl %esi, %edx
465 ; X86-NEXT: andl {{[0-9]+}}(%esp), %edx
466 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
467 ; X86-NEXT: andl {{[0-9]+}}(%esp), %edx
468 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
469 ; X86-NEXT: andl {{[0-9]+}}(%esp), %edx
470 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
471 ; X86-NEXT: andl %esi, %edx
472 ; X86-NEXT: andl %ecx, %eax
473 ; X86-NEXT: popl %esi
476 ; X64-LABEL: blsr_through3:
477 ; X64: # %bb.0: # %entry
478 ; X64-NEXT: movq %rdi, %rax
479 ; X64-NEXT: andq %rsi, %rcx
480 ; X64-NEXT: negq %rsi
481 ; X64-NEXT: andq %rdx, %rax
482 ; X64-NEXT: andq %rsi, %rax
483 ; X64-NEXT: andq %rcx, %rax
486 %sub = sub nsw i64 0, %b
487 %and = and i64 %sub, %a
488 %0 = and i64 %and, %c
490 %and4 = and i64 %1, %b
494 define i32 @blsr_through1_used1(i32 %a, i32 %b) nounwind {
495 ; X86-LABEL: blsr_through1_used1:
496 ; X86: # %bb.0: # %entry
497 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
498 ; X86-NEXT: leal -1(%ecx), %eax
499 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
500 ; X86-NEXT: andl %eax, %ecx
501 ; X86-NEXT: incl %eax
502 ; X86-NEXT: orl %ecx, %eax
505 ; X64-LABEL: blsr_through1_used1:
506 ; X64: # %bb.0: # %entry
507 ; X64-NEXT: # kill: def $esi killed $esi def $rsi
508 ; X64-NEXT: leal -1(%rsi), %eax
509 ; X64-NEXT: andl %edi, %eax
510 ; X64-NEXT: andl %eax, %esi
511 ; X64-NEXT: incl %eax
512 ; X64-NEXT: orl %esi, %eax
515 %sub = add i32 %b, -1
516 %and = and i32 %sub, %a
517 %and1 = and i32 %and, %b
518 %add = add i32 %and, 1
519 %or = or i32 %add, %and1
523 define i64 @blsr_through1_used2(i64 %a, i64 %b) nounwind {
524 ; X86-LABEL: blsr_through1_used2:
525 ; X86: # %bb.0: # %entry
526 ; X86-NEXT: pushl %ebp
527 ; X86-NEXT: pushl %ebx
528 ; X86-NEXT: pushl %edi
529 ; X86-NEXT: pushl %esi
530 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
531 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
532 ; X86-NEXT: movl %ecx, %edi
533 ; X86-NEXT: addl $-1, %edi
534 ; X86-NEXT: movl %esi, %ebp
535 ; X86-NEXT: adcl $-1, %ebp
536 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ebx
537 ; X86-NEXT: andl %ebp, %ebx
538 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
539 ; X86-NEXT: andl %edi, %eax
540 ; X86-NEXT: andl %ebx, %esi
541 ; X86-NEXT: andl %eax, %ecx
542 ; X86-NEXT: imull %eax, %ebp
543 ; X86-NEXT: mull %edi
544 ; X86-NEXT: addl %ebp, %edx
545 ; X86-NEXT: imull %edi, %ebx
546 ; X86-NEXT: addl %ebx, %edx
547 ; X86-NEXT: orl %esi, %edx
548 ; X86-NEXT: orl %ecx, %eax
549 ; X86-NEXT: popl %esi
550 ; X86-NEXT: popl %edi
551 ; X86-NEXT: popl %ebx
552 ; X86-NEXT: popl %ebp
555 ; X64-LABEL: blsr_through1_used2:
556 ; X64: # %bb.0: # %entry
557 ; X64-NEXT: leaq -1(%rsi), %rax
558 ; X64-NEXT: andq %rax, %rdi
559 ; X64-NEXT: andq %rdi, %rsi
560 ; X64-NEXT: imulq %rdi, %rax
561 ; X64-NEXT: orq %rsi, %rax
564 %sub = add i64 %b, -1
565 %and = and i64 %sub, %a
566 %and1 = and i64 %and, %b
567 %mul = mul i64 %and, %sub
568 %or = or i64 %mul, %and1