1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s
4 define zeroext i1 @all_bits_clear(i32 %P, i32 %Q) nounwind {
5 ; CHECK-LABEL: all_bits_clear:
7 ; CHECK-NEXT: orl %esi, %edi
10 %a = icmp eq i32 %P, 0
11 %b = icmp eq i32 %Q, 0
16 define zeroext i1 @all_sign_bits_clear(i32 %P, i32 %Q) nounwind {
17 ; CHECK-LABEL: all_sign_bits_clear:
19 ; CHECK-NEXT: orl %esi, %edi
20 ; CHECK-NEXT: setns %al
22 %a = icmp sgt i32 %P, -1
23 %b = icmp sgt i32 %Q, -1
28 define zeroext i1 @all_bits_set(i32 %P, i32 %Q) nounwind {
29 ; CHECK-LABEL: all_bits_set:
31 ; CHECK-NEXT: andl %esi, %edi
32 ; CHECK-NEXT: cmpl $-1, %edi
33 ; CHECK-NEXT: sete %al
35 %a = icmp eq i32 %P, -1
36 %b = icmp eq i32 %Q, -1
41 define zeroext i1 @all_sign_bits_set(i32 %P, i32 %Q) nounwind {
42 ; CHECK-LABEL: all_sign_bits_set:
44 ; CHECK-NEXT: movl %edi, %eax
45 ; CHECK-NEXT: andl %esi, %eax
46 ; CHECK-NEXT: shrl $31, %eax
47 ; CHECK-NEXT: # kill: def $al killed $al killed $eax
49 %a = icmp slt i32 %P, 0
50 %b = icmp slt i32 %Q, 0
55 define zeroext i1 @any_bits_set(i32 %P, i32 %Q) nounwind {
56 ; CHECK-LABEL: any_bits_set:
58 ; CHECK-NEXT: orl %esi, %edi
59 ; CHECK-NEXT: setne %al
61 %a = icmp ne i32 %P, 0
62 %b = icmp ne i32 %Q, 0
67 define zeroext i1 @any_sign_bits_set(i32 %P, i32 %Q) nounwind {
68 ; CHECK-LABEL: any_sign_bits_set:
70 ; CHECK-NEXT: movl %edi, %eax
71 ; CHECK-NEXT: orl %esi, %eax
72 ; CHECK-NEXT: shrl $31, %eax
73 ; CHECK-NEXT: # kill: def $al killed $al killed $eax
75 %a = icmp slt i32 %P, 0
76 %b = icmp slt i32 %Q, 0
81 define zeroext i1 @any_bits_clear(i32 %P, i32 %Q) nounwind {
82 ; CHECK-LABEL: any_bits_clear:
84 ; CHECK-NEXT: andl %esi, %edi
85 ; CHECK-NEXT: cmpl $-1, %edi
86 ; CHECK-NEXT: setne %al
88 %a = icmp ne i32 %P, -1
89 %b = icmp ne i32 %Q, -1
94 define zeroext i1 @any_sign_bits_clear(i32 %P, i32 %Q) nounwind {
95 ; CHECK-LABEL: any_sign_bits_clear:
97 ; CHECK-NEXT: testl %esi, %edi
98 ; CHECK-NEXT: setns %al
100 %a = icmp sgt i32 %P, -1
101 %b = icmp sgt i32 %Q, -1
106 ; PR3351 - (P == 0) & (Q == 0) -> (P|Q) == 0
107 define i32 @all_bits_clear_branch(i32* %P, i32* %Q) nounwind {
108 ; CHECK-LABEL: all_bits_clear_branch:
109 ; CHECK: # %bb.0: # %entry
110 ; CHECK-NEXT: orq %rsi, %rdi
111 ; CHECK-NEXT: jne .LBB8_2
112 ; CHECK-NEXT: # %bb.1: # %bb1
113 ; CHECK-NEXT: movl $4, %eax
115 ; CHECK-NEXT: .LBB8_2: # %return
116 ; CHECK-NEXT: movl $192, %eax
119 %a = icmp eq i32* %P, null
120 %b = icmp eq i32* %Q, null
122 br i1 %c, label %bb1, label %return
131 define i32 @all_sign_bits_clear_branch(i32 %P, i32 %Q) nounwind {
132 ; CHECK-LABEL: all_sign_bits_clear_branch:
133 ; CHECK: # %bb.0: # %entry
134 ; CHECK-NEXT: testl %edi, %edi
135 ; CHECK-NEXT: js .LBB9_3
136 ; CHECK-NEXT: # %bb.1: # %entry
137 ; CHECK-NEXT: testl %esi, %esi
138 ; CHECK-NEXT: js .LBB9_3
139 ; CHECK-NEXT: # %bb.2: # %bb1
140 ; CHECK-NEXT: movl $4, %eax
142 ; CHECK-NEXT: .LBB9_3: # %return
143 ; CHECK-NEXT: movl $192, %eax
146 %a = icmp sgt i32 %P, -1
147 %b = icmp sgt i32 %Q, -1
149 br i1 %c, label %bb1, label %return
158 define i32 @all_bits_set_branch(i32 %P, i32 %Q) nounwind {
159 ; CHECK-LABEL: all_bits_set_branch:
160 ; CHECK: # %bb.0: # %entry
161 ; CHECK-NEXT: cmpl $-1, %edi
162 ; CHECK-NEXT: jne .LBB10_3
163 ; CHECK-NEXT: # %bb.1: # %entry
164 ; CHECK-NEXT: cmpl $-1, %esi
165 ; CHECK-NEXT: jne .LBB10_3
166 ; CHECK-NEXT: # %bb.2: # %bb1
167 ; CHECK-NEXT: movl $4, %eax
169 ; CHECK-NEXT: .LBB10_3: # %return
170 ; CHECK-NEXT: movl $192, %eax
173 %a = icmp eq i32 %P, -1
174 %b = icmp eq i32 %Q, -1
176 br i1 %c, label %bb1, label %return
185 define i32 @all_sign_bits_set_branch(i32 %P, i32 %Q) nounwind {
186 ; CHECK-LABEL: all_sign_bits_set_branch:
187 ; CHECK: # %bb.0: # %entry
188 ; CHECK-NEXT: testl %edi, %edi
189 ; CHECK-NEXT: jns .LBB11_3
190 ; CHECK-NEXT: # %bb.1: # %entry
191 ; CHECK-NEXT: testl %esi, %esi
192 ; CHECK-NEXT: jns .LBB11_3
193 ; CHECK-NEXT: # %bb.2: # %bb1
194 ; CHECK-NEXT: movl $4, %eax
196 ; CHECK-NEXT: .LBB11_3: # %return
197 ; CHECK-NEXT: movl $192, %eax
200 %a = icmp slt i32 %P, 0
201 %b = icmp slt i32 %Q, 0
203 br i1 %c, label %bb1, label %return
212 ; PR3351 - (P != 0) | (Q != 0) -> (P|Q) != 0
213 define i32 @any_bits_set_branch(i32* %P, i32* %Q) nounwind {
214 ; CHECK-LABEL: any_bits_set_branch:
215 ; CHECK: # %bb.0: # %entry
216 ; CHECK-NEXT: orq %rsi, %rdi
217 ; CHECK-NEXT: je .LBB12_2
218 ; CHECK-NEXT: # %bb.1: # %bb1
219 ; CHECK-NEXT: movl $4, %eax
221 ; CHECK-NEXT: .LBB12_2: # %return
222 ; CHECK-NEXT: movl $192, %eax
225 %a = icmp ne i32* %P, null
226 %b = icmp ne i32* %Q, null
228 br i1 %c, label %bb1, label %return
237 define i32 @any_sign_bits_set_branch(i32 %P, i32 %Q) nounwind {
238 ; CHECK-LABEL: any_sign_bits_set_branch:
239 ; CHECK: # %bb.0: # %entry
240 ; CHECK-NEXT: testl %edi, %edi
241 ; CHECK-NEXT: js .LBB13_2
242 ; CHECK-NEXT: # %bb.1: # %entry
243 ; CHECK-NEXT: testl %esi, %esi
244 ; CHECK-NEXT: js .LBB13_2
245 ; CHECK-NEXT: # %bb.3: # %return
246 ; CHECK-NEXT: movl $192, %eax
248 ; CHECK-NEXT: .LBB13_2: # %bb1
249 ; CHECK-NEXT: movl $4, %eax
252 %a = icmp slt i32 %P, 0
253 %b = icmp slt i32 %Q, 0
255 br i1 %c, label %bb1, label %return
264 define i32 @any_bits_clear_branch(i32 %P, i32 %Q) nounwind {
265 ; CHECK-LABEL: any_bits_clear_branch:
266 ; CHECK: # %bb.0: # %entry
267 ; CHECK-NEXT: cmpl $-1, %edi
268 ; CHECK-NEXT: jne .LBB14_2
269 ; CHECK-NEXT: # %bb.1: # %entry
270 ; CHECK-NEXT: cmpl $-1, %esi
271 ; CHECK-NEXT: jne .LBB14_2
272 ; CHECK-NEXT: # %bb.3: # %return
273 ; CHECK-NEXT: movl $192, %eax
275 ; CHECK-NEXT: .LBB14_2: # %bb1
276 ; CHECK-NEXT: movl $4, %eax
279 %a = icmp ne i32 %P, -1
280 %b = icmp ne i32 %Q, -1
282 br i1 %c, label %bb1, label %return
291 define i32 @any_sign_bits_clear_branch(i32 %P, i32 %Q) nounwind {
292 ; CHECK-LABEL: any_sign_bits_clear_branch:
293 ; CHECK: # %bb.0: # %entry
294 ; CHECK-NEXT: testl %edi, %edi
295 ; CHECK-NEXT: jns .LBB15_2
296 ; CHECK-NEXT: # %bb.1: # %entry
297 ; CHECK-NEXT: testl %esi, %esi
298 ; CHECK-NEXT: jns .LBB15_2
299 ; CHECK-NEXT: # %bb.3: # %return
300 ; CHECK-NEXT: movl $192, %eax
302 ; CHECK-NEXT: .LBB15_2: # %bb1
303 ; CHECK-NEXT: movl $4, %eax
306 %a = icmp sgt i32 %P, -1
307 %b = icmp sgt i32 %Q, -1
309 br i1 %c, label %bb1, label %return
318 define <4 x i1> @all_bits_clear_vec(<4 x i32> %P, <4 x i32> %Q) nounwind {
319 ; CHECK-LABEL: all_bits_clear_vec:
321 ; CHECK-NEXT: por %xmm1, %xmm0
322 ; CHECK-NEXT: pxor %xmm1, %xmm1
323 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm0
325 %a = icmp eq <4 x i32> %P, zeroinitializer
326 %b = icmp eq <4 x i32> %Q, zeroinitializer
327 %c = and <4 x i1> %a, %b
331 define <4 x i1> @all_sign_bits_clear_vec(<4 x i32> %P, <4 x i32> %Q) nounwind {
332 ; CHECK-LABEL: all_sign_bits_clear_vec:
334 ; CHECK-NEXT: por %xmm1, %xmm0
335 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm1
336 ; CHECK-NEXT: pcmpgtd %xmm1, %xmm0
338 %a = icmp sgt <4 x i32> %P, <i32 -1, i32 -1, i32 -1, i32 -1>
339 %b = icmp sgt <4 x i32> %Q, <i32 -1, i32 -1, i32 -1, i32 -1>
340 %c = and <4 x i1> %a, %b
344 define <4 x i1> @all_bits_set_vec(<4 x i32> %P, <4 x i32> %Q) nounwind {
345 ; CHECK-LABEL: all_bits_set_vec:
347 ; CHECK-NEXT: pand %xmm1, %xmm0
348 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm1
349 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm0
351 %a = icmp eq <4 x i32> %P, <i32 -1, i32 -1, i32 -1, i32 -1>
352 %b = icmp eq <4 x i32> %Q, <i32 -1, i32 -1, i32 -1, i32 -1>
353 %c = and <4 x i1> %a, %b
357 define <4 x i1> @all_sign_bits_set_vec(<4 x i32> %P, <4 x i32> %Q) nounwind {
358 ; CHECK-LABEL: all_sign_bits_set_vec:
360 ; CHECK-NEXT: pand %xmm1, %xmm0
361 ; CHECK-NEXT: pxor %xmm1, %xmm1
362 ; CHECK-NEXT: pcmpgtd %xmm0, %xmm1
363 ; CHECK-NEXT: movdqa %xmm1, %xmm0
365 %a = icmp slt <4 x i32> %P, zeroinitializer
366 %b = icmp slt <4 x i32> %Q, zeroinitializer
367 %c = and <4 x i1> %a, %b
371 define <4 x i1> @any_bits_set_vec(<4 x i32> %P, <4 x i32> %Q) nounwind {
372 ; CHECK-LABEL: any_bits_set_vec:
374 ; CHECK-NEXT: por %xmm1, %xmm0
375 ; CHECK-NEXT: pxor %xmm1, %xmm1
376 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm0
377 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm1
378 ; CHECK-NEXT: pxor %xmm1, %xmm0
380 %a = icmp ne <4 x i32> %P, zeroinitializer
381 %b = icmp ne <4 x i32> %Q, zeroinitializer
382 %c = or <4 x i1> %a, %b
386 define <4 x i1> @any_sign_bits_set_vec(<4 x i32> %P, <4 x i32> %Q) nounwind {
387 ; CHECK-LABEL: any_sign_bits_set_vec:
389 ; CHECK-NEXT: por %xmm1, %xmm0
390 ; CHECK-NEXT: pxor %xmm1, %xmm1
391 ; CHECK-NEXT: pcmpgtd %xmm0, %xmm1
392 ; CHECK-NEXT: movdqa %xmm1, %xmm0
394 %a = icmp slt <4 x i32> %P, zeroinitializer
395 %b = icmp slt <4 x i32> %Q, zeroinitializer
396 %c = or <4 x i1> %a, %b
400 define <4 x i1> @any_bits_clear_vec(<4 x i32> %P, <4 x i32> %Q) nounwind {
401 ; CHECK-LABEL: any_bits_clear_vec:
403 ; CHECK-NEXT: pand %xmm1, %xmm0
404 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm1
405 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm0
406 ; CHECK-NEXT: pxor %xmm1, %xmm0
408 %a = icmp ne <4 x i32> %P, <i32 -1, i32 -1, i32 -1, i32 -1>
409 %b = icmp ne <4 x i32> %Q, <i32 -1, i32 -1, i32 -1, i32 -1>
410 %c = or <4 x i1> %a, %b
414 define <4 x i1> @any_sign_bits_clear_vec(<4 x i32> %P, <4 x i32> %Q) nounwind {
415 ; CHECK-LABEL: any_sign_bits_clear_vec:
417 ; CHECK-NEXT: pand %xmm1, %xmm0
418 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm1
419 ; CHECK-NEXT: pcmpgtd %xmm1, %xmm0
421 %a = icmp sgt <4 x i32> %P, <i32 -1, i32 -1, i32 -1, i32 -1>
422 %b = icmp sgt <4 x i32> %Q, <i32 -1, i32 -1, i32 -1, i32 -1>
423 %c = or <4 x i1> %a, %b
427 define zeroext i1 @ne_neg1_and_ne_zero(i64 %x) nounwind {
428 ; CHECK-LABEL: ne_neg1_and_ne_zero:
430 ; CHECK-NEXT: incq %rdi
431 ; CHECK-NEXT: cmpq $1, %rdi
432 ; CHECK-NEXT: seta %al
434 %cmp1 = icmp ne i64 %x, -1
435 %cmp2 = icmp ne i64 %x, 0
436 %and = and i1 %cmp1, %cmp2
440 ; PR32401 - https://bugs.llvm.org/show_bug.cgi?id=32401
442 define zeroext i1 @and_eq(i8 %a, i8 %b, i8 %c, i8 %d) nounwind {
443 ; CHECK-LABEL: and_eq:
445 ; CHECK-NEXT: xorl %esi, %edi
446 ; CHECK-NEXT: xorl %ecx, %edx
447 ; CHECK-NEXT: orb %dl, %dil
448 ; CHECK-NEXT: sete %al
450 %cmp1 = icmp eq i8 %a, %b
451 %cmp2 = icmp eq i8 %c, %d
452 %and = and i1 %cmp1, %cmp2
456 define zeroext i1 @or_ne(i8 %a, i8 %b, i8 %c, i8 %d) nounwind {
457 ; CHECK-LABEL: or_ne:
459 ; CHECK-NEXT: xorl %esi, %edi
460 ; CHECK-NEXT: xorl %ecx, %edx
461 ; CHECK-NEXT: orb %dl, %dil
462 ; CHECK-NEXT: setne %al
464 %cmp1 = icmp ne i8 %a, %b
465 %cmp2 = icmp ne i8 %c, %d
466 %or = or i1 %cmp1, %cmp2
470 ; This should not be transformed because vector compares + bitwise logic are faster.
472 define <4 x i1> @and_eq_vec(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c, <4 x i32> %d) nounwind {
473 ; CHECK-LABEL: and_eq_vec:
475 ; CHECK-NEXT: pcmpeqd %xmm1, %xmm0
476 ; CHECK-NEXT: pcmpeqd %xmm3, %xmm2
477 ; CHECK-NEXT: pand %xmm2, %xmm0
479 %cmp1 = icmp eq <4 x i32> %a, %b
480 %cmp2 = icmp eq <4 x i32> %c, %d
481 %and = and <4 x i1> %cmp1, %cmp2
485 define i1 @or_icmps_const_1bit_diff(i8 %x) {
486 ; CHECK-LABEL: or_icmps_const_1bit_diff:
488 ; CHECK-NEXT: addb $-43, %dil
489 ; CHECK-NEXT: testb $-3, %dil
490 ; CHECK-NEXT: sete %al
492 %a = icmp eq i8 %x, 43
493 %b = icmp eq i8 %x, 45
498 define i1 @and_icmps_const_1bit_diff(i32 %x) {
499 ; CHECK-LABEL: and_icmps_const_1bit_diff:
501 ; CHECK-NEXT: addl $-44, %edi
502 ; CHECK-NEXT: testl $-17, %edi
503 ; CHECK-NEXT: setne %al
505 %a = icmp ne i32 %x, 44
506 %b = icmp ne i32 %x, 60
511 ; Negative test - extra use prevents optimization
513 define i1 @or_icmps_const_1bit_diff_extra_use(i8 %x, i8* %p) {
514 ; CHECK-LABEL: or_icmps_const_1bit_diff_extra_use:
516 ; CHECK-NEXT: cmpb $45, %dil
517 ; CHECK-NEXT: sete %cl
518 ; CHECK-NEXT: cmpb $43, %dil
519 ; CHECK-NEXT: sete %al
520 ; CHECK-NEXT: sete (%rsi)
521 ; CHECK-NEXT: orb %cl, %al
523 %a = icmp eq i8 %x, 43
524 %b = icmp eq i8 %x, 45
526 %z = zext i1 %a to i8
531 ; Negative test - constant diff is >1 bit
533 define i1 @and_icmps_const_not1bit_diff(i32 %x) {
534 ; CHECK-LABEL: and_icmps_const_not1bit_diff:
536 ; CHECK-NEXT: cmpl $44, %edi
537 ; CHECK-NEXT: setne %cl
538 ; CHECK-NEXT: cmpl $92, %edi
539 ; CHECK-NEXT: setne %al
540 ; CHECK-NEXT: andb %cl, %al
542 %a = icmp ne i32 %x, 44
543 %b = icmp ne i32 %x, 92
548 ; Negative test - wrong comparison
550 define i1 @and_icmps_const_1bit_diff_wrong_pred(i32 %x) {
551 ; CHECK-LABEL: and_icmps_const_1bit_diff_wrong_pred:
553 ; CHECK-NEXT: cmpl $43, %edi
554 ; CHECK-NEXT: sete %cl
555 ; CHECK-NEXT: cmpl $45, %edi
556 ; CHECK-NEXT: setl %al
557 ; CHECK-NEXT: orb %cl, %al
559 %a = icmp eq i32 %x, 43
560 %b = icmp slt i32 %x, 45
565 ; Negative test - no common operand
567 define i1 @and_icmps_const_1bit_diff_common_op(i32 %x, i32 %y) {
568 ; CHECK-LABEL: and_icmps_const_1bit_diff_common_op:
570 ; CHECK-NEXT: cmpl $43, %edi
571 ; CHECK-NEXT: sete %cl
572 ; CHECK-NEXT: cmpl $45, %esi
573 ; CHECK-NEXT: sete %al
574 ; CHECK-NEXT: orb %cl, %al
576 %a = icmp eq i32 %x, 43
577 %b = icmp eq i32 %y, 45