1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-- | FileCheck %s --check-prefixes=X86
3 ; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s --check-prefixes=X64
6 ; fixed avg(x,y) = add(and(x,y),ashr(xor(x,y),1))
8 ; ext avg(x,y) = trunc(ashr(add(sext(x),sext(y)),1))
11 define i8 @test_fixed_i8(i8 %a0, i8 %a1) nounwind {
12 ; X86-LABEL: test_fixed_i8:
14 ; X86-NEXT: movsbl {{[0-9]+}}(%esp), %ecx
15 ; X86-NEXT: movsbl {{[0-9]+}}(%esp), %eax
16 ; X86-NEXT: addl %ecx, %eax
18 ; X86-NEXT: # kill: def $al killed $al killed $eax
21 ; X64-LABEL: test_fixed_i8:
23 ; X64-NEXT: movsbl %sil, %ecx
24 ; X64-NEXT: movsbl %dil, %eax
25 ; X64-NEXT: addl %ecx, %eax
27 ; X64-NEXT: # kill: def $al killed $al killed $eax
29 %and = and i8 %a0, %a1
30 %xor = xor i8 %a0, %a1
31 %shift = ashr i8 %xor, 1
32 %res = add i8 %and, %shift
36 define i8 @test_ext_i8(i8 %a0, i8 %a1) nounwind {
37 ; X86-LABEL: test_ext_i8:
39 ; X86-NEXT: movsbl {{[0-9]+}}(%esp), %ecx
40 ; X86-NEXT: movsbl {{[0-9]+}}(%esp), %eax
41 ; X86-NEXT: addl %ecx, %eax
43 ; X86-NEXT: # kill: def $al killed $al killed $eax
46 ; X64-LABEL: test_ext_i8:
48 ; X64-NEXT: movsbl %sil, %ecx
49 ; X64-NEXT: movsbl %dil, %eax
50 ; X64-NEXT: addl %ecx, %eax
52 ; X64-NEXT: # kill: def $al killed $al killed $eax
54 %x0 = sext i8 %a0 to i16
55 %x1 = sext i8 %a1 to i16
56 %sum = add i16 %x0, %x1
57 %shift = ashr i16 %sum, 1
58 %res = trunc i16 %shift to i8
62 define i16 @test_fixed_i16(i16 %a0, i16 %a1) nounwind {
63 ; X86-LABEL: test_fixed_i16:
65 ; X86-NEXT: movswl {{[0-9]+}}(%esp), %ecx
66 ; X86-NEXT: movswl {{[0-9]+}}(%esp), %eax
67 ; X86-NEXT: addl %ecx, %eax
69 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
72 ; X64-LABEL: test_fixed_i16:
74 ; X64-NEXT: movswl %si, %ecx
75 ; X64-NEXT: movswl %di, %eax
76 ; X64-NEXT: addl %ecx, %eax
78 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
80 %and = and i16 %a0, %a1
81 %xor = xor i16 %a0, %a1
82 %shift = ashr i16 %xor, 1
83 %res = add i16 %and, %shift
87 define i16 @test_ext_i16(i16 %a0, i16 %a1) nounwind {
88 ; X86-LABEL: test_ext_i16:
90 ; X86-NEXT: movswl {{[0-9]+}}(%esp), %ecx
91 ; X86-NEXT: movswl {{[0-9]+}}(%esp), %eax
92 ; X86-NEXT: addl %ecx, %eax
94 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
97 ; X64-LABEL: test_ext_i16:
99 ; X64-NEXT: movswl %si, %ecx
100 ; X64-NEXT: movswl %di, %eax
101 ; X64-NEXT: addl %ecx, %eax
102 ; X64-NEXT: shrl %eax
103 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
105 %x0 = sext i16 %a0 to i32
106 %x1 = sext i16 %a1 to i32
107 %sum = add i32 %x0, %x1
108 %shift = ashr i32 %sum, 1
109 %res = trunc i32 %shift to i16
113 define i32 @test_fixed_i32(i32 %a0, i32 %a1) nounwind {
114 ; X86-LABEL: test_fixed_i32:
116 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
117 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
118 ; X86-NEXT: movl %eax, %edx
119 ; X86-NEXT: andl %ecx, %edx
120 ; X86-NEXT: xorl %ecx, %eax
121 ; X86-NEXT: sarl %eax
122 ; X86-NEXT: addl %edx, %eax
125 ; X64-LABEL: test_fixed_i32:
127 ; X64-NEXT: movslq %esi, %rcx
128 ; X64-NEXT: movslq %edi, %rax
129 ; X64-NEXT: addq %rcx, %rax
130 ; X64-NEXT: shrq %rax
131 ; X64-NEXT: # kill: def $eax killed $eax killed $rax
133 %and = and i32 %a0, %a1
134 %xor = xor i32 %a1, %a0
135 %shift = ashr i32 %xor, 1
136 %res = add i32 %and, %shift
140 define i32 @test_ext_i32(i32 %a0, i32 %a1) nounwind {
141 ; X86-LABEL: test_ext_i32:
143 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
144 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
145 ; X86-NEXT: movl %eax, %edx
146 ; X86-NEXT: andl %ecx, %edx
147 ; X86-NEXT: xorl %ecx, %eax
148 ; X86-NEXT: sarl %eax
149 ; X86-NEXT: addl %edx, %eax
152 ; X64-LABEL: test_ext_i32:
154 ; X64-NEXT: movslq %esi, %rcx
155 ; X64-NEXT: movslq %edi, %rax
156 ; X64-NEXT: addq %rcx, %rax
157 ; X64-NEXT: shrq %rax
158 ; X64-NEXT: # kill: def $eax killed $eax killed $rax
160 %x0 = sext i32 %a0 to i64
161 %x1 = sext i32 %a1 to i64
162 %sum = add i64 %x0, %x1
163 %shift = ashr i64 %sum, 1
164 %res = trunc i64 %shift to i32
168 define i64 @test_fixed_i64(i64 %a0, i64 %a1) nounwind {
169 ; X86-LABEL: test_fixed_i64:
171 ; X86-NEXT: pushl %ebx
172 ; X86-NEXT: pushl %edi
173 ; X86-NEXT: pushl %esi
174 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
175 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
176 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
177 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
178 ; X86-NEXT: movl %eax, %ebx
179 ; X86-NEXT: xorl %esi, %ebx
180 ; X86-NEXT: movl %ecx, %edx
181 ; X86-NEXT: xorl %edi, %edx
182 ; X86-NEXT: shrdl $1, %edx, %ebx
183 ; X86-NEXT: andl %edi, %ecx
184 ; X86-NEXT: sarl %edx
185 ; X86-NEXT: andl %esi, %eax
186 ; X86-NEXT: addl %ebx, %eax
187 ; X86-NEXT: adcl %ecx, %edx
188 ; X86-NEXT: popl %esi
189 ; X86-NEXT: popl %edi
190 ; X86-NEXT: popl %ebx
193 ; X64-LABEL: test_fixed_i64:
195 ; X64-NEXT: movq %rdi, %rax
196 ; X64-NEXT: andq %rsi, %rax
197 ; X64-NEXT: xorq %rsi, %rdi
198 ; X64-NEXT: sarq %rdi
199 ; X64-NEXT: addq %rdi, %rax
201 %and = and i64 %a0, %a1
202 %xor = xor i64 %a1, %a0
203 %shift = ashr i64 %xor, 1
204 %res = add i64 %and, %shift
208 define i64 @test_ext_i64(i64 %a0, i64 %a1) nounwind {
209 ; X86-LABEL: test_ext_i64:
211 ; X86-NEXT: pushl %ebx
212 ; X86-NEXT: pushl %edi
213 ; X86-NEXT: pushl %esi
214 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
215 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
216 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
217 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
218 ; X86-NEXT: movl %eax, %ebx
219 ; X86-NEXT: xorl %esi, %ebx
220 ; X86-NEXT: movl %ecx, %edx
221 ; X86-NEXT: xorl %edi, %edx
222 ; X86-NEXT: shrdl $1, %edx, %ebx
223 ; X86-NEXT: andl %edi, %ecx
224 ; X86-NEXT: sarl %edx
225 ; X86-NEXT: andl %esi, %eax
226 ; X86-NEXT: addl %ebx, %eax
227 ; X86-NEXT: adcl %ecx, %edx
228 ; X86-NEXT: popl %esi
229 ; X86-NEXT: popl %edi
230 ; X86-NEXT: popl %ebx
233 ; X64-LABEL: test_ext_i64:
235 ; X64-NEXT: movq %rdi, %rax
236 ; X64-NEXT: andq %rsi, %rax
237 ; X64-NEXT: xorq %rsi, %rdi
238 ; X64-NEXT: sarq %rdi
239 ; X64-NEXT: addq %rdi, %rax
241 %x0 = sext i64 %a0 to i128
242 %x1 = sext i64 %a1 to i128
243 %sum = add i128 %x0, %x1
244 %shift = ashr i128 %sum, 1
245 %res = trunc i128 %shift to i64