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: movb {{[0-9]+}}(%esp), %cl
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: movswl {{[0-9]+}}(%esp), %ecx
38 ; X86-NEXT: movl %ecx, %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: cmovlw %di, %ax
51 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
53 %abs = tail call i16 @llvm.abs.i16(i16 %x, i1 true)
54 %neg = sub nsw i16 0, %abs
58 define i32 @neg_abs_i32(i32 %x) nounwind {
59 ; X86-LABEL: neg_abs_i32:
61 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
62 ; X86-NEXT: movl %ecx, %eax
63 ; X86-NEXT: sarl $31, %eax
64 ; X86-NEXT: xorl %eax, %ecx
65 ; X86-NEXT: subl %ecx, %eax
68 ; X64-LABEL: neg_abs_i32:
70 ; X64-NEXT: movl %edi, %eax
72 ; X64-NEXT: cmovll %edi, %eax
75 %abs = tail call i32 @llvm.abs.i32(i32 %x, i1 true)
76 %neg = sub nsw i32 0, %abs
80 define i64 @neg_abs_i64(i64 %x) nounwind {
81 ; X86-LABEL: neg_abs_i64:
83 ; X86-NEXT: pushl %esi
84 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
85 ; X86-NEXT: movl %ecx, %edx
86 ; X86-NEXT: sarl $31, %edx
87 ; X86-NEXT: xorl %edx, %ecx
88 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
89 ; X86-NEXT: xorl %edx, %esi
90 ; X86-NEXT: movl %edx, %eax
91 ; X86-NEXT: subl %esi, %eax
92 ; X86-NEXT: sbbl %ecx, %edx
96 ; X64-LABEL: neg_abs_i64:
98 ; X64-NEXT: movq %rdi, %rax
100 ; X64-NEXT: cmovlq %rdi, %rax
101 ; X64-NEXT: negq %rax
103 %abs = tail call i64 @llvm.abs.i64(i64 %x, i1 true)
104 %neg = sub nsw i64 0, %abs
108 define i128 @neg_abs_i128(i128 %x) nounwind {
109 ; X86-LABEL: neg_abs_i128:
111 ; X86-NEXT: pushl %ebp
112 ; X86-NEXT: pushl %ebx
113 ; X86-NEXT: pushl %edi
114 ; X86-NEXT: pushl %esi
115 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
116 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
117 ; X86-NEXT: movl %ecx, %edx
118 ; X86-NEXT: sarl $31, %edx
119 ; X86-NEXT: xorl %edx, %ecx
120 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
121 ; X86-NEXT: xorl %edx, %esi
122 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
123 ; X86-NEXT: xorl %edx, %edi
124 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ebx
125 ; X86-NEXT: xorl %edx, %ebx
126 ; X86-NEXT: movl %edx, %ebp
127 ; X86-NEXT: subl %ebx, %ebp
128 ; X86-NEXT: movl %edx, %ebx
129 ; X86-NEXT: sbbl %edi, %ebx
130 ; X86-NEXT: movl %edx, %edi
131 ; X86-NEXT: sbbl %esi, %edi
132 ; X86-NEXT: sbbl %ecx, %edx
133 ; X86-NEXT: movl %ebp, (%eax)
134 ; X86-NEXT: movl %ebx, 4(%eax)
135 ; X86-NEXT: movl %edi, 8(%eax)
136 ; X86-NEXT: movl %edx, 12(%eax)
137 ; X86-NEXT: popl %esi
138 ; X86-NEXT: popl %edi
139 ; X86-NEXT: popl %ebx
140 ; X86-NEXT: popl %ebp
143 ; X64-LABEL: neg_abs_i128:
145 ; X64-NEXT: movq %rsi, %rdx
146 ; X64-NEXT: sarq $63, %rdx
147 ; X64-NEXT: xorq %rdx, %rsi
148 ; X64-NEXT: xorq %rdx, %rdi
149 ; X64-NEXT: movq %rdx, %rax
150 ; X64-NEXT: subq %rdi, %rax
151 ; X64-NEXT: sbbq %rsi, %rdx
153 %abs = tail call i128 @llvm.abs.i128(i128 %x, i1 true)
154 %neg = sub nsw i128 0, %abs