1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -fast-isel -mtriple=i686-unknown-unknown -mattr=+bmi | FileCheck %s --check-prefix=X32
3 ; RUN: llc < %s -fast-isel -mtriple=x86_64-unknown-unknown -mattr=+bmi | FileCheck %s --check-prefix=X64
5 ; NOTE: This should use IR equivalent to what is generated by clang/test/CodeGen/bmi-builtins.c
11 define i16 @test__tzcnt_u16(i16 %a0) {
12 ; X32-LABEL: test__tzcnt_u16:
14 ; X32-NEXT: movzwl {{[0-9]+}}(%esp), %eax
15 ; X32-NEXT: movzwl %ax, %ecx
16 ; X32-NEXT: cmpl $0, %ecx
17 ; X32-NEXT: jne .LBB0_1
19 ; X32-NEXT: movw $16, %ax
22 ; X32-NEXT: tzcntw %ax, %ax
25 ; X64-LABEL: test__tzcnt_u16:
27 ; X64-NEXT: movw $16, %cx
28 ; X64-NEXT: movzwl %di, %edx
29 ; X64-NEXT: tzcntw %dx, %ax
30 ; X64-NEXT: cmpl $0, %edx
31 ; X64-NEXT: cmovew %cx, %ax
33 %zext = zext i16 %a0 to i32
34 %cmp = icmp ne i32 %zext, 0
35 %cttz = call i16 @llvm.cttz.i16(i16 %a0, i1 true)
36 %res = select i1 %cmp, i16 %cttz, i16 16
40 define i32 @test__andn_u32(i32 %a0, i32 %a1) {
41 ; X32-LABEL: test__andn_u32:
43 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
44 ; X32-NEXT: xorl $-1, %eax
45 ; X32-NEXT: andl {{[0-9]+}}(%esp), %eax
48 ; X64-LABEL: test__andn_u32:
50 ; X64-NEXT: xorl $-1, %edi
51 ; X64-NEXT: andl %esi, %edi
52 ; X64-NEXT: movl %edi, %eax
54 %xor = xor i32 %a0, -1
55 %res = and i32 %xor, %a1
59 define i32 @test__bextr_u32(i32 %a0, i32 %a1) {
60 ; X32-LABEL: test__bextr_u32:
62 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
63 ; X32-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
66 ; X64-LABEL: test__bextr_u32:
68 ; X64-NEXT: bextrl %esi, %edi, %eax
70 %res = call i32 @llvm.x86.bmi.bextr.32(i32 %a0, i32 %a1)
74 define i32 @test__blsi_u32(i32 %a0) {
75 ; X32-LABEL: test__blsi_u32:
77 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
78 ; X32-NEXT: xorl %eax, %eax
79 ; X32-NEXT: subl %ecx, %eax
80 ; X32-NEXT: andl %ecx, %eax
83 ; X64-LABEL: test__blsi_u32:
85 ; X64-NEXT: xorl %eax, %eax
86 ; X64-NEXT: subl %edi, %eax
87 ; X64-NEXT: andl %edi, %eax
90 %res = and i32 %a0, %neg
94 define i32 @test__blsmsk_u32(i32 %a0) {
95 ; X32-LABEL: test__blsmsk_u32:
97 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
98 ; X32-NEXT: movl %ecx, %eax
99 ; X32-NEXT: subl $1, %eax
100 ; X32-NEXT: xorl %ecx, %eax
103 ; X64-LABEL: test__blsmsk_u32:
105 ; X64-NEXT: movl %edi, %eax
106 ; X64-NEXT: subl $1, %eax
107 ; X64-NEXT: xorl %edi, %eax
109 %dec = sub i32 %a0, 1
110 %res = xor i32 %a0, %dec
114 define i32 @test__blsr_u32(i32 %a0) {
115 ; X32-LABEL: test__blsr_u32:
117 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
118 ; X32-NEXT: movl %ecx, %eax
119 ; X32-NEXT: subl $1, %eax
120 ; X32-NEXT: andl %ecx, %eax
123 ; X64-LABEL: test__blsr_u32:
125 ; X64-NEXT: movl %edi, %eax
126 ; X64-NEXT: subl $1, %eax
127 ; X64-NEXT: andl %edi, %eax
129 %dec = sub i32 %a0, 1
130 %res = and i32 %a0, %dec
134 define i32 @test__tzcnt_u32(i32 %a0) {
135 ; X32-LABEL: test__tzcnt_u32:
137 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
138 ; X32-NEXT: cmpl $0, %eax
139 ; X32-NEXT: jne .LBB6_1
141 ; X32-NEXT: movl $32, %eax
144 ; X32-NEXT: tzcntl %eax, %eax
147 ; X64-LABEL: test__tzcnt_u32:
149 ; X64-NEXT: movl $32, %ecx
150 ; X64-NEXT: tzcntl %edi, %eax
151 ; X64-NEXT: cmovbl %ecx, %eax
153 %cmp = icmp ne i32 %a0, 0
154 %cttz = call i32 @llvm.cttz.i32(i32 %a0, i1 true)
155 %res = select i1 %cmp, i32 %cttz, i32 32
163 define i16 @test_tzcnt_u16(i16 %a0) {
164 ; X32-LABEL: test_tzcnt_u16:
166 ; X32-NEXT: movzwl {{[0-9]+}}(%esp), %eax
167 ; X32-NEXT: movzwl %ax, %ecx
168 ; X32-NEXT: cmpl $0, %ecx
169 ; X32-NEXT: jne .LBB7_1
171 ; X32-NEXT: movw $16, %ax
174 ; X32-NEXT: tzcntw %ax, %ax
177 ; X64-LABEL: test_tzcnt_u16:
179 ; X64-NEXT: movw $16, %cx
180 ; X64-NEXT: movzwl %di, %edx
181 ; X64-NEXT: tzcntw %dx, %ax
182 ; X64-NEXT: cmpl $0, %edx
183 ; X64-NEXT: cmovew %cx, %ax
185 %zext = zext i16 %a0 to i32
186 %cmp = icmp ne i32 %zext, 0
187 %cttz = call i16 @llvm.cttz.i16(i16 %a0, i1 true)
188 %res = select i1 %cmp, i16 %cttz, i16 16
192 define i32 @test_andn_u32(i32 %a0, i32 %a1) {
193 ; X32-LABEL: test_andn_u32:
195 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
196 ; X32-NEXT: xorl $-1, %eax
197 ; X32-NEXT: andl {{[0-9]+}}(%esp), %eax
200 ; X64-LABEL: test_andn_u32:
202 ; X64-NEXT: xorl $-1, %edi
203 ; X64-NEXT: andl %esi, %edi
204 ; X64-NEXT: movl %edi, %eax
206 %xor = xor i32 %a0, -1
207 %res = and i32 %xor, %a1
211 define i32 @test_bextr_u32(i32 %a0, i32 %a1, i32 %a2) {
212 ; X32-LABEL: test_bextr_u32:
214 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
215 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
216 ; X32-NEXT: andl $255, %ecx
217 ; X32-NEXT: andl $255, %eax
218 ; X32-NEXT: shll $8, %eax
219 ; X32-NEXT: orl %ecx, %eax
220 ; X32-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
223 ; X64-LABEL: test_bextr_u32:
225 ; X64-NEXT: andl $255, %esi
226 ; X64-NEXT: andl $255, %edx
227 ; X64-NEXT: shll $8, %edx
228 ; X64-NEXT: orl %esi, %edx
229 ; X64-NEXT: bextrl %edx, %edi, %eax
231 %and1 = and i32 %a1, 255
232 %and2 = and i32 %a2, 255
233 %shl = shl i32 %and2, 8
234 %or = or i32 %and1, %shl
235 %res = call i32 @llvm.x86.bmi.bextr.32(i32 %a0, i32 %or)
239 define i32 @test_blsi_u32(i32 %a0) {
240 ; X32-LABEL: test_blsi_u32:
242 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
243 ; X32-NEXT: xorl %eax, %eax
244 ; X32-NEXT: subl %ecx, %eax
245 ; X32-NEXT: andl %ecx, %eax
248 ; X64-LABEL: test_blsi_u32:
250 ; X64-NEXT: xorl %eax, %eax
251 ; X64-NEXT: subl %edi, %eax
252 ; X64-NEXT: andl %edi, %eax
254 %neg = sub i32 0, %a0
255 %res = and i32 %a0, %neg
259 define i32 @test_blsmsk_u32(i32 %a0) {
260 ; X32-LABEL: test_blsmsk_u32:
262 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
263 ; X32-NEXT: movl %ecx, %eax
264 ; X32-NEXT: subl $1, %eax
265 ; X32-NEXT: xorl %ecx, %eax
268 ; X64-LABEL: test_blsmsk_u32:
270 ; X64-NEXT: movl %edi, %eax
271 ; X64-NEXT: subl $1, %eax
272 ; X64-NEXT: xorl %edi, %eax
274 %dec = sub i32 %a0, 1
275 %res = xor i32 %a0, %dec
279 define i32 @test_blsr_u32(i32 %a0) {
280 ; X32-LABEL: test_blsr_u32:
282 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
283 ; X32-NEXT: movl %ecx, %eax
284 ; X32-NEXT: subl $1, %eax
285 ; X32-NEXT: andl %ecx, %eax
288 ; X64-LABEL: test_blsr_u32:
290 ; X64-NEXT: movl %edi, %eax
291 ; X64-NEXT: subl $1, %eax
292 ; X64-NEXT: andl %edi, %eax
294 %dec = sub i32 %a0, 1
295 %res = and i32 %a0, %dec
299 define i32 @test_tzcnt_u32(i32 %a0) {
300 ; X32-LABEL: test_tzcnt_u32:
302 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
303 ; X32-NEXT: cmpl $0, %eax
304 ; X32-NEXT: jne .LBB13_1
306 ; X32-NEXT: movl $32, %eax
308 ; X32-NEXT: .LBB13_1:
309 ; X32-NEXT: tzcntl %eax, %eax
312 ; X64-LABEL: test_tzcnt_u32:
314 ; X64-NEXT: movl $32, %ecx
315 ; X64-NEXT: tzcntl %edi, %eax
316 ; X64-NEXT: cmovbl %ecx, %eax
318 %cmp = icmp ne i32 %a0, 0
319 %cttz = call i32 @llvm.cttz.i32(i32 %a0, i1 true)
320 %res = select i1 %cmp, i32 %cttz, i32 32
324 declare i16 @llvm.cttz.i16(i16, i1)
325 declare i32 @llvm.cttz.i32(i32, i1)
326 declare i32 @llvm.x86.bmi.bextr.32(i32, i32)