1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -verify-machineinstrs -mtriple=i686-unknown-unknown | FileCheck %s --check-prefix=X86
3 ; RUN: llc < %s -verify-machineinstrs -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=X64
5 declare i8 @llvm.abs.i8(i8, i1)
6 declare i16 @llvm.abs.i16(i16, i1)
7 declare i24 @llvm.abs.i24(i24, i1)
8 declare i32 @llvm.abs.i32(i32, i1)
9 declare i64 @llvm.abs.i64(i64, i1)
10 declare i128 @llvm.abs.i128(i128, i1)
12 define i8 @neg_abs_i8(i8 %x) nounwind {
13 ; X86-LABEL: neg_abs_i8:
15 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
16 ; X86-NEXT: movl %ecx, %eax
17 ; X86-NEXT: sarb $7, %al
18 ; X86-NEXT: xorb %al, %cl
19 ; X86-NEXT: subb %cl, %al
22 ; X64-LABEL: neg_abs_i8:
24 ; X64-NEXT: movl %edi, %eax
25 ; X64-NEXT: sarb $7, %al
26 ; X64-NEXT: xorb %al, %dil
27 ; X64-NEXT: subb %dil, %al
29 %abs = tail call i8 @llvm.abs.i8(i8 %x, i1 true)
30 %neg = sub nsw i8 0, %abs
34 define i16 @neg_abs_i16(i16 %x) nounwind {
35 ; X86-LABEL: neg_abs_i16:
37 ; X86-NEXT: movzwl {{[0-9]+}}(%esp), %ecx
38 ; X86-NEXT: movswl %cx, %eax
39 ; X86-NEXT: sarl $15, %eax
40 ; X86-NEXT: xorl %eax, %ecx
41 ; X86-NEXT: subl %ecx, %eax
42 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
45 ; X64-LABEL: neg_abs_i16:
47 ; X64-NEXT: movl %edi, %eax
49 ; X64-NEXT: cmovnsw %di, %ax
51 %abs = tail call i16 @llvm.abs.i16(i16 %x, i1 true)
52 %neg = sub nsw i16 0, %abs
56 define i32 @neg_abs_i32(i32 %x) nounwind {
57 ; X86-LABEL: neg_abs_i32:
59 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
60 ; X86-NEXT: movl %ecx, %eax
61 ; X86-NEXT: sarl $31, %eax
62 ; X86-NEXT: xorl %eax, %ecx
63 ; X86-NEXT: subl %ecx, %eax
66 ; X64-LABEL: neg_abs_i32:
68 ; X64-NEXT: movl %edi, %eax
70 ; X64-NEXT: cmovnsl %edi, %eax
72 %abs = tail call i32 @llvm.abs.i32(i32 %x, i1 true)
73 %neg = sub nsw i32 0, %abs
77 define i64 @neg_abs_i64(i64 %x) nounwind {
78 ; X86-LABEL: neg_abs_i64:
80 ; X86-NEXT: pushl %esi
81 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
82 ; X86-NEXT: movl %ecx, %edx
83 ; X86-NEXT: sarl $31, %edx
84 ; X86-NEXT: xorl %edx, %ecx
85 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
86 ; X86-NEXT: xorl %edx, %esi
87 ; X86-NEXT: movl %edx, %eax
88 ; X86-NEXT: subl %esi, %eax
89 ; X86-NEXT: sbbl %ecx, %edx
93 ; X64-LABEL: neg_abs_i64:
95 ; X64-NEXT: movq %rdi, %rax
97 ; X64-NEXT: cmovnsq %rdi, %rax
99 %abs = tail call i64 @llvm.abs.i64(i64 %x, i1 true)
100 %neg = sub nsw i64 0, %abs
104 define i128 @neg_abs_i128(i128 %x) nounwind {
105 ; X86-LABEL: neg_abs_i128:
107 ; X86-NEXT: pushl %ebp
108 ; X86-NEXT: pushl %ebx
109 ; X86-NEXT: pushl %edi
110 ; X86-NEXT: pushl %esi
111 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
112 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
113 ; X86-NEXT: movl %edx, %ecx
114 ; X86-NEXT: sarl $31, %ecx
115 ; X86-NEXT: xorl %ecx, %edx
116 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
117 ; X86-NEXT: xorl %ecx, %esi
118 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
119 ; X86-NEXT: xorl %ecx, %edi
120 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ebx
121 ; X86-NEXT: xorl %ecx, %ebx
122 ; X86-NEXT: movl %ecx, %ebp
123 ; X86-NEXT: subl %ebx, %ebp
124 ; X86-NEXT: movl %ecx, %ebx
125 ; X86-NEXT: sbbl %edi, %ebx
126 ; X86-NEXT: movl %ecx, %edi
127 ; X86-NEXT: sbbl %esi, %edi
128 ; X86-NEXT: sbbl %edx, %ecx
129 ; X86-NEXT: movl %ebp, (%eax)
130 ; X86-NEXT: movl %ebx, 4(%eax)
131 ; X86-NEXT: movl %edi, 8(%eax)
132 ; X86-NEXT: movl %ecx, 12(%eax)
133 ; X86-NEXT: popl %esi
134 ; X86-NEXT: popl %edi
135 ; X86-NEXT: popl %ebx
136 ; X86-NEXT: popl %ebp
139 ; X64-LABEL: neg_abs_i128:
141 ; X64-NEXT: movq %rsi, %rdx
142 ; X64-NEXT: sarq $63, %rdx
143 ; X64-NEXT: xorq %rdx, %rsi
144 ; X64-NEXT: xorq %rdx, %rdi
145 ; X64-NEXT: movq %rdx, %rax
146 ; X64-NEXT: subq %rdi, %rax
147 ; X64-NEXT: sbbq %rsi, %rdx
149 %abs = tail call i128 @llvm.abs.i128(i128 %x, i1 true)
150 %neg = sub nsw i128 0, %abs
154 define i8 @sub_abs_i8(i8 %x, i8 %y) nounwind {
155 ; X86-LABEL: sub_abs_i8:
157 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
158 ; X86-NEXT: movl %ecx, %eax
159 ; X86-NEXT: sarb $7, %al
160 ; X86-NEXT: xorb %al, %cl
161 ; X86-NEXT: subb %cl, %al
162 ; X86-NEXT: addb {{[0-9]+}}(%esp), %al
165 ; X64-LABEL: sub_abs_i8:
167 ; X64-NEXT: movl %edi, %eax
168 ; X64-NEXT: sarb $7, %al
169 ; X64-NEXT: xorb %al, %dil
170 ; X64-NEXT: subb %dil, %al
171 ; X64-NEXT: addb %sil, %al
173 %abs = tail call i8 @llvm.abs.i8(i8 %x, i1 false)
174 %neg = sub nsw i8 %y, %abs
178 define i16 @sub_abs_i16(i16 %x, i16 %y) nounwind {
179 ; X86-LABEL: sub_abs_i16:
181 ; X86-NEXT: movzwl {{[0-9]+}}(%esp), %ecx
182 ; X86-NEXT: movswl %cx, %eax
183 ; X86-NEXT: sarl $15, %eax
184 ; X86-NEXT: xorl %eax, %ecx
185 ; X86-NEXT: subl %ecx, %eax
186 ; X86-NEXT: addl {{[0-9]+}}(%esp), %eax
187 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
190 ; X64-LABEL: sub_abs_i16:
192 ; X64-NEXT: movl %edi, %eax
194 ; X64-NEXT: cmovnsw %di, %ax
195 ; X64-NEXT: addl %esi, %eax
196 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
198 %abs = tail call i16 @llvm.abs.i16(i16 %x, i1 false)
199 %neg = sub i16 %y, %abs
203 define i32 @sub_abs_i32(i32 %x, i32 %y) nounwind {
204 ; X86-LABEL: sub_abs_i32:
206 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
207 ; X86-NEXT: movl %ecx, %eax
208 ; X86-NEXT: sarl $31, %eax
209 ; X86-NEXT: xorl %eax, %ecx
210 ; X86-NEXT: subl %ecx, %eax
211 ; X86-NEXT: addl {{[0-9]+}}(%esp), %eax
214 ; X64-LABEL: sub_abs_i32:
216 ; X64-NEXT: movl %edi, %eax
217 ; X64-NEXT: negl %eax
218 ; X64-NEXT: cmovnsl %edi, %eax
219 ; X64-NEXT: addl %esi, %eax
221 %abs = tail call i32 @llvm.abs.i32(i32 %x, i1 false)
222 %neg = sub i32 %y, %abs
226 define i64 @sub_abs_i64(i64 %x, i64 %y) nounwind {
227 ; X86-LABEL: sub_abs_i64:
229 ; X86-NEXT: pushl %edi
230 ; X86-NEXT: pushl %esi
231 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
232 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
233 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
234 ; X86-NEXT: movl %ecx, %esi
235 ; X86-NEXT: sarl $31, %esi
236 ; X86-NEXT: xorl %esi, %ecx
237 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
238 ; X86-NEXT: xorl %esi, %edi
239 ; X86-NEXT: subl %esi, %edi
240 ; X86-NEXT: sbbl %esi, %ecx
241 ; X86-NEXT: subl %edi, %eax
242 ; X86-NEXT: sbbl %ecx, %edx
243 ; X86-NEXT: popl %esi
244 ; X86-NEXT: popl %edi
247 ; X64-LABEL: sub_abs_i64:
249 ; X64-NEXT: movq %rdi, %rax
250 ; X64-NEXT: negq %rax
251 ; X64-NEXT: cmovnsq %rdi, %rax
252 ; X64-NEXT: addq %rsi, %rax
254 %abs = tail call i64 @llvm.abs.i64(i64 %x, i1 false)
255 %neg = sub i64 %y, %abs
259 define i128 @sub_abs_i128(i128 %x, i128 %y) nounwind {
260 ; X86-LABEL: sub_abs_i128:
262 ; X86-NEXT: pushl %edi
263 ; X86-NEXT: pushl %esi
264 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
265 ; X86-NEXT: movl %eax, %edx
266 ; X86-NEXT: sarl $31, %edx
267 ; X86-NEXT: xorl %edx, %eax
268 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
269 ; X86-NEXT: xorl %edx, %ecx
270 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
271 ; X86-NEXT: xorl %edx, %esi
272 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
273 ; X86-NEXT: xorl %edx, %edi
274 ; X86-NEXT: subl %edx, %edi
275 ; X86-NEXT: sbbl %edx, %esi
276 ; X86-NEXT: sbbl %edx, %ecx
277 ; X86-NEXT: sbbl %edx, %eax
278 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
279 ; X86-NEXT: subl %edi, %edx
280 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
281 ; X86-NEXT: sbbl %esi, %edi
282 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
283 ; X86-NEXT: sbbl %ecx, %esi
284 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
285 ; X86-NEXT: sbbl %eax, %ecx
286 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
287 ; X86-NEXT: movl %edx, (%eax)
288 ; X86-NEXT: movl %edi, 4(%eax)
289 ; X86-NEXT: movl %esi, 8(%eax)
290 ; X86-NEXT: movl %ecx, 12(%eax)
291 ; X86-NEXT: popl %esi
292 ; X86-NEXT: popl %edi
295 ; X64-LABEL: sub_abs_i128:
297 ; X64-NEXT: movq %rdx, %rax
298 ; X64-NEXT: movq %rsi, %rdx
299 ; X64-NEXT: sarq $63, %rdx
300 ; X64-NEXT: xorq %rdx, %rsi
301 ; X64-NEXT: xorq %rdx, %rdi
302 ; X64-NEXT: subq %rdx, %rdi
303 ; X64-NEXT: sbbq %rdx, %rsi
304 ; X64-NEXT: subq %rdi, %rax
305 ; X64-NEXT: sbbq %rsi, %rcx
306 ; X64-NEXT: movq %rcx, %rdx
308 %abs = tail call i128 @llvm.abs.i128(i128 %x, i1 false)
309 %neg = sub i128 %y, %abs