1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-linux | FileCheck %s --check-prefixes=X86
3 ; RUN: llc < %s -mtriple=x86_64-linux | FileCheck %s --check-prefixes=X64
7 define i8 @add_and_xor(i8 %x, i8 %y) {
8 ; X86-LABEL: add_and_xor:
10 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
11 ; X86-NEXT: orb {{[0-9]+}}(%esp), %al
14 ; X64-LABEL: add_and_xor:
16 ; X64-NEXT: movl %edi, %eax
17 ; X64-NEXT: orl %esi, %eax
18 ; X64-NEXT: # kill: def $al killed $al killed $eax
21 %and = and i8 %xor, %y
22 %add = add i8 %and, %x
26 define i8 @add_and_xor_wrong_const(i8 %x, i8 %y) {
27 ; X86-LABEL: add_and_xor_wrong_const:
29 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
30 ; X86-NEXT: movl %ecx, %eax
31 ; X86-NEXT: xorb $-2, %al
32 ; X86-NEXT: andb {{[0-9]+}}(%esp), %al
33 ; X86-NEXT: addb %cl, %al
36 ; X64-LABEL: add_and_xor_wrong_const:
38 ; X64-NEXT: movl %edi, %eax
39 ; X64-NEXT: xorb $-2, %al
40 ; X64-NEXT: andb %sil, %al
41 ; X64-NEXT: addb %dil, %al
44 %and = and i8 %xor, %y
45 %add = add i8 %and, %x
49 define i8 @add_and_xor_wrong_op(i8 %x, i8 %y, i8 %z) {
50 ; X86-LABEL: add_and_xor_wrong_op:
52 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
54 ; X86-NEXT: andb {{[0-9]+}}(%esp), %al
55 ; X86-NEXT: addb {{[0-9]+}}(%esp), %al
58 ; X64-LABEL: add_and_xor_wrong_op:
60 ; X64-NEXT: # kill: def $edx killed $edx def $rdx
61 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
63 ; X64-NEXT: andb %sil, %dl
64 ; X64-NEXT: leal (%rdx,%rdi), %eax
65 ; X64-NEXT: # kill: def $al killed $al killed $eax
68 %and = and i8 %xor, %y
69 %add = add i8 %and, %x
73 define i8 @add_and_xor_commuted1(i8 %x, i8 %y) {
74 ; X86-LABEL: add_and_xor_commuted1:
76 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
77 ; X86-NEXT: orb {{[0-9]+}}(%esp), %al
80 ; X64-LABEL: add_and_xor_commuted1:
82 ; X64-NEXT: movl %edi, %eax
83 ; X64-NEXT: orl %esi, %eax
84 ; X64-NEXT: # kill: def $al killed $al killed $eax
87 %and = and i8 %y, %xor
88 %add = add i8 %and, %x
92 define i8 @add_and_xor_commuted2(i8 %x, i8 %y) {
93 ; X86-LABEL: add_and_xor_commuted2:
95 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
96 ; X86-NEXT: orb {{[0-9]+}}(%esp), %al
99 ; X64-LABEL: add_and_xor_commuted2:
101 ; X64-NEXT: movl %edi, %eax
102 ; X64-NEXT: orl %esi, %eax
103 ; X64-NEXT: # kill: def $al killed $al killed $eax
106 %and = and i8 %xor, %y
107 %add = add i8 %x, %and
111 define i8 @add_and_xor_commuted3(i8 %x, i8 %y) {
112 ; X86-LABEL: add_and_xor_commuted3:
114 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
115 ; X86-NEXT: orb {{[0-9]+}}(%esp), %al
118 ; X64-LABEL: add_and_xor_commuted3:
120 ; X64-NEXT: movl %edi, %eax
121 ; X64-NEXT: orl %esi, %eax
122 ; X64-NEXT: # kill: def $al killed $al killed $eax
125 %and = and i8 %y, %xor
126 %add = add i8 %x, %and
130 define i8 @add_and_xor_extra_use(i8 %x, i8 %y) nounwind {
131 ; X86-LABEL: add_and_xor_extra_use:
133 ; X86-NEXT: pushl %ebx
134 ; X86-NEXT: subl $8, %esp
135 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ebx
136 ; X86-NEXT: movb {{[0-9]+}}(%esp), %bh
138 ; X86-NEXT: movzbl %bh, %eax
139 ; X86-NEXT: movl %eax, (%esp)
140 ; X86-NEXT: calll use@PLT
141 ; X86-NEXT: andb %bl, %bh
142 ; X86-NEXT: movzbl %bh, %eax
143 ; X86-NEXT: movl %eax, (%esp)
144 ; X86-NEXT: calll use@PLT
145 ; X86-NEXT: orb {{[0-9]+}}(%esp), %bl
146 ; X86-NEXT: movl %ebx, %eax
147 ; X86-NEXT: addl $8, %esp
148 ; X86-NEXT: popl %ebx
151 ; X64-LABEL: add_and_xor_extra_use:
153 ; X64-NEXT: pushq %rbp
154 ; X64-NEXT: pushq %r14
155 ; X64-NEXT: pushq %rbx
156 ; X64-NEXT: movl %esi, %ebx
157 ; X64-NEXT: movl %edi, %ebp
158 ; X64-NEXT: movl %ebp, %eax
160 ; X64-NEXT: movzbl %al, %r14d
161 ; X64-NEXT: movl %r14d, %edi
162 ; X64-NEXT: callq use@PLT
163 ; X64-NEXT: andb %bl, %r14b
164 ; X64-NEXT: movzbl %r14b, %edi
165 ; X64-NEXT: callq use@PLT
166 ; X64-NEXT: orb %bpl, %bl
167 ; X64-NEXT: movl %ebx, %eax
168 ; X64-NEXT: popq %rbx
169 ; X64-NEXT: popq %r14
170 ; X64-NEXT: popq %rbp
173 call void @use(i8 %xor)
174 %and = and i8 %xor, %y
175 call void @use(i8 %and)
176 %add = add i8 %and, %x
180 define i64 @add_and_xor_const(i64 %x) {
181 ; X86-LABEL: add_and_xor_const:
183 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
184 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
185 ; X86-NEXT: orl $1, %eax
188 ; X64-LABEL: add_and_xor_const:
190 ; X64-NEXT: movq %rdi, %rax
191 ; X64-NEXT: orq $1, %rax
193 %xor = xor i64 %x, -1
194 %and = and i64 %xor, 1
195 %add = add i64 %and, %x
199 define i64 @add_and_xor_const_wrong_op(i64 %x, i64 %y) {
200 ; X86-LABEL: add_and_xor_const_wrong_op:
202 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
203 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
204 ; X86-NEXT: notl %eax
205 ; X86-NEXT: andl $1, %eax
206 ; X86-NEXT: addl {{[0-9]+}}(%esp), %eax
207 ; X86-NEXT: adcl $0, %edx
210 ; X64-LABEL: add_and_xor_const_wrong_op:
212 ; X64-NEXT: notl %esi
213 ; X64-NEXT: andl $1, %esi
214 ; X64-NEXT: leaq (%rsi,%rdi), %rax
216 %xor = xor i64 %y, -1
217 %and = and i64 %xor, 1
218 %add = add i64 %and, %x
222 define i64 @add_and_xor_const_explicit_trunc(i64 %x) {
223 ; X86-LABEL: add_and_xor_const_explicit_trunc:
225 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
226 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
227 ; X86-NEXT: orl $1, %eax
230 ; X64-LABEL: add_and_xor_const_explicit_trunc:
232 ; X64-NEXT: movq %rdi, %rax
233 ; X64-NEXT: orq $1, %rax
235 %trunc = trunc i64 %x to i32
236 %xor = xor i32 %trunc, -1
237 %ext = sext i32 %xor to i64
238 %and = and i64 %ext, 1
239 %add = add i64 %and, %x
243 define i64 @add_and_xor_const_explicit_trunc_wrong_mask(i64 %x) {
244 ; X86-LABEL: add_and_xor_const_explicit_trunc_wrong_mask:
246 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
247 ; X86-NEXT: movl %ecx, %eax
248 ; X86-NEXT: notl %eax
249 ; X86-NEXT: movl %eax, %edx
250 ; X86-NEXT: shrl $31, %edx
251 ; X86-NEXT: andl $1, %eax
252 ; X86-NEXT: addl %ecx, %eax
253 ; X86-NEXT: adcl {{[0-9]+}}(%esp), %edx
256 ; X64-LABEL: add_and_xor_const_explicit_trunc_wrong_mask:
258 ; X64-NEXT: movl %edi, %eax
259 ; X64-NEXT: notl %eax
260 ; X64-NEXT: movslq %eax, %rcx
261 ; X64-NEXT: movabsq $4294967297, %rax # imm = 0x100000001
262 ; X64-NEXT: andq %rcx, %rax
263 ; X64-NEXT: addq %rdi, %rax
265 %trunc = trunc i64 %x to i32
266 %xor = xor i32 %trunc, -1
267 %ext = sext i32 %xor to i64
268 %and = and i64 %ext, 4294967297
269 %add = add i64 %and, %x
273 define ptr @gep_and_xor(ptr %a, i64 %m) {
274 ; X86-LABEL: gep_and_xor:
276 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
277 ; X86-NEXT: orl {{[0-9]+}}(%esp), %eax
280 ; X64-LABEL: gep_and_xor:
282 ; X64-NEXT: movq %rdi, %rax
283 ; X64-NEXT: orq %rsi, %rax
285 %old = ptrtoint ptr %a to i64
286 %old.not = and i64 %old, %m
287 %offset = xor i64 %old.not, %m
288 %p = getelementptr i8, ptr %a, i64 %offset
292 define ptr @gep_and_xor_const(ptr %a) {
293 ; X86-LABEL: gep_and_xor_const:
295 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
296 ; X86-NEXT: orl $1, %eax
299 ; X64-LABEL: gep_and_xor_const:
301 ; X64-NEXT: movq %rdi, %rax
302 ; X64-NEXT: orq $1, %rax
304 %old = ptrtoint ptr %a to i64
305 %old.not = and i64 %old, 1
306 %offset = xor i64 %old.not, 1
307 %p = getelementptr i8, ptr %a, i64 %offset
311 define i64 @add_and_xor_const_zext_trunc(i64 %x) {
312 ; X86-LABEL: add_and_xor_const_zext_trunc:
314 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
315 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
316 ; X86-NEXT: orl $1, %eax
319 ; X64-LABEL: add_and_xor_const_zext_trunc:
321 ; X64-NEXT: movq %rdi, %rax
322 ; X64-NEXT: orq $1, %rax
324 %t = trunc i64 %x to i32
325 %xor = xor i32 %t, -1
326 %and = and i32 %xor, 1
327 %ext = zext i32 %and to i64
328 %add = add i64 %ext, %x
332 define i64 @add_and_xor_const_zext_trunc_var(i64 %x, i64 %y) {
333 ; X86-LABEL: add_and_xor_const_zext_trunc_var:
335 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
336 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
337 ; X86-NEXT: orl {{[0-9]+}}(%esp), %eax
340 ; X64-LABEL: add_and_xor_const_zext_trunc_var:
342 ; X64-NEXT: movl %esi, %eax
343 ; X64-NEXT: orq %rdi, %rax
345 %tx = trunc i64 %x to i32
346 %ty = trunc i64 %y to i32
347 %xor = xor i32 %tx, -1
348 %and = and i32 %ty, %xor
349 %ext = zext i32 %and to i64
350 %add = add i64 %ext, %x