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=X86
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 ; X86-LABEL: test__tzcnt_u16:
14 ; X86-NEXT: movzwl {{[0-9]+}}(%esp), %eax
15 ; X86-NEXT: orl $65536, %eax # imm = 0x10000
16 ; X86-NEXT: tzcntl %eax, %eax
17 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
20 ; X64-LABEL: test__tzcnt_u16:
22 ; X64-NEXT: orl $65536, %edi # imm = 0x10000
23 ; X64-NEXT: tzcntl %edi, %eax
24 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
26 %zext = zext i16 %a0 to i32
27 %cmp = icmp ne i32 %zext, 0
28 %cttz = call i16 @llvm.cttz.i16(i16 %a0, i1 false)
32 define i32 @test__andn_u32(i32 %a0, i32 %a1) {
33 ; X86-LABEL: test__andn_u32:
35 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
36 ; X86-NEXT: xorl $-1, %eax
37 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
40 ; X64-LABEL: test__andn_u32:
42 ; X64-NEXT: movl %edi, %eax
43 ; X64-NEXT: xorl $-1, %eax
44 ; X64-NEXT: andl %esi, %eax
46 %xor = xor i32 %a0, -1
47 %res = and i32 %xor, %a1
51 define i32 @test__bextr_u32(i32 %a0, i32 %a1) {
52 ; X86-LABEL: test__bextr_u32:
54 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
55 ; X86-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
58 ; X64-LABEL: test__bextr_u32:
60 ; X64-NEXT: bextrl %esi, %edi, %eax
62 %res = call i32 @llvm.x86.bmi.bextr.32(i32 %a0, i32 %a1)
66 define i32 @test__blsi_u32(i32 %a0) {
67 ; X86-LABEL: test__blsi_u32:
69 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
70 ; X86-NEXT: xorl %eax, %eax
71 ; X86-NEXT: subl %ecx, %eax
72 ; X86-NEXT: andl %ecx, %eax
75 ; X64-LABEL: test__blsi_u32:
77 ; X64-NEXT: xorl %eax, %eax
78 ; X64-NEXT: subl %edi, %eax
79 ; X64-NEXT: andl %edi, %eax
82 %res = and i32 %a0, %neg
86 define i32 @test__blsmsk_u32(i32 %a0) {
87 ; X86-LABEL: test__blsmsk_u32:
89 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
90 ; X86-NEXT: leal -1(%ecx), %eax
91 ; X86-NEXT: xorl %ecx, %eax
94 ; X64-LABEL: test__blsmsk_u32:
96 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
97 ; X64-NEXT: leal -1(%rdi), %eax
98 ; X64-NEXT: xorl %edi, %eax
100 %dec = sub i32 %a0, 1
101 %res = xor i32 %a0, %dec
105 define i32 @test__blsr_u32(i32 %a0) {
106 ; X86-LABEL: test__blsr_u32:
108 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
109 ; X86-NEXT: leal -1(%ecx), %eax
110 ; X86-NEXT: andl %ecx, %eax
113 ; X64-LABEL: test__blsr_u32:
115 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
116 ; X64-NEXT: leal -1(%rdi), %eax
117 ; X64-NEXT: andl %edi, %eax
119 %dec = sub i32 %a0, 1
120 %res = and i32 %a0, %dec
124 define i32 @test__tzcnt_u32(i32 %a0) {
125 ; X86-LABEL: test__tzcnt_u32:
127 ; X86-NEXT: tzcntl {{[0-9]+}}(%esp), %eax
130 ; X64-LABEL: test__tzcnt_u32:
132 ; X64-NEXT: tzcntl %edi, %eax
134 %cmp = icmp ne i32 %a0, 0
135 %cttz = call i32 @llvm.cttz.i32(i32 %a0, i1 false)
143 define i16 @test_tzcnt_u16(i16 %a0) {
144 ; X86-LABEL: test_tzcnt_u16:
146 ; X86-NEXT: movzwl {{[0-9]+}}(%esp), %eax
147 ; X86-NEXT: orl $65536, %eax # imm = 0x10000
148 ; X86-NEXT: tzcntl %eax, %eax
149 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
152 ; X64-LABEL: test_tzcnt_u16:
154 ; X64-NEXT: orl $65536, %edi # imm = 0x10000
155 ; X64-NEXT: tzcntl %edi, %eax
156 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
158 %zext = zext i16 %a0 to i32
159 %cmp = icmp ne i32 %zext, 0
160 %cttz = call i16 @llvm.cttz.i16(i16 %a0, i1 false)
164 define i32 @test_andn_u32(i32 %a0, i32 %a1) {
165 ; X86-LABEL: test_andn_u32:
167 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
168 ; X86-NEXT: xorl $-1, %eax
169 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
172 ; X64-LABEL: test_andn_u32:
174 ; X64-NEXT: movl %edi, %eax
175 ; X64-NEXT: xorl $-1, %eax
176 ; X64-NEXT: andl %esi, %eax
178 %xor = xor i32 %a0, -1
179 %res = and i32 %xor, %a1
183 define i32 @test_bextr_u32(i32 %a0, i32 %a1, i32 %a2) {
184 ; X86-LABEL: test_bextr_u32:
186 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
187 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
188 ; X86-NEXT: andl $255, %ecx
189 ; X86-NEXT: andl $255, %eax
190 ; X86-NEXT: shll $8, %eax
191 ; X86-NEXT: orl %ecx, %eax
192 ; X86-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
195 ; X64-LABEL: test_bextr_u32:
197 ; X64-NEXT: andl $255, %esi
198 ; X64-NEXT: andl $255, %edx
199 ; X64-NEXT: shll $8, %edx
200 ; X64-NEXT: orl %esi, %edx
201 ; X64-NEXT: bextrl %edx, %edi, %eax
203 %and1 = and i32 %a1, 255
204 %and2 = and i32 %a2, 255
205 %shl = shl i32 %and2, 8
206 %or = or i32 %and1, %shl
207 %res = call i32 @llvm.x86.bmi.bextr.32(i32 %a0, i32 %or)
211 define i32 @test_blsi_u32(i32 %a0) {
212 ; X86-LABEL: test_blsi_u32:
214 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
215 ; X86-NEXT: xorl %eax, %eax
216 ; X86-NEXT: subl %ecx, %eax
217 ; X86-NEXT: andl %ecx, %eax
220 ; X64-LABEL: test_blsi_u32:
222 ; X64-NEXT: xorl %eax, %eax
223 ; X64-NEXT: subl %edi, %eax
224 ; X64-NEXT: andl %edi, %eax
226 %neg = sub i32 0, %a0
227 %res = and i32 %a0, %neg
231 define i32 @test_blsmsk_u32(i32 %a0) {
232 ; X86-LABEL: test_blsmsk_u32:
234 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
235 ; X86-NEXT: leal -1(%ecx), %eax
236 ; X86-NEXT: xorl %ecx, %eax
239 ; X64-LABEL: test_blsmsk_u32:
241 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
242 ; X64-NEXT: leal -1(%rdi), %eax
243 ; X64-NEXT: xorl %edi, %eax
245 %dec = sub i32 %a0, 1
246 %res = xor i32 %a0, %dec
250 define i32 @test_blsr_u32(i32 %a0) {
251 ; X86-LABEL: test_blsr_u32:
253 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
254 ; X86-NEXT: leal -1(%ecx), %eax
255 ; X86-NEXT: andl %ecx, %eax
258 ; X64-LABEL: test_blsr_u32:
260 ; X64-NEXT: # kill: def $edi killed $edi def $rdi
261 ; X64-NEXT: leal -1(%rdi), %eax
262 ; X64-NEXT: andl %edi, %eax
264 %dec = sub i32 %a0, 1
265 %res = and i32 %a0, %dec
269 define i32 @test_tzcnt_u32(i32 %a0) {
270 ; X86-LABEL: test_tzcnt_u32:
272 ; X86-NEXT: tzcntl {{[0-9]+}}(%esp), %eax
275 ; X64-LABEL: test_tzcnt_u32:
277 ; X64-NEXT: tzcntl %edi, %eax
279 %cmp = icmp ne i32 %a0, 0
280 %cttz = call i32 @llvm.cttz.i32(i32 %a0, i1 false)
284 declare i16 @llvm.cttz.i16(i16, i1)
285 declare i32 @llvm.cttz.i32(i32, i1)
286 declare i32 @llvm.x86.bmi.bextr.32(i32, i32)