1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -fast-isel-sink-local-values < %s -fast-isel -mtriple=i686-unknown-unknown -mattr=+bmi | FileCheck %s --check-prefix=X32
3 ; RUN: llc -fast-isel-sink-local-values < %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: tzcntw {{[0-9]+}}(%esp), %ax
17 ; X64-LABEL: test__tzcnt_u16:
19 ; X64-NEXT: tzcntw %di, %ax
21 %zext = zext i16 %a0 to i32
22 %cmp = icmp ne i32 %zext, 0
23 %cttz = call i16 @llvm.cttz.i16(i16 %a0, i1 false)
27 define i32 @test__andn_u32(i32 %a0, i32 %a1) {
28 ; X32-LABEL: test__andn_u32:
30 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
31 ; X32-NEXT: xorl $-1, %eax
32 ; X32-NEXT: andl {{[0-9]+}}(%esp), %eax
35 ; X64-LABEL: test__andn_u32:
37 ; X64-NEXT: movl %edi, %eax
38 ; X64-NEXT: xorl $-1, %eax
39 ; X64-NEXT: andl %esi, %eax
41 %xor = xor i32 %a0, -1
42 %res = and i32 %xor, %a1
46 define i32 @test__bextr_u32(i32 %a0, i32 %a1) {
47 ; X32-LABEL: test__bextr_u32:
49 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
50 ; X32-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
53 ; X64-LABEL: test__bextr_u32:
55 ; X64-NEXT: bextrl %esi, %edi, %eax
57 %res = call i32 @llvm.x86.bmi.bextr.32(i32 %a0, i32 %a1)
61 define i32 @test__blsi_u32(i32 %a0) {
62 ; X32-LABEL: test__blsi_u32:
64 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
65 ; X32-NEXT: xorl %eax, %eax
66 ; X32-NEXT: subl %ecx, %eax
67 ; X32-NEXT: andl %ecx, %eax
70 ; X64-LABEL: test__blsi_u32:
72 ; X64-NEXT: xorl %eax, %eax
73 ; X64-NEXT: subl %edi, %eax
74 ; X64-NEXT: andl %edi, %eax
77 %res = and i32 %a0, %neg
81 define i32 @test__blsmsk_u32(i32 %a0) {
82 ; X32-LABEL: test__blsmsk_u32:
84 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
85 ; X32-NEXT: movl %ecx, %eax
86 ; X32-NEXT: subl $1, %eax
87 ; X32-NEXT: xorl %ecx, %eax
90 ; X64-LABEL: test__blsmsk_u32:
92 ; X64-NEXT: movl %edi, %eax
93 ; X64-NEXT: subl $1, %eax
94 ; X64-NEXT: xorl %edi, %eax
97 %res = xor i32 %a0, %dec
101 define i32 @test__blsr_u32(i32 %a0) {
102 ; X32-LABEL: test__blsr_u32:
104 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
105 ; X32-NEXT: movl %ecx, %eax
106 ; X32-NEXT: subl $1, %eax
107 ; X32-NEXT: andl %ecx, %eax
110 ; X64-LABEL: test__blsr_u32:
112 ; X64-NEXT: movl %edi, %eax
113 ; X64-NEXT: subl $1, %eax
114 ; X64-NEXT: andl %edi, %eax
116 %dec = sub i32 %a0, 1
117 %res = and i32 %a0, %dec
121 define i32 @test__tzcnt_u32(i32 %a0) {
122 ; X32-LABEL: test__tzcnt_u32:
124 ; X32-NEXT: tzcntl {{[0-9]+}}(%esp), %eax
127 ; X64-LABEL: test__tzcnt_u32:
129 ; X64-NEXT: tzcntl %edi, %eax
131 %cmp = icmp ne i32 %a0, 0
132 %cttz = call i32 @llvm.cttz.i32(i32 %a0, i1 false)
140 define i16 @test_tzcnt_u16(i16 %a0) {
141 ; X32-LABEL: test_tzcnt_u16:
143 ; X32-NEXT: tzcntw {{[0-9]+}}(%esp), %ax
146 ; X64-LABEL: test_tzcnt_u16:
148 ; X64-NEXT: tzcntw %di, %ax
150 %zext = zext i16 %a0 to i32
151 %cmp = icmp ne i32 %zext, 0
152 %cttz = call i16 @llvm.cttz.i16(i16 %a0, i1 false)
156 define i32 @test_andn_u32(i32 %a0, i32 %a1) {
157 ; X32-LABEL: test_andn_u32:
159 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
160 ; X32-NEXT: xorl $-1, %eax
161 ; X32-NEXT: andl {{[0-9]+}}(%esp), %eax
164 ; X64-LABEL: test_andn_u32:
166 ; X64-NEXT: movl %edi, %eax
167 ; X64-NEXT: xorl $-1, %eax
168 ; X64-NEXT: andl %esi, %eax
170 %xor = xor i32 %a0, -1
171 %res = and i32 %xor, %a1
175 define i32 @test_bextr_u32(i32 %a0, i32 %a1, i32 %a2) {
176 ; X32-LABEL: test_bextr_u32:
178 ; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
179 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
180 ; X32-NEXT: andl $255, %ecx
181 ; X32-NEXT: andl $255, %eax
182 ; X32-NEXT: shll $8, %eax
183 ; X32-NEXT: orl %ecx, %eax
184 ; X32-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
187 ; X64-LABEL: test_bextr_u32:
189 ; X64-NEXT: andl $255, %esi
190 ; X64-NEXT: andl $255, %edx
191 ; X64-NEXT: shll $8, %edx
192 ; X64-NEXT: orl %esi, %edx
193 ; X64-NEXT: bextrl %edx, %edi, %eax
195 %and1 = and i32 %a1, 255
196 %and2 = and i32 %a2, 255
197 %shl = shl i32 %and2, 8
198 %or = or i32 %and1, %shl
199 %res = call i32 @llvm.x86.bmi.bextr.32(i32 %a0, i32 %or)
203 define i32 @test_blsi_u32(i32 %a0) {
204 ; X32-LABEL: test_blsi_u32:
206 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
207 ; X32-NEXT: xorl %eax, %eax
208 ; X32-NEXT: subl %ecx, %eax
209 ; X32-NEXT: andl %ecx, %eax
212 ; X64-LABEL: test_blsi_u32:
214 ; X64-NEXT: xorl %eax, %eax
215 ; X64-NEXT: subl %edi, %eax
216 ; X64-NEXT: andl %edi, %eax
218 %neg = sub i32 0, %a0
219 %res = and i32 %a0, %neg
223 define i32 @test_blsmsk_u32(i32 %a0) {
224 ; X32-LABEL: test_blsmsk_u32:
226 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
227 ; X32-NEXT: movl %ecx, %eax
228 ; X32-NEXT: subl $1, %eax
229 ; X32-NEXT: xorl %ecx, %eax
232 ; X64-LABEL: test_blsmsk_u32:
234 ; X64-NEXT: movl %edi, %eax
235 ; X64-NEXT: subl $1, %eax
236 ; X64-NEXT: xorl %edi, %eax
238 %dec = sub i32 %a0, 1
239 %res = xor i32 %a0, %dec
243 define i32 @test_blsr_u32(i32 %a0) {
244 ; X32-LABEL: test_blsr_u32:
246 ; X32-NEXT: movl {{[0-9]+}}(%esp), %ecx
247 ; X32-NEXT: movl %ecx, %eax
248 ; X32-NEXT: subl $1, %eax
249 ; X32-NEXT: andl %ecx, %eax
252 ; X64-LABEL: test_blsr_u32:
254 ; X64-NEXT: movl %edi, %eax
255 ; X64-NEXT: subl $1, %eax
256 ; X64-NEXT: andl %edi, %eax
258 %dec = sub i32 %a0, 1
259 %res = and i32 %a0, %dec
263 define i32 @test_tzcnt_u32(i32 %a0) {
264 ; X32-LABEL: test_tzcnt_u32:
266 ; X32-NEXT: tzcntl {{[0-9]+}}(%esp), %eax
269 ; X64-LABEL: test_tzcnt_u32:
271 ; X64-NEXT: tzcntl %edi, %eax
273 %cmp = icmp ne i32 %a0, 0
274 %cttz = call i32 @llvm.cttz.i32(i32 %a0, i1 false)
278 declare i16 @llvm.cttz.i16(i16, i1)
279 declare i32 @llvm.cttz.i32(i32, i1)
280 declare i32 @llvm.x86.bmi.bextr.32(i32, i32)