1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -ppc-gpr-icmps=all -verify-machineinstrs -mtriple=powerpc64le-unknown-unknown -ppc-convert-rr-to-ri=true | FileCheck %s
4 define zeroext i1 @all_bits_clear(i32 %P, i32 %Q) {
5 ; CHECK-LABEL: all_bits_clear:
7 ; CHECK-NEXT: or 3, 3, 4
8 ; CHECK-NEXT: cntlzw 3, 3
9 ; CHECK-NEXT: srwi 3, 3, 5
11 %a = icmp eq i32 %P, 0
12 %b = icmp eq i32 %Q, 0
17 define zeroext i1 @all_sign_bits_clear(i32 %P, i32 %Q) {
18 ; CHECK-LABEL: all_sign_bits_clear:
20 ; CHECK-NEXT: or 3, 3, 4
21 ; CHECK-NEXT: nor 3, 3, 3
22 ; CHECK-NEXT: srwi 3, 3, 31
24 %a = icmp sgt i32 %P, -1
25 %b = icmp sgt i32 %Q, -1
30 define zeroext i1 @all_bits_set(i32 %P, i32 %Q) {
31 ; CHECK-LABEL: all_bits_set:
33 ; CHECK-NEXT: li 5, -1
34 ; CHECK-NEXT: and 3, 3, 4
35 ; CHECK-NEXT: xor 3, 3, 5
36 ; CHECK-NEXT: cntlzw 3, 3
37 ; CHECK-NEXT: srwi 3, 3, 5
39 %a = icmp eq i32 %P, -1
40 %b = icmp eq i32 %Q, -1
45 define zeroext i1 @all_sign_bits_set(i32 %P, i32 %Q) {
46 ; CHECK-LABEL: all_sign_bits_set:
48 ; CHECK-NEXT: and 3, 3, 4
49 ; CHECK-NEXT: srwi 3, 3, 31
51 %a = icmp slt i32 %P, 0
52 %b = icmp slt i32 %Q, 0
57 define zeroext i1 @any_bits_set(i32 %P, i32 %Q) {
58 ; CHECK-LABEL: any_bits_set:
60 ; CHECK-NEXT: or 3, 3, 4
61 ; CHECK-NEXT: cntlzw 3, 3
62 ; CHECK-NEXT: srwi 3, 3, 5
63 ; CHECK-NEXT: xori 3, 3, 1
65 %a = icmp ne i32 %P, 0
66 %b = icmp ne i32 %Q, 0
71 define zeroext i1 @any_sign_bits_set(i32 %P, i32 %Q) {
72 ; CHECK-LABEL: any_sign_bits_set:
74 ; CHECK-NEXT: or 3, 3, 4
75 ; CHECK-NEXT: srwi 3, 3, 31
77 %a = icmp slt i32 %P, 0
78 %b = icmp slt i32 %Q, 0
83 define zeroext i1 @any_bits_clear(i32 %P, i32 %Q) {
84 ; CHECK-LABEL: any_bits_clear:
86 ; CHECK-NEXT: li 5, -1
87 ; CHECK-NEXT: and 3, 3, 4
88 ; CHECK-NEXT: xor 3, 3, 5
89 ; CHECK-NEXT: cntlzw 3, 3
90 ; CHECK-NEXT: srwi 3, 3, 5
91 ; CHECK-NEXT: xori 3, 3, 1
93 %a = icmp ne i32 %P, -1
94 %b = icmp ne i32 %Q, -1
99 define zeroext i1 @any_sign_bits_clear(i32 %P, i32 %Q) {
100 ; CHECK-LABEL: any_sign_bits_clear:
102 ; CHECK-NEXT: and 3, 3, 4
103 ; CHECK-NEXT: nor 3, 3, 3
104 ; CHECK-NEXT: srwi 3, 3, 31
106 %a = icmp sgt i32 %P, -1
107 %b = icmp sgt i32 %Q, -1
112 ; PR3351 - (P == 0) & (Q == 0) -> (P|Q) == 0
113 define i32 @all_bits_clear_branch(i32* %P, i32* %Q) {
114 ; CHECK-LABEL: all_bits_clear_branch:
115 ; CHECK: # %bb.0: # %entry
116 ; CHECK-NEXT: or. 3, 3, 4
117 ; CHECK-NEXT: bne 0, .LBB8_2
118 ; CHECK-NEXT: # %bb.1: # %bb1
119 ; CHECK-NEXT: li 3, 4
121 ; CHECK-NEXT: .LBB8_2: # %return
122 ; CHECK-NEXT: li 3, 192
125 %a = icmp eq i32* %P, null
126 %b = icmp eq i32* %Q, null
128 br i1 %c, label %bb1, label %return
137 define i32 @all_sign_bits_clear_branch(i32 %P, i32 %Q) {
138 ; CHECK-LABEL: all_sign_bits_clear_branch:
139 ; CHECK: # %bb.0: # %entry
140 ; CHECK-NEXT: or 3, 3, 4
141 ; CHECK-NEXT: cmpwi 0, 3, 0
142 ; CHECK-NEXT: blt 0, .LBB9_2
143 ; CHECK-NEXT: # %bb.1: # %bb1
144 ; CHECK-NEXT: li 3, 4
146 ; CHECK-NEXT: .LBB9_2: # %return
147 ; CHECK-NEXT: li 3, 192
150 %a = icmp sgt i32 %P, -1
151 %b = icmp sgt i32 %Q, -1
153 br i1 %c, label %bb1, label %return
162 define i32 @all_bits_set_branch(i32 %P, i32 %Q) {
163 ; CHECK-LABEL: all_bits_set_branch:
164 ; CHECK: # %bb.0: # %entry
165 ; CHECK-NEXT: and 3, 3, 4
166 ; CHECK-NEXT: cmpwi 0, 3, -1
167 ; CHECK-NEXT: bne 0, .LBB10_2
168 ; CHECK-NEXT: # %bb.1: # %bb1
169 ; CHECK-NEXT: li 3, 4
171 ; CHECK-NEXT: .LBB10_2: # %return
172 ; CHECK-NEXT: li 3, 192
175 %a = icmp eq i32 %P, -1
176 %b = icmp eq i32 %Q, -1
178 br i1 %c, label %bb1, label %return
187 define i32 @all_sign_bits_set_branch(i32 %P, i32 %Q) {
188 ; CHECK-LABEL: all_sign_bits_set_branch:
189 ; CHECK: # %bb.0: # %entry
190 ; CHECK-NEXT: and 3, 3, 4
191 ; CHECK-NEXT: cmpwi 0, 3, -1
192 ; CHECK-NEXT: bgt 0, .LBB11_2
193 ; CHECK-NEXT: # %bb.1: # %bb1
194 ; CHECK-NEXT: li 3, 4
196 ; CHECK-NEXT: .LBB11_2: # %return
197 ; CHECK-NEXT: li 3, 192
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) {
214 ; CHECK-LABEL: any_bits_set_branch:
215 ; CHECK: # %bb.0: # %entry
216 ; CHECK-NEXT: or. 3, 3, 4
217 ; CHECK-NEXT: beq 0, .LBB12_2
218 ; CHECK-NEXT: # %bb.1: # %bb1
219 ; CHECK-NEXT: li 3, 4
221 ; CHECK-NEXT: .LBB12_2: # %return
222 ; CHECK-NEXT: li 3, 192
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) {
238 ; CHECK-LABEL: any_sign_bits_set_branch:
239 ; CHECK: # %bb.0: # %entry
240 ; CHECK-NEXT: or 3, 3, 4
241 ; CHECK-NEXT: cmpwi 0, 3, -1
242 ; CHECK-NEXT: bgt 0, .LBB13_2
243 ; CHECK-NEXT: # %bb.1: # %bb1
244 ; CHECK-NEXT: li 3, 4
246 ; CHECK-NEXT: .LBB13_2: # %return
247 ; CHECK-NEXT: li 3, 192
250 %a = icmp slt i32 %P, 0
251 %b = icmp slt i32 %Q, 0
253 br i1 %c, label %bb1, label %return
262 define i32 @any_bits_clear_branch(i32 %P, i32 %Q) {
263 ; CHECK-LABEL: any_bits_clear_branch:
264 ; CHECK: # %bb.0: # %entry
265 ; CHECK-NEXT: and 3, 3, 4
266 ; CHECK-NEXT: cmpwi 0, 3, -1
267 ; CHECK-NEXT: beq 0, .LBB14_2
268 ; CHECK-NEXT: # %bb.1: # %bb1
269 ; CHECK-NEXT: li 3, 4
271 ; CHECK-NEXT: .LBB14_2: # %return
272 ; CHECK-NEXT: li 3, 192
275 %a = icmp ne i32 %P, -1
276 %b = icmp ne i32 %Q, -1
278 br i1 %c, label %bb1, label %return
287 define i32 @any_sign_bits_clear_branch(i32 %P, i32 %Q) {
288 ; CHECK-LABEL: any_sign_bits_clear_branch:
289 ; CHECK: # %bb.0: # %entry
290 ; CHECK-NEXT: and 3, 3, 4
291 ; CHECK-NEXT: cmpwi 0, 3, 0
292 ; CHECK-NEXT: blt 0, .LBB15_2
293 ; CHECK-NEXT: # %bb.1: # %bb1
294 ; CHECK-NEXT: li 3, 4
296 ; CHECK-NEXT: .LBB15_2: # %return
297 ; CHECK-NEXT: li 3, 192
300 %a = icmp sgt i32 %P, -1
301 %b = icmp sgt i32 %Q, -1
303 br i1 %c, label %bb1, label %return
312 define <4 x i1> @all_bits_clear_vec(<4 x i32> %P, <4 x i32> %Q) {
313 ; CHECK-LABEL: all_bits_clear_vec:
315 ; CHECK-NEXT: xxlxor 36, 36, 36
316 ; CHECK-NEXT: xxlor 34, 34, 35
317 ; CHECK-NEXT: vcmpequw 2, 2, 4
319 %a = icmp eq <4 x i32> %P, zeroinitializer
320 %b = icmp eq <4 x i32> %Q, zeroinitializer
321 %c = and <4 x i1> %a, %b
325 define <4 x i1> @all_sign_bits_clear_vec(<4 x i32> %P, <4 x i32> %Q) {
326 ; CHECK-LABEL: all_sign_bits_clear_vec:
328 ; CHECK-NEXT: vspltisb 4, -1
329 ; CHECK-NEXT: xxlor 34, 34, 35
330 ; CHECK-NEXT: vcmpgtsw 2, 2, 4
332 %a = icmp sgt <4 x i32> %P, <i32 -1, i32 -1, i32 -1, i32 -1>
333 %b = icmp sgt <4 x i32> %Q, <i32 -1, i32 -1, i32 -1, i32 -1>
334 %c = and <4 x i1> %a, %b
338 define <4 x i1> @all_bits_set_vec(<4 x i32> %P, <4 x i32> %Q) {
339 ; CHECK-LABEL: all_bits_set_vec:
341 ; CHECK-NEXT: vspltisb 4, -1
342 ; CHECK-NEXT: xxland 34, 34, 35
343 ; CHECK-NEXT: vcmpequw 2, 2, 4
345 %a = icmp eq <4 x i32> %P, <i32 -1, i32 -1, i32 -1, i32 -1>
346 %b = icmp eq <4 x i32> %Q, <i32 -1, i32 -1, i32 -1, i32 -1>
347 %c = and <4 x i1> %a, %b
351 define <4 x i1> @all_sign_bits_set_vec(<4 x i32> %P, <4 x i32> %Q) {
352 ; CHECK-LABEL: all_sign_bits_set_vec:
354 ; CHECK-NEXT: xxlxor 36, 36, 36
355 ; CHECK-NEXT: xxland 34, 34, 35
356 ; CHECK-NEXT: vcmpgtsw 2, 4, 2
358 %a = icmp slt <4 x i32> %P, zeroinitializer
359 %b = icmp slt <4 x i32> %Q, zeroinitializer
360 %c = and <4 x i1> %a, %b
364 define <4 x i1> @any_bits_set_vec(<4 x i32> %P, <4 x i32> %Q) {
365 ; CHECK-LABEL: any_bits_set_vec:
367 ; CHECK-NEXT: xxlxor 36, 36, 36
368 ; CHECK-NEXT: xxlor 34, 34, 35
369 ; CHECK-NEXT: vcmpequw 2, 2, 4
370 ; CHECK-NEXT: xxlnor 34, 34, 34
372 %a = icmp ne <4 x i32> %P, zeroinitializer
373 %b = icmp ne <4 x i32> %Q, zeroinitializer
374 %c = or <4 x i1> %a, %b
378 define <4 x i1> @any_sign_bits_set_vec(<4 x i32> %P, <4 x i32> %Q) {
379 ; CHECK-LABEL: any_sign_bits_set_vec:
381 ; CHECK-NEXT: xxlxor 36, 36, 36
382 ; CHECK-NEXT: xxlor 34, 34, 35
383 ; CHECK-NEXT: vcmpgtsw 2, 4, 2
385 %a = icmp slt <4 x i32> %P, zeroinitializer
386 %b = icmp slt <4 x i32> %Q, zeroinitializer
387 %c = or <4 x i1> %a, %b
391 define <4 x i1> @any_bits_clear_vec(<4 x i32> %P, <4 x i32> %Q) {
392 ; CHECK-LABEL: any_bits_clear_vec:
394 ; CHECK-NEXT: vspltisb 4, -1
395 ; CHECK-NEXT: xxland 34, 34, 35
396 ; CHECK-NEXT: vcmpequw 2, 2, 4
397 ; CHECK-NEXT: xxlnor 34, 34, 34
399 %a = icmp ne <4 x i32> %P, <i32 -1, i32 -1, i32 -1, i32 -1>
400 %b = icmp ne <4 x i32> %Q, <i32 -1, i32 -1, i32 -1, i32 -1>
401 %c = or <4 x i1> %a, %b
405 define <4 x i1> @any_sign_bits_clear_vec(<4 x i32> %P, <4 x i32> %Q) {
406 ; CHECK-LABEL: any_sign_bits_clear_vec:
408 ; CHECK-NEXT: vspltisb 4, -1
409 ; CHECK-NEXT: xxland 34, 34, 35
410 ; CHECK-NEXT: vcmpgtsw 2, 2, 4
412 %a = icmp sgt <4 x i32> %P, <i32 -1, i32 -1, i32 -1, i32 -1>
413 %b = icmp sgt <4 x i32> %Q, <i32 -1, i32 -1, i32 -1, i32 -1>
414 %c = or <4 x i1> %a, %b
418 define zeroext i1 @ne_neg1_and_ne_zero(i64 %x) {
419 ; CHECK-LABEL: ne_neg1_and_ne_zero:
421 ; CHECK-NEXT: addi 3, 3, 1
422 ; CHECK-NEXT: li 4, 1
423 ; CHECK-NEXT: subfic 3, 3, 1
424 ; CHECK-NEXT: subfe 3, 4, 4
425 ; CHECK-NEXT: neg 3, 3
427 %cmp1 = icmp ne i64 %x, -1
428 %cmp2 = icmp ne i64 %x, 0
429 %and = and i1 %cmp1, %cmp2
433 ; PR32401 - https://bugs.llvm.org/show_bug.cgi?id=32401
435 define zeroext i1 @and_eq(i16 zeroext %a, i16 zeroext %b, i16 zeroext %c, i16 zeroext %d) {
436 ; CHECK-LABEL: and_eq:
438 ; CHECK-NEXT: xor 3, 3, 4
439 ; CHECK-NEXT: xor 4, 5, 6
440 ; CHECK-NEXT: or 3, 3, 4
441 ; CHECK-NEXT: cntlzw 3, 3
442 ; CHECK-NEXT: srwi 3, 3, 5
444 %cmp1 = icmp eq i16 %a, %b
445 %cmp2 = icmp eq i16 %c, %d
446 %and = and i1 %cmp1, %cmp2
450 define zeroext i1 @or_ne(i32 %a, i32 %b, i32 %c, i32 %d) {
451 ; CHECK-LABEL: or_ne:
453 ; CHECK-NEXT: xor 3, 3, 4
454 ; CHECK-NEXT: xor 4, 5, 6
455 ; CHECK-NEXT: or 3, 3, 4
456 ; CHECK-NEXT: cntlzw 3, 3
457 ; CHECK-NEXT: srwi 3, 3, 5
458 ; CHECK-NEXT: xori 3, 3, 1
460 %cmp1 = icmp ne i32 %a, %b
461 %cmp2 = icmp ne i32 %c, %d
462 %or = or i1 %cmp1, %cmp2
466 ; This should not be transformed because vector compares + bitwise logic are faster.
468 define <4 x i1> @and_eq_vec(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c, <4 x i32> %d) {
469 ; CHECK-LABEL: and_eq_vec:
471 ; CHECK-NEXT: vcmpequw 2, 2, 3
472 ; CHECK-NEXT: vcmpequw 3, 4, 5
473 ; CHECK-NEXT: xxland 34, 34, 35
475 %cmp1 = icmp eq <4 x i32> %a, %b
476 %cmp2 = icmp eq <4 x i32> %c, %d
477 %and = and <4 x i1> %cmp1, %cmp2
481 define i1 @or_icmps_const_1bit_diff(i64 %x) {
482 ; CHECK-LABEL: or_icmps_const_1bit_diff:
484 ; CHECK-NEXT: li 4, -5
485 ; CHECK-NEXT: addi 3, 3, -13
486 ; CHECK-NEXT: and 3, 3, 4
487 ; CHECK-NEXT: cntlzd 3, 3
488 ; CHECK-NEXT: rldicl 3, 3, 58, 63
490 %a = icmp eq i64 %x, 17
491 %b = icmp eq i64 %x, 13
496 define i1 @and_icmps_const_1bit_diff(i32 %x) {
497 ; CHECK-LABEL: and_icmps_const_1bit_diff:
499 ; CHECK-NEXT: addi 3, 3, -4625
500 ; CHECK-NEXT: rlwinm 3, 3, 0, 28, 26
501 ; CHECK-NEXT: cntlzw 3, 3
502 ; CHECK-NEXT: nor 3, 3, 3
503 ; CHECK-NEXT: rlwinm 3, 3, 27, 31, 31
505 %a = icmp ne i32 %x, 4625
506 %b = icmp ne i32 %x, 4641