1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s --check-prefix=X86 --check-prefix=X86-NO-CMOV
3 ; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+cmov | FileCheck %s --check-prefix=X86 --check-prefix=X86-CMOV
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=X64
6 ;; Integer absolute value, should produce something at least as good as:
12 define i8 @test_i8(i8 %a) nounwind {
15 ; X86-NEXT: movzbl {{[0-9]+}}(%esp), %eax
16 ; X86-NEXT: movl %eax, %ecx
17 ; X86-NEXT: sarb $7, %cl
18 ; X86-NEXT: xorb %cl, %al
19 ; X86-NEXT: subb %cl, %al
24 ; X64-NEXT: movl %edi, %eax
25 ; X64-NEXT: movl %eax, %ecx
26 ; X64-NEXT: sarb $7, %cl
27 ; X64-NEXT: xorb %cl, %al
28 ; X64-NEXT: subb %cl, %al
29 ; X64-NEXT: # kill: def $al killed $al killed $eax
31 %tmp1neg = sub i8 0, %a
32 %b = icmp sgt i8 %a, -1
33 %abs = select i1 %b, i8 %a, i8 %tmp1neg
37 define i16 @test_i16(i16 %a) nounwind {
38 ; X86-NO-CMOV-LABEL: test_i16:
39 ; X86-NO-CMOV: # %bb.0:
40 ; X86-NO-CMOV-NEXT: movzwl {{[0-9]+}}(%esp), %eax
41 ; X86-NO-CMOV-NEXT: movswl %ax, %ecx
42 ; X86-NO-CMOV-NEXT: sarl $15, %ecx
43 ; X86-NO-CMOV-NEXT: xorl %ecx, %eax
44 ; X86-NO-CMOV-NEXT: subl %ecx, %eax
45 ; X86-NO-CMOV-NEXT: # kill: def $ax killed $ax killed $eax
46 ; X86-NO-CMOV-NEXT: retl
48 ; X86-CMOV-LABEL: test_i16:
50 ; X86-CMOV-NEXT: movzwl {{[0-9]+}}(%esp), %ecx
51 ; X86-CMOV-NEXT: movl %ecx, %eax
52 ; X86-CMOV-NEXT: negw %ax
53 ; X86-CMOV-NEXT: cmovsw %cx, %ax
56 ; X64-LABEL: test_i16:
58 ; X64-NEXT: movl %edi, %eax
60 ; X64-NEXT: cmovsw %di, %ax
62 %tmp1neg = sub i16 0, %a
63 %b = icmp sgt i16 %a, -1
64 %abs = select i1 %b, i16 %a, i16 %tmp1neg
68 define i32 @test_i32(i32 %a) nounwind {
69 ; X86-NO-CMOV-LABEL: test_i32:
70 ; X86-NO-CMOV: # %bb.0:
71 ; X86-NO-CMOV-NEXT: movl {{[0-9]+}}(%esp), %eax
72 ; X86-NO-CMOV-NEXT: movl %eax, %ecx
73 ; X86-NO-CMOV-NEXT: sarl $31, %ecx
74 ; X86-NO-CMOV-NEXT: xorl %ecx, %eax
75 ; X86-NO-CMOV-NEXT: subl %ecx, %eax
76 ; X86-NO-CMOV-NEXT: retl
78 ; X86-CMOV-LABEL: test_i32:
80 ; X86-CMOV-NEXT: movl {{[0-9]+}}(%esp), %ecx
81 ; X86-CMOV-NEXT: movl %ecx, %eax
82 ; X86-CMOV-NEXT: negl %eax
83 ; X86-CMOV-NEXT: cmovsl %ecx, %eax
86 ; X64-LABEL: test_i32:
88 ; X64-NEXT: movl %edi, %eax
90 ; X64-NEXT: cmovsl %edi, %eax
92 %tmp1neg = sub i32 0, %a
93 %b = icmp sgt i32 %a, -1
94 %abs = select i1 %b, i32 %a, i32 %tmp1neg
98 define i64 @test_i64(i64 %a) nounwind {
99 ; X86-LABEL: test_i64:
101 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
102 ; X86-NEXT: movl %edx, %ecx
103 ; X86-NEXT: sarl $31, %ecx
104 ; X86-NEXT: xorl %ecx, %edx
105 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
106 ; X86-NEXT: xorl %ecx, %eax
107 ; X86-NEXT: subl %ecx, %eax
108 ; X86-NEXT: sbbl %ecx, %edx
111 ; X64-LABEL: test_i64:
113 ; X64-NEXT: movq %rdi, %rax
114 ; X64-NEXT: negq %rax
115 ; X64-NEXT: cmovsq %rdi, %rax
117 %tmp1neg = sub i64 0, %a
118 %b = icmp sgt i64 %a, -1
119 %abs = select i1 %b, i64 %a, i64 %tmp1neg
123 define i128 @test_i128(i128 %a) nounwind {
124 ; X86-LABEL: test_i128:
126 ; X86-NEXT: pushl %ebx
127 ; X86-NEXT: pushl %edi
128 ; X86-NEXT: pushl %esi
129 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
130 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
131 ; X86-NEXT: movl %ecx, %edx
132 ; X86-NEXT: sarl $31, %edx
133 ; X86-NEXT: xorl %edx, %ecx
134 ; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
135 ; X86-NEXT: xorl %edx, %esi
136 ; X86-NEXT: movl {{[0-9]+}}(%esp), %edi
137 ; X86-NEXT: xorl %edx, %edi
138 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ebx
139 ; X86-NEXT: xorl %edx, %ebx
140 ; X86-NEXT: subl %edx, %ebx
141 ; X86-NEXT: sbbl %edx, %edi
142 ; X86-NEXT: sbbl %edx, %esi
143 ; X86-NEXT: sbbl %edx, %ecx
144 ; X86-NEXT: movl %ebx, (%eax)
145 ; X86-NEXT: movl %edi, 4(%eax)
146 ; X86-NEXT: movl %esi, 8(%eax)
147 ; X86-NEXT: movl %ecx, 12(%eax)
148 ; X86-NEXT: popl %esi
149 ; X86-NEXT: popl %edi
150 ; X86-NEXT: popl %ebx
153 ; X64-LABEL: test_i128:
155 ; X64-NEXT: movq %rsi, %rdx
156 ; X64-NEXT: movq %rdi, %rax
157 ; X64-NEXT: movq %rsi, %rcx
158 ; X64-NEXT: sarq $63, %rcx
159 ; X64-NEXT: xorq %rcx, %rdx
160 ; X64-NEXT: xorq %rcx, %rax
161 ; X64-NEXT: subq %rcx, %rax
162 ; X64-NEXT: sbbq %rcx, %rdx
164 %tmp1neg = sub i128 0, %a
165 %b = icmp sgt i128 %a, -1
166 %abs = select i1 %b, i128 %a, i128 %tmp1neg