1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=x86_64-unknown-unknown -show-mc-encoding < %s | FileCheck %s
4 ; Test that the direct object emission selects the 'and' variant with 8-bit
6 ; We used to get this wrong when using direct object emission, but not when
9 define void @f1() nounwind {
12 ; CHECK-NEXT: pushq %rbp # encoding: [0x55]
13 ; CHECK-NEXT: movq %rsp, %rbp # encoding: [0x48,0x89,0xe5]
14 ; CHECK-NEXT: andq $-32, %rsp # encoding: [0x48,0x83,0xe4,0xe0]
15 ; CHECK-NEXT: movq %rbp, %rsp # encoding: [0x48,0x89,0xec]
16 ; CHECK-NEXT: popq %rbp # encoding: [0x5d]
17 ; CHECK-NEXT: retq # encoding: [0xc3]
18 %foo = alloca i8, align 32
22 define void @f2(i16 %x, ptr%y) nounwind {
25 ; CHECK-NEXT: andl $1, %edi # encoding: [0x83,0xe7,0x01]
26 ; CHECK-NEXT: movb %dil, (%rsi) # encoding: [0x40,0x88,0x3e]
27 ; CHECK-NEXT: retq # encoding: [0xc3]
28 %c = trunc i16 %x to i1
33 define void @f3(i32 %x, ptr%y) nounwind {
36 ; CHECK-NEXT: andl $1, %edi # encoding: [0x83,0xe7,0x01]
37 ; CHECK-NEXT: movb %dil, (%rsi) # encoding: [0x40,0x88,0x3e]
38 ; CHECK-NEXT: retq # encoding: [0xc3]
39 %c = trunc i32 %x to i1
44 ; The immediate (0x0ffffff0) can be made into an i8 by making it negative.
46 define i32 @lopped32_32to8(i32 %x) {
47 ; CHECK-LABEL: lopped32_32to8:
49 ; CHECK-NEXT: movl %edi, %eax # encoding: [0x89,0xf8]
50 ; CHECK-NEXT: shrl $4, %eax # encoding: [0xc1,0xe8,0x04]
51 ; CHECK-NEXT: andl $-16, %eax # encoding: [0x83,0xe0,0xf0]
52 ; CHECK-NEXT: retq # encoding: [0xc3]
54 %and = and i32 %shr, 268435440
58 ; The immediate (0x0ffffff0) can be made into an i8 by making it negative.
60 define i64 @lopped64_32to8(i64 %x) {
61 ; CHECK-LABEL: lopped64_32to8:
63 ; CHECK-NEXT: movq %rdi, %rax # encoding: [0x48,0x89,0xf8]
64 ; CHECK-NEXT: shrq $36, %rax # encoding: [0x48,0xc1,0xe8,0x24]
65 ; CHECK-NEXT: andl $-16, %eax # encoding: [0x83,0xe0,0xf0]
66 ; CHECK-NEXT: retq # encoding: [0xc3]
67 %shr = lshr i64 %x, 36
68 %and = and i64 %shr, 268435440
72 ; The immediate (0x0ffffffffffffff0) can be made into an i8 by making it negative.
74 define i64 @lopped64_64to8(i64 %x) {
75 ; CHECK-LABEL: lopped64_64to8:
77 ; CHECK-NEXT: movq %rdi, %rax # encoding: [0x48,0x89,0xf8]
78 ; CHECK-NEXT: shrq $4, %rax # encoding: [0x48,0xc1,0xe8,0x04]
79 ; CHECK-NEXT: andq $-16, %rax # encoding: [0x48,0x83,0xe0,0xf0]
80 ; CHECK-NEXT: retq # encoding: [0xc3]
82 %and = and i64 %shr, 1152921504606846960
86 ; The immediate (0x0ffffffffff0fff0) can be made into an i32 by making it negative.
88 define i64 @lopped64_64to32(i64 %x) {
89 ; CHECK-LABEL: lopped64_64to32:
91 ; CHECK-NEXT: movq %rdi, %rax # encoding: [0x48,0x89,0xf8]
92 ; CHECK-NEXT: shrq $4, %rax # encoding: [0x48,0xc1,0xe8,0x04]
93 ; CHECK-NEXT: andq $-983056, %rax # encoding: [0x48,0x25,0xf0,0xff,0xf0,0xff]
94 ; CHECK-NEXT: # imm = 0xFFF0FFF0
95 ; CHECK-NEXT: retq # encoding: [0xc3]
97 %and = and i64 %shr, 1152921504605863920
101 ; The transform is not limited to shifts - computeKnownBits() knows the top 4 bits
102 ; must be cleared, so 0x0fffff80 can become 0x80 sign-extended.
104 define i32 @shrinkAndKnownBits(i32 %x) {
105 ; CHECK-LABEL: shrinkAndKnownBits:
107 ; CHECK-NEXT: movl %edi, %ecx # encoding: [0x89,0xf9]
108 ; CHECK-NEXT: movl $4042322161, %eax # encoding: [0xb8,0xf1,0xf0,0xf0,0xf0]
109 ; CHECK-NEXT: # imm = 0xF0F0F0F1
110 ; CHECK-NEXT: imulq %rcx, %rax # encoding: [0x48,0x0f,0xaf,0xc1]
111 ; CHECK-NEXT: shrq $36, %rax # encoding: [0x48,0xc1,0xe8,0x24]
112 ; CHECK-NEXT: andl $-128, %eax # encoding: [0x83,0xe0,0x80]
113 ; CHECK-NEXT: # kill: def $eax killed $eax killed $rax
114 ; CHECK-NEXT: retq # encoding: [0xc3]
115 %div = udiv i32 %x, 17
116 %and = and i32 %div, 268435328