1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -show-mc-encoding | FileCheck %s
4 @d = dso_local global i8 0, align 1
5 @d64 = dso_local global i64 0
7 define i32 @test1(i32 %X, ptr %y) nounwind {
9 ; CHECK: # %bb.0: # %entry
10 ; CHECK-NEXT: cmpl $0, (%rsi) # encoding: [0x83,0x3e,0x00]
11 ; CHECK-NEXT: je .LBB0_2 # encoding: [0x74,A]
12 ; CHECK-NEXT: # fixup A - offset: 1, value: .LBB0_2-1, kind: FK_PCRel_1
13 ; CHECK-NEXT: # %bb.1: # %cond_true
14 ; CHECK-NEXT: movl $1, %eax # encoding: [0xb8,0x01,0x00,0x00,0x00]
15 ; CHECK-NEXT: retq # encoding: [0xc3]
16 ; CHECK-NEXT: .LBB0_2: # %ReturnBlock
17 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
18 ; CHECK-NEXT: retq # encoding: [0xc3]
20 %tmp = load i32, ptr %y
21 %tmp.upgrd.1 = icmp eq i32 %tmp, 0
22 br i1 %tmp.upgrd.1, label %ReturnBlock, label %cond_true
31 define i32 @test2(i32 %X, ptr %y) nounwind {
33 ; CHECK: # %bb.0: # %entry
34 ; CHECK-NEXT: testl $536870911, (%rsi) # encoding: [0xf7,0x06,0xff,0xff,0xff,0x1f]
35 ; CHECK-NEXT: # imm = 0x1FFFFFFF
36 ; CHECK-NEXT: je .LBB1_2 # encoding: [0x74,A]
37 ; CHECK-NEXT: # fixup A - offset: 1, value: .LBB1_2-1, kind: FK_PCRel_1
38 ; CHECK-NEXT: # %bb.1: # %cond_true
39 ; CHECK-NEXT: movl $1, %eax # encoding: [0xb8,0x01,0x00,0x00,0x00]
40 ; CHECK-NEXT: retq # encoding: [0xc3]
41 ; CHECK-NEXT: .LBB1_2: # %ReturnBlock
42 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
43 ; CHECK-NEXT: retq # encoding: [0xc3]
45 %tmp = load i32, ptr %y
46 %tmp1 = shl i32 %tmp, 3
47 %tmp1.upgrd.2 = icmp eq i32 %tmp1, 0
48 br i1 %tmp1.upgrd.2, label %ReturnBlock, label %cond_true
57 define i8 @test2b(i8 %X, ptr %y) nounwind {
58 ; CHECK-LABEL: test2b:
59 ; CHECK: # %bb.0: # %entry
60 ; CHECK-NEXT: testb $31, (%rsi) # encoding: [0xf6,0x06,0x1f]
61 ; CHECK-NEXT: je .LBB2_2 # encoding: [0x74,A]
62 ; CHECK-NEXT: # fixup A - offset: 1, value: .LBB2_2-1, kind: FK_PCRel_1
63 ; CHECK-NEXT: # %bb.1: # %cond_true
64 ; CHECK-NEXT: movb $1, %al # encoding: [0xb0,0x01]
65 ; CHECK-NEXT: retq # encoding: [0xc3]
66 ; CHECK-NEXT: .LBB2_2: # %ReturnBlock
67 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
68 ; CHECK-NEXT: retq # encoding: [0xc3]
70 %tmp = load i8, ptr %y
71 %tmp1 = shl i8 %tmp, 3
72 %tmp1.upgrd.2 = icmp eq i8 %tmp1, 0
73 br i1 %tmp1.upgrd.2, label %ReturnBlock, label %cond_true
82 define i64 @test3(i64 %x) nounwind {
84 ; CHECK: # %bb.0: # %entry
85 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
86 ; CHECK-NEXT: testq %rdi, %rdi # encoding: [0x48,0x85,0xff]
87 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
88 ; CHECK-NEXT: retq # encoding: [0xc3]
90 %t = icmp eq i64 %x, 0
91 %r = zext i1 %t to i64
95 define i64 @test4(i64 %x) nounwind {
98 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
99 ; CHECK-NEXT: testq %rdi, %rdi # encoding: [0x48,0x85,0xff]
100 ; CHECK-NEXT: setle %al # encoding: [0x0f,0x9e,0xc0]
101 ; CHECK-NEXT: retq # encoding: [0xc3]
102 %t = icmp slt i64 %x, 1
103 %r = zext i1 %t to i64
107 define i32 @test5(double %A) nounwind {
108 ; CHECK-LABEL: test5:
109 ; CHECK: # %bb.0: # %entry
110 ; CHECK-NEXT: ucomisd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0 # encoding: [0x66,0x0f,0x2e,0x05,A,A,A,A]
111 ; CHECK-NEXT: # fixup A - offset: 4, value: {{\.?LCPI[0-9]+_[0-9]+}}-4, kind: reloc_riprel_4byte
112 ; CHECK-NEXT: ja .LBB5_3 # encoding: [0x77,A]
113 ; CHECK-NEXT: # fixup A - offset: 1, value: .LBB5_3-1, kind: FK_PCRel_1
114 ; CHECK-NEXT: # %bb.1: # %entry
115 ; CHECK-NEXT: ucomisd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0 # encoding: [0x66,0x0f,0x2e,0x05,A,A,A,A]
116 ; CHECK-NEXT: # fixup A - offset: 4, value: {{\.?LCPI[0-9]+_[0-9]+}}-4, kind: reloc_riprel_4byte
117 ; CHECK-NEXT: jb .LBB5_3 # encoding: [0x72,A]
118 ; CHECK-NEXT: # fixup A - offset: 1, value: .LBB5_3-1, kind: FK_PCRel_1
119 ; CHECK-NEXT: # %bb.2: # %bb12
120 ; CHECK-NEXT: movl $32, %eax # encoding: [0xb8,0x20,0x00,0x00,0x00]
121 ; CHECK-NEXT: retq # encoding: [0xc3]
122 ; CHECK-NEXT: .LBB5_3: # %bb8
123 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
124 ; CHECK-NEXT: jmp foo@PLT # TAILCALL
125 ; CHECK-NEXT: # encoding: [0xeb,A]
126 ; CHECK-NEXT: # fixup A - offset: 1, value: foo@PLT-1, kind: FK_PCRel_1
128 %tmp2 = fcmp ogt double %A, 1.500000e+02
129 %tmp5 = fcmp ult double %A, 7.500000e+01
130 %bothcond = or i1 %tmp2, %tmp5
131 br i1 %bothcond, label %bb8, label %bb12
134 %tmp9 = tail call i32 (...) @foo() nounwind
141 declare i32 @foo(...)
143 define i32 @test6() nounwind align 2 {
144 ; CHECK-LABEL: test6:
145 ; CHECK: # %bb.0: # %entry
146 ; CHECK-NEXT: cmpq $0, -{{[0-9]+}}(%rsp) # encoding: [0x48,0x83,0x7c,0x24,0xf8,0x00]
147 ; CHECK-NEXT: je .LBB6_1 # encoding: [0x74,A]
148 ; CHECK-NEXT: # fixup A - offset: 1, value: .LBB6_1-1, kind: FK_PCRel_1
149 ; CHECK-NEXT: # %bb.2: # %F
150 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
151 ; CHECK-NEXT: retq # encoding: [0xc3]
152 ; CHECK-NEXT: .LBB6_1: # %T
153 ; CHECK-NEXT: movl $1, %eax # encoding: [0xb8,0x01,0x00,0x00,0x00]
154 ; CHECK-NEXT: retq # encoding: [0xc3]
156 %A = alloca { i64, i64 }, align 8
157 %B = getelementptr inbounds { i64, i64 }, ptr %A, i64 0, i32 1
158 %C = load i64, ptr %B
159 %D = icmp eq i64 %C, 0
160 br i1 %D, label %T, label %F
169 define i32 @test7(i64 %res) nounwind {
170 ; CHECK-LABEL: test7:
171 ; CHECK: # %bb.0: # %entry
172 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
173 ; CHECK-NEXT: shrq $32, %rdi # encoding: [0x48,0xc1,0xef,0x20]
174 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
175 ; CHECK-NEXT: retq # encoding: [0xc3]
177 %lnot = icmp ult i64 %res, 4294967296
178 %lnot.ext = zext i1 %lnot to i32
182 define i32 @test8(i64 %res) nounwind {
183 ; CHECK-LABEL: test8:
185 ; CHECK-NEXT: shrq $32, %rdi # encoding: [0x48,0xc1,0xef,0x20]
186 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
187 ; CHECK-NEXT: cmpl $3, %edi # encoding: [0x83,0xff,0x03]
188 ; CHECK-NEXT: setb %al # encoding: [0x0f,0x92,0xc0]
189 ; CHECK-NEXT: retq # encoding: [0xc3]
190 %lnot = icmp ult i64 %res, 12884901888
191 %lnot.ext = zext i1 %lnot to i32
195 define i32 @test9(i64 %res) nounwind {
196 ; CHECK-LABEL: test9:
198 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
199 ; CHECK-NEXT: shrq $33, %rdi # encoding: [0x48,0xc1,0xef,0x21]
200 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
201 ; CHECK-NEXT: retq # encoding: [0xc3]
202 %lnot = icmp ult i64 %res, 8589934592
203 %lnot.ext = zext i1 %lnot to i32
207 define i32 @test10(i64 %res) nounwind {
208 ; CHECK-LABEL: test10:
210 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
211 ; CHECK-NEXT: shrq $32, %rdi # encoding: [0x48,0xc1,0xef,0x20]
212 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
213 ; CHECK-NEXT: retq # encoding: [0xc3]
214 %lnot = icmp uge i64 %res, 4294967296
215 %lnot.ext = zext i1 %lnot to i32
219 define i32 @test11(i64 %l) nounwind {
220 ; CHECK-LABEL: test11:
222 ; CHECK-NEXT: shrq $47, %rdi # encoding: [0x48,0xc1,0xef,0x2f]
223 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
224 ; CHECK-NEXT: cmpl $1, %edi # encoding: [0x83,0xff,0x01]
225 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
226 ; CHECK-NEXT: retq # encoding: [0xc3]
227 %shr.mask = and i64 %l, -140737488355328
228 %cmp = icmp eq i64 %shr.mask, 140737488355328
229 %conv = zext i1 %cmp to i32
233 define i32 @test12() ssp uwtable {
234 ; CHECK-LABEL: test12:
235 ; CHECK: # %bb.0: # %entry
236 ; CHECK-NEXT: pushq %rax # encoding: [0x50]
237 ; CHECK-NEXT: .cfi_def_cfa_offset 16
238 ; CHECK-NEXT: callq test12b@PLT # encoding: [0xe8,A,A,A,A]
239 ; CHECK-NEXT: # fixup A - offset: 1, value: test12b@PLT-4, kind: FK_PCRel_4
240 ; CHECK-NEXT: testb %al, %al # encoding: [0x84,0xc0]
241 ; CHECK-NEXT: je .LBB12_2 # encoding: [0x74,A]
242 ; CHECK-NEXT: # fixup A - offset: 1, value: .LBB12_2-1, kind: FK_PCRel_1
243 ; CHECK-NEXT: # %bb.1: # %T
244 ; CHECK-NEXT: movl $1, %eax # encoding: [0xb8,0x01,0x00,0x00,0x00]
245 ; CHECK-NEXT: popq %rcx # encoding: [0x59]
246 ; CHECK-NEXT: .cfi_def_cfa_offset 8
247 ; CHECK-NEXT: retq # encoding: [0xc3]
248 ; CHECK-NEXT: .LBB12_2: # %F
249 ; CHECK-NEXT: .cfi_def_cfa_offset 16
250 ; CHECK-NEXT: movl $2, %eax # encoding: [0xb8,0x02,0x00,0x00,0x00]
251 ; CHECK-NEXT: popq %rcx # encoding: [0x59]
252 ; CHECK-NEXT: .cfi_def_cfa_offset 8
253 ; CHECK-NEXT: retq # encoding: [0xc3]
255 %tmp1 = call zeroext i1 @test12b()
256 br i1 %tmp1, label %T, label %F
265 declare zeroext i1 @test12b()
267 define i32 @test13(i32 %mask, i32 %base, i32 %intra) {
268 ; CHECK-LABEL: test13:
270 ; CHECK-NEXT: movl %esi, %eax # encoding: [0x89,0xf0]
271 ; CHECK-NEXT: testb $8, %dil # encoding: [0x40,0xf6,0xc7,0x08]
272 ; CHECK-NEXT: cmovnel %edx, %eax # encoding: [0x0f,0x45,0xc2]
273 ; CHECK-NEXT: retq # encoding: [0xc3]
274 %and = and i32 %mask, 8
275 %tobool = icmp ne i32 %and, 0
276 %cond = select i1 %tobool, i32 %intra, i32 %base
280 define i32 @test14(i32 %mask, i32 %base, i32 %intra) {
281 ; CHECK-LABEL: test14:
283 ; CHECK-NEXT: movl %esi, %eax # encoding: [0x89,0xf0]
284 ; CHECK-NEXT: shrl $7, %edi # encoding: [0xc1,0xef,0x07]
285 ; CHECK-NEXT: cmovnsl %edx, %eax # encoding: [0x0f,0x49,0xc2]
286 ; CHECK-NEXT: retq # encoding: [0xc3]
287 %s = lshr i32 %mask, 7
288 %tobool = icmp sgt i32 %s, -1
289 %cond = select i1 %tobool, i32 %intra, i32 %base
294 define zeroext i1 @test15(i32 %bf.load, i32 %n) {
295 ; CHECK-LABEL: test15:
297 ; CHECK-NEXT: shrl $16, %edi # encoding: [0xc1,0xef,0x10]
298 ; CHECK-NEXT: sete %cl # encoding: [0x0f,0x94,0xc1]
299 ; CHECK-NEXT: cmpl %esi, %edi # encoding: [0x39,0xf7]
300 ; CHECK-NEXT: setae %al # encoding: [0x0f,0x93,0xc0]
301 ; CHECK-NEXT: orb %cl, %al # encoding: [0x08,0xc8]
302 ; CHECK-NEXT: retq # encoding: [0xc3]
303 %bf.lshr = lshr i32 %bf.load, 16
304 %cmp2 = icmp eq i32 %bf.lshr, 0
305 %cmp5 = icmp uge i32 %bf.lshr, %n
306 %.cmp5 = or i1 %cmp2, %cmp5
310 define i8 @signbit_i16(i16 signext %L) {
311 ; CHECK-LABEL: signbit_i16:
313 ; CHECK-NEXT: testw %di, %di # encoding: [0x66,0x85,0xff]
314 ; CHECK-NEXT: setns %al # encoding: [0x0f,0x99,0xc0]
315 ; CHECK-NEXT: retq # encoding: [0xc3]
316 %lshr = lshr i16 %L, 15
317 %trunc = trunc i16 %lshr to i8
318 %not = xor i8 %trunc, 1
322 define i8 @signbit_i32(i32 %L) {
323 ; CHECK-LABEL: signbit_i32:
325 ; CHECK-NEXT: testl %edi, %edi # encoding: [0x85,0xff]
326 ; CHECK-NEXT: setns %al # encoding: [0x0f,0x99,0xc0]
327 ; CHECK-NEXT: retq # encoding: [0xc3]
328 %lshr = lshr i32 %L, 31
329 %trunc = trunc i32 %lshr to i8
330 %not = xor i8 %trunc, 1
334 define i8 @signbit_i64(i64 %L) {
335 ; CHECK-LABEL: signbit_i64:
337 ; CHECK-NEXT: testq %rdi, %rdi # encoding: [0x48,0x85,0xff]
338 ; CHECK-NEXT: setns %al # encoding: [0x0f,0x99,0xc0]
339 ; CHECK-NEXT: retq # encoding: [0xc3]
340 %lshr = lshr i64 %L, 63
341 %trunc = trunc i64 %lshr to i8
342 %not = xor i8 %trunc, 1
346 define zeroext i1 @signbit_i32_i1(i32 %L) {
347 ; CHECK-LABEL: signbit_i32_i1:
349 ; CHECK-NEXT: testl %edi, %edi # encoding: [0x85,0xff]
350 ; CHECK-NEXT: setns %al # encoding: [0x0f,0x99,0xc0]
351 ; CHECK-NEXT: retq # encoding: [0xc3]
352 %lshr = lshr i32 %L, 31
353 %trunc = trunc i32 %lshr to i1
354 %not = xor i1 %trunc, true
358 ; This test failed due to incorrect handling of "shift + icmp" sequence
359 define void @test20(i32 %bf.load, i8 %x1, ptr %b_addr) {
360 ; CHECK-LABEL: test20:
362 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
363 ; CHECK-NEXT: testl $16777215, %edi # encoding: [0xf7,0xc7,0xff,0xff,0xff,0x00]
364 ; CHECK-NEXT: # imm = 0xFFFFFF
365 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
366 ; CHECK-NEXT: movzbl %sil, %ecx # encoding: [0x40,0x0f,0xb6,0xce]
367 ; CHECK-NEXT: addl %eax, %ecx # encoding: [0x01,0xc1]
368 ; CHECK-NEXT: setne (%rdx) # encoding: [0x0f,0x95,0x02]
369 ; CHECK-NEXT: testl $16777215, %edi # encoding: [0xf7,0xc7,0xff,0xff,0xff,0x00]
370 ; CHECK-NEXT: # imm = 0xFFFFFF
371 ; CHECK-NEXT: setne d(%rip) # encoding: [0x0f,0x95,0x05,A,A,A,A]
372 ; CHECK-NEXT: # fixup A - offset: 3, value: d-4, kind: reloc_riprel_4byte
373 ; CHECK-NEXT: retq # encoding: [0xc3]
374 %bf.shl = shl i32 %bf.load, 8
375 %bf.ashr = ashr exact i32 %bf.shl, 8
376 %tobool4 = icmp ne i32 %bf.ashr, 0
377 %conv = zext i1 %tobool4 to i32
378 %conv6 = zext i8 %x1 to i32
379 %add = add nuw nsw i32 %conv, %conv6
380 %tobool7 = icmp ne i32 %add, 0
381 %frombool = zext i1 %tobool7 to i8
382 store i8 %frombool, ptr %b_addr, align 1
383 %tobool14 = icmp ne i32 %bf.shl, 0
384 %frombool15 = zext i1 %tobool14 to i8
385 store i8 %frombool15, ptr @d, align 1
389 define i32 @highmask_i64_simplify(i64 %val) {
390 ; CHECK-LABEL: highmask_i64_simplify:
392 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
393 ; CHECK-NEXT: retq # encoding: [0xc3]
394 %and = and i64 %val, -2199023255552
395 %cmp = icmp ult i64 %and, 0
396 %ret = zext i1 %cmp to i32
400 define i32 @highmask_i64_mask64(i64 %val) {
401 ; CHECK-LABEL: highmask_i64_mask64:
403 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
404 ; CHECK-NEXT: shrq $41, %rdi # encoding: [0x48,0xc1,0xef,0x29]
405 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
406 ; CHECK-NEXT: retq # encoding: [0xc3]
407 %and = and i64 %val, -2199023255552
408 %cmp = icmp ne i64 %and, 0
409 %ret = zext i1 %cmp to i32
413 define i64 @highmask_i64_mask64_extra_use(i64 %val) nounwind {
414 ; CHECK-LABEL: highmask_i64_mask64_extra_use:
416 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
417 ; CHECK-NEXT: movq %rdi, %rcx # encoding: [0x48,0x89,0xf9]
418 ; CHECK-NEXT: shrq $41, %rcx # encoding: [0x48,0xc1,0xe9,0x29]
419 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
420 ; CHECK-NEXT: imulq %rdi, %rax # encoding: [0x48,0x0f,0xaf,0xc7]
421 ; CHECK-NEXT: retq # encoding: [0xc3]
422 %and = and i64 %val, -2199023255552
423 %cmp = icmp ne i64 %and, 0
424 %z = zext i1 %cmp to i64
425 %ret = mul i64 %z, %val
429 define i32 @highmask_i64_mask32(i64 %val) {
430 ; CHECK-LABEL: highmask_i64_mask32:
432 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
433 ; CHECK-NEXT: shrq $20, %rdi # encoding: [0x48,0xc1,0xef,0x14]
434 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
435 ; CHECK-NEXT: retq # encoding: [0xc3]
436 %and = and i64 %val, -1048576
437 %cmp = icmp eq i64 %and, 0
438 %ret = zext i1 %cmp to i32
442 define i64 @highmask_i64_mask32_extra_use(i64 %val) nounwind {
443 ; CHECK-LABEL: highmask_i64_mask32_extra_use:
445 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
446 ; CHECK-NEXT: testq $-1048576, %rdi # encoding: [0x48,0xf7,0xc7,0x00,0x00,0xf0,0xff]
447 ; CHECK-NEXT: # imm = 0xFFF00000
448 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
449 ; CHECK-NEXT: imulq %rdi, %rax # encoding: [0x48,0x0f,0xaf,0xc7]
450 ; CHECK-NEXT: retq # encoding: [0xc3]
451 %and = and i64 %val, -1048576
452 %cmp = icmp eq i64 %and, 0
453 %z = zext i1 %cmp to i64
454 %ret = mul i64 %z, %val
458 define i32 @highmask_i64_mask8(i64 %val) {
459 ; CHECK-LABEL: highmask_i64_mask8:
461 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
462 ; CHECK-NEXT: testq $-16, %rdi # encoding: [0x48,0xf7,0xc7,0xf0,0xff,0xff,0xff]
463 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
464 ; CHECK-NEXT: retq # encoding: [0xc3]
465 %and = and i64 %val, -16
466 %cmp = icmp ne i64 %and, 0
467 %ret = zext i1 %cmp to i32
471 define i32 @lowmask_i64_mask64(i64 %val) {
472 ; CHECK-LABEL: lowmask_i64_mask64:
474 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
475 ; CHECK-NEXT: shlq $16, %rdi # encoding: [0x48,0xc1,0xe7,0x10]
476 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
477 ; CHECK-NEXT: retq # encoding: [0xc3]
478 %and = and i64 %val, 281474976710655
479 %cmp = icmp eq i64 %and, 0
480 %ret = zext i1 %cmp to i32
484 define i64 @lowmask_i64_mask64_extra_use(i64 %val) nounwind {
485 ; CHECK-LABEL: lowmask_i64_mask64_extra_use:
487 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
488 ; CHECK-NEXT: movq %rdi, %rcx # encoding: [0x48,0x89,0xf9]
489 ; CHECK-NEXT: shlq $16, %rcx # encoding: [0x48,0xc1,0xe1,0x10]
490 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
491 ; CHECK-NEXT: imulq %rdi, %rax # encoding: [0x48,0x0f,0xaf,0xc7]
492 ; CHECK-NEXT: retq # encoding: [0xc3]
493 %and = and i64 %val, 281474976710655
494 %cmp = icmp eq i64 %and, 0
495 %z = zext i1 %cmp to i64
496 %ret = mul i64 %z, %val
500 define i32 @lowmask_i64_mask32(i64 %val) {
501 ; CHECK-LABEL: lowmask_i64_mask32:
503 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
504 ; CHECK-NEXT: shlq $44, %rdi # encoding: [0x48,0xc1,0xe7,0x2c]
505 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
506 ; CHECK-NEXT: retq # encoding: [0xc3]
507 %and = and i64 %val, 1048575
508 %cmp = icmp ne i64 %and, 0
509 %ret = zext i1 %cmp to i32
513 define i64 @lowmask_i64_mask32_extra_use(i64 %val) nounwind {
514 ; CHECK-LABEL: lowmask_i64_mask32_extra_use:
516 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
517 ; CHECK-NEXT: testl $1048575, %edi # encoding: [0xf7,0xc7,0xff,0xff,0x0f,0x00]
518 ; CHECK-NEXT: # imm = 0xFFFFF
519 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
520 ; CHECK-NEXT: imulq %rdi, %rax # encoding: [0x48,0x0f,0xaf,0xc7]
521 ; CHECK-NEXT: retq # encoding: [0xc3]
522 %and = and i64 %val, 1048575
523 %cmp = icmp ne i64 %and, 0
524 %z = zext i1 %cmp to i64
525 %ret = mul i64 %z, %val
529 define i32 @lowmask_i64_mask8(i64 %val) {
530 ; CHECK-LABEL: lowmask_i64_mask8:
532 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
533 ; CHECK-NEXT: testb $31, %dil # encoding: [0x40,0xf6,0xc7,0x1f]
534 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
535 ; CHECK-NEXT: retq # encoding: [0xc3]
536 %and = and i64 %val, 31
537 %cmp = icmp eq i64 %and, 0
538 %ret = zext i1 %cmp to i32
542 define i32 @highmask_i32_mask32(i32 %val) {
543 ; CHECK-LABEL: highmask_i32_mask32:
545 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
546 ; CHECK-NEXT: testl $-1048576, %edi # encoding: [0xf7,0xc7,0x00,0x00,0xf0,0xff]
547 ; CHECK-NEXT: # imm = 0xFFF00000
548 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
549 ; CHECK-NEXT: retq # encoding: [0xc3]
550 %and = and i32 %val, -1048576
551 %cmp = icmp ne i32 %and, 0
552 %ret = zext i1 %cmp to i32
556 define i32 @highmask_i32_mask8(i32 %val) {
557 ; CHECK-LABEL: highmask_i32_mask8:
559 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
560 ; CHECK-NEXT: testl $-16, %edi # encoding: [0xf7,0xc7,0xf0,0xff,0xff,0xff]
561 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
562 ; CHECK-NEXT: retq # encoding: [0xc3]
563 %and = and i32 %val, -16
564 %cmp = icmp eq i32 %and, 0
565 %ret = zext i1 %cmp to i32
569 define i32 @lowmask_i32_mask32(i32 %val) {
570 ; CHECK-LABEL: lowmask_i32_mask32:
572 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
573 ; CHECK-NEXT: testl $1048575, %edi # encoding: [0xf7,0xc7,0xff,0xff,0x0f,0x00]
574 ; CHECK-NEXT: # imm = 0xFFFFF
575 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
576 ; CHECK-NEXT: retq # encoding: [0xc3]
577 %and = and i32 %val, 1048575
578 %cmp = icmp eq i32 %and, 0
579 %ret = zext i1 %cmp to i32
583 define i32 @lowmask_i32_mask8(i32 %val) {
584 ; CHECK-LABEL: lowmask_i32_mask8:
586 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
587 ; CHECK-NEXT: testb $31, %dil # encoding: [0x40,0xf6,0xc7,0x1f]
588 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
589 ; CHECK-NEXT: retq # encoding: [0xc3]
590 %and = and i32 %val, 31
591 %cmp = icmp ne i32 %and, 0
592 %ret = zext i1 %cmp to i32
596 define i1 @shifted_mask64_testb(i64 %a) {
597 ; CHECK-LABEL: shifted_mask64_testb:
599 ; CHECK-NEXT: shrq $50, %rdi # encoding: [0x48,0xc1,0xef,0x32]
600 ; CHECK-NEXT: testb %dil, %dil # encoding: [0x40,0x84,0xff]
601 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
602 ; CHECK-NEXT: retq # encoding: [0xc3]
603 %v0 = and i64 %a, 287104476244869120 ; 0xff << 50
604 %v1 = icmp ne i64 %v0, 0
608 define i1 @shifted_mask64_testw(i64 %a) {
609 ; CHECK-LABEL: shifted_mask64_testw:
611 ; CHECK-NEXT: shrq $33, %rdi # encoding: [0x48,0xc1,0xef,0x21]
612 ; CHECK-NEXT: testw %di, %di # encoding: [0x66,0x85,0xff]
613 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
614 ; CHECK-NEXT: retq # encoding: [0xc3]
615 %v0 = and i64 %a, 562941363486720 ; 0xffff << 33
616 %v1 = icmp ne i64 %v0, 0
620 define i1 @shifted_mask64_testl(i64 %a) {
621 ; CHECK-LABEL: shifted_mask64_testl:
623 ; CHECK-NEXT: shrq $7, %rdi # encoding: [0x48,0xc1,0xef,0x07]
624 ; CHECK-NEXT: testl %edi, %edi # encoding: [0x85,0xff]
625 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
626 ; CHECK-NEXT: retq # encoding: [0xc3]
627 %v0 = and i64 %a, 549755813760 ; 0xffffffff << 7
628 %v1 = icmp eq i64 %v0, 0
632 define i1 @shifted_mask64_extra_use_const(i64 %a) {
633 ; CHECK-LABEL: shifted_mask64_extra_use_const:
635 ; CHECK-NEXT: movabsq $287104476244869120, %rcx # encoding: [0x48,0xb9,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0x03]
636 ; CHECK-NEXT: # imm = 0x3FC000000000000
637 ; CHECK-NEXT: testq %rcx, %rdi # encoding: [0x48,0x85,0xcf]
638 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
639 ; CHECK-NEXT: movq %rcx, d64(%rip) # encoding: [0x48,0x89,0x0d,A,A,A,A]
640 ; CHECK-NEXT: # fixup A - offset: 3, value: d64-4, kind: reloc_riprel_4byte
641 ; CHECK-NEXT: retq # encoding: [0xc3]
642 %v0 = and i64 %a, 287104476244869120 ; 0xff << 50
643 %v1 = icmp ne i64 %v0, 0
644 store i64 287104476244869120, ptr @d64
648 define i1 @shifted_mask64_extra_use_and(i64 %a) {
649 ; CHECK-LABEL: shifted_mask64_extra_use_and:
651 ; CHECK-NEXT: movabsq $287104476244869120, %rcx # encoding: [0x48,0xb9,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0x03]
652 ; CHECK-NEXT: # imm = 0x3FC000000000000
653 ; CHECK-NEXT: andq %rdi, %rcx # encoding: [0x48,0x21,0xf9]
654 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
655 ; CHECK-NEXT: movq %rcx, d64(%rip) # encoding: [0x48,0x89,0x0d,A,A,A,A]
656 ; CHECK-NEXT: # fixup A - offset: 3, value: d64-4, kind: reloc_riprel_4byte
657 ; CHECK-NEXT: retq # encoding: [0xc3]
658 %v0 = and i64 %a, 287104476244869120 ; 0xff << 50
659 %v1 = icmp ne i64 %v0, 0
660 store i64 %v0, ptr @d64
664 define i1 @shifted_mask32_testl_immediate(i64 %a) {
665 ; CHECK-LABEL: shifted_mask32_testl_immediate:
667 ; CHECK-NEXT: testl $66846720, %edi # encoding: [0xf7,0xc7,0x00,0x00,0xfc,0x03]
668 ; CHECK-NEXT: # imm = 0x3FC0000
669 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
670 ; CHECK-NEXT: retq # encoding: [0xc3]
671 %v0 = and i64 %a, 66846720 ; 0xff << 18
672 %v1 = icmp ne i64 %v0, 0
676 define i1 @shifted_mask32_extra_use_const(i64 %a) {
677 ; CHECK-LABEL: shifted_mask32_extra_use_const:
679 ; CHECK-NEXT: testl $66846720, %edi # encoding: [0xf7,0xc7,0x00,0x00,0xfc,0x03]
680 ; CHECK-NEXT: # imm = 0x3FC0000
681 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
682 ; CHECK-NEXT: movq $66846720, d64(%rip) # encoding: [0x48,0xc7,0x05,A,A,A,A,0x00,0x00,0xfc,0x03]
683 ; CHECK-NEXT: # fixup A - offset: 3, value: d64-8, kind: reloc_riprel_4byte
684 ; CHECK-NEXT: # imm = 0x3FC0000
685 ; CHECK-NEXT: retq # encoding: [0xc3]
686 %v0 = and i64 %a, 66846720 ; 0xff << 18
687 %v1 = icmp ne i64 %v0, 0
688 store i64 66846720, ptr @d64
692 define i1 @shifted_mask32_extra_use_and(i64 %a) {
693 ; CHECK-LABEL: shifted_mask32_extra_use_and:
695 ; CHECK-NEXT: andq $66846720, %rdi # encoding: [0x48,0x81,0xe7,0x00,0x00,0xfc,0x03]
696 ; CHECK-NEXT: # imm = 0x3FC0000
697 ; CHECK-NEXT: setne %al # encoding: [0x0f,0x95,0xc0]
698 ; CHECK-NEXT: movq %rdi, d64(%rip) # encoding: [0x48,0x89,0x3d,A,A,A,A]
699 ; CHECK-NEXT: # fixup A - offset: 3, value: d64-4, kind: reloc_riprel_4byte
700 ; CHECK-NEXT: retq # encoding: [0xc3]
701 %v0 = and i64 %a, 66846720 ; 0xff << 50
702 %v1 = icmp ne i64 %v0, 0
703 store i64 %v0, ptr @d64
707 define { i64, i64 } @pr39968(i64, i64, i32) {
708 ; CHECK-LABEL: pr39968:
710 ; CHECK-NEXT: xorl %eax, %eax # encoding: [0x31,0xc0]
711 ; CHECK-NEXT: testb $64, %dl # encoding: [0xf6,0xc2,0x40]
712 ; CHECK-NEXT: cmovneq %rdi, %rsi # encoding: [0x48,0x0f,0x45,0xf7]
713 ; CHECK-NEXT: cmovneq %rdi, %rax # encoding: [0x48,0x0f,0x45,0xc7]
714 ; CHECK-NEXT: movq %rsi, %rdx # encoding: [0x48,0x89,0xf2]
715 ; CHECK-NEXT: retq # encoding: [0xc3]
717 %5 = icmp ne i32 %4, 0
718 %6 = select i1 %5, i64 %0, i64 %1
719 %7 = select i1 %5, i64 %0, i64 0
720 %8 = insertvalue { i64, i64 } undef, i64 %7, 0
721 %9 = insertvalue { i64, i64 } %8, i64 %6, 1
725 ; Make sure we use a 32-bit comparison without an extend based on the input
726 ; being pre-sign extended by caller.
727 define i32 @pr42189(i16 signext %c) {
728 ; CHECK-LABEL: pr42189:
729 ; CHECK: # %bb.0: # %entry
730 ; CHECK-NEXT: cmpl $32767, %edi # encoding: [0x81,0xff,0xff,0x7f,0x00,0x00]
731 ; CHECK-NEXT: # imm = 0x7FFF
732 ; CHECK-NEXT: jne .LBB45_2 # encoding: [0x75,A]
733 ; CHECK-NEXT: # fixup A - offset: 1, value: .LBB45_2-1, kind: FK_PCRel_1
734 ; CHECK-NEXT: # %bb.1: # %if.then
735 ; CHECK-NEXT: jmp g@PLT # TAILCALL
736 ; CHECK-NEXT: # encoding: [0xeb,A]
737 ; CHECK-NEXT: # fixup A - offset: 1, value: g@PLT-1, kind: FK_PCRel_1
738 ; CHECK-NEXT: .LBB45_2: # %if.end
739 ; CHECK-NEXT: jmp f@PLT # TAILCALL
740 ; CHECK-NEXT: # encoding: [0xeb,A]
741 ; CHECK-NEXT: # fixup A - offset: 1, value: f@PLT-1, kind: FK_PCRel_1
743 %cmp = icmp eq i16 %c, 32767
744 br i1 %cmp, label %if.then, label %if.end
746 if.then: ; preds = %entry
747 %call = tail call i32 @g()
750 if.end: ; preds = %entry
751 %call2 = tail call i32 @f()
754 return: ; preds = %if.end, %if.then
755 %retval.0 = phi i32 [ %call, %if.then ], [ %call2, %if.end ]
762 ; Make sure we fold the load+and into a test from memory.
763 ; The store makes sure the chain result of the load is used which used to
764 ; prevent the post isel peephole from catching this.
765 define i1 @fold_test_and_with_chain(i32* %x, i32* %y, i32 %z) {
766 ; CHECK-LABEL: fold_test_and_with_chain:
768 ; CHECK-NEXT: testl %edx, (%rdi) # encoding: [0x85,0x17]
769 ; CHECK-NEXT: sete %al # encoding: [0x0f,0x94,0xc0]
770 ; CHECK-NEXT: movl %edx, (%rsi) # encoding: [0x89,0x16]
771 ; CHECK-NEXT: retq # encoding: [0xc3]
772 %a = load i32, i32* %x
774 %c = icmp eq i32 %b, 0
775 store i32 %z, i32* %y