1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=-bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,NOBMI,X86-NOBMI
3 ; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,BMI1,X86-BMI1,BMI1NOTBM,X86-BMI1NOTBM
4 ; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,+tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,BMI1,X86-BMI1,BMI1TBM,X86-BMI1TBM
5 ; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,+tbm,+bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,BMI1,X86-BMI1,BMI1BMI2,X86-BMI1BMI2,BMI1TBM,X86-BMI1TBM,BMI1TBMBMI2,X86-BMI1TBMBMI2
6 ; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,-tbm,+bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X86,BMI1,X86-BMI1,BMI1BMI2,X86-BMI1BMI2,BMI1NOTBMBMI2,X86-BMI1NOTBMBMI2
7 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,NOBMI,X64-NOBMI
8 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,-tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,BMI1,X64-BMI1,BMI1NOTBM,X64-BMI1NOTBM
9 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,+tbm,-bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,BMI1,X64-BMI1,BMI1TBM,X64-BMI1TBM
10 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,+tbm,+bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,BMI1,X64-BMI1,BMI1BMI2,X64-BMI1BMI2,BMI1TBM,X64-BMI1TBM,BMI1TBMBMI2,X64-BMI1TBMBMI2
11 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi,-tbm,+bmi2 < %s | FileCheck %s --check-prefixes=CHECK,X64,BMI1,X64-BMI1,BMI1BMI2,X64-BMI1BMI2,BMI1NOTBMBMI2,X64-BMI1NOTBMBMI2
13 ; *Please* keep in sync with test/CodeGen/AArch64/extract-lowbits.ll
15 ; https://bugs.llvm.org/show_bug.cgi?id=36419
16 ; https://bugs.llvm.org/show_bug.cgi?id=37603
17 ; https://bugs.llvm.org/show_bug.cgi?id=37610
20 ; a) x & (1 << nbits) - 1
21 ; b) x & ~(-1 << nbits)
22 ; c) x & (-1 >> (32 - y))
23 ; d) x << (32 - y) >> (32 - y)
26 ; ---------------------------------------------------------------------------- ;
28 ; ---------------------------------------------------------------------------- ;
30 define i32 @bzhi32_a0(i32 %val, i32 %numlowbits) nounwind {
31 ; X86-NOBMI-LABEL: bzhi32_a0:
33 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
34 ; X86-NOBMI-NEXT: movl $1, %eax
35 ; X86-NOBMI-NEXT: shll %cl, %eax
36 ; X86-NOBMI-NEXT: decl %eax
37 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
38 ; X86-NOBMI-NEXT: retl
40 ; X86-BMI1NOTBM-LABEL: bzhi32_a0:
41 ; X86-BMI1NOTBM: # %bb.0:
42 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
43 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
44 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
45 ; X86-BMI1NOTBM-NEXT: retl
47 ; X86-BMI1BMI2-LABEL: bzhi32_a0:
48 ; X86-BMI1BMI2: # %bb.0:
49 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
50 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
51 ; X86-BMI1BMI2-NEXT: retl
53 ; X64-NOBMI-LABEL: bzhi32_a0:
55 ; X64-NOBMI-NEXT: movl %esi, %ecx
56 ; X64-NOBMI-NEXT: movl $1, %eax
57 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
58 ; X64-NOBMI-NEXT: shll %cl, %eax
59 ; X64-NOBMI-NEXT: decl %eax
60 ; X64-NOBMI-NEXT: andl %edi, %eax
61 ; X64-NOBMI-NEXT: retq
63 ; X64-BMI1NOTBM-LABEL: bzhi32_a0:
64 ; X64-BMI1NOTBM: # %bb.0:
65 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
66 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
67 ; X64-BMI1NOTBM-NEXT: retq
69 ; X64-BMI1BMI2-LABEL: bzhi32_a0:
70 ; X64-BMI1BMI2: # %bb.0:
71 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
72 ; X64-BMI1BMI2-NEXT: retq
73 %onebit = shl i32 1, %numlowbits
74 %mask = add nsw i32 %onebit, -1
75 %masked = and i32 %mask, %val
79 define i32 @bzhi32_a1_indexzext(i32 %val, i8 zeroext %numlowbits) nounwind {
80 ; X86-NOBMI-LABEL: bzhi32_a1_indexzext:
82 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
83 ; X86-NOBMI-NEXT: movl $1, %eax
84 ; X86-NOBMI-NEXT: shll %cl, %eax
85 ; X86-NOBMI-NEXT: decl %eax
86 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
87 ; X86-NOBMI-NEXT: retl
89 ; X86-BMI1NOTBM-LABEL: bzhi32_a1_indexzext:
90 ; X86-BMI1NOTBM: # %bb.0:
91 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
92 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
93 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
94 ; X86-BMI1NOTBM-NEXT: retl
96 ; X86-BMI1BMI2-LABEL: bzhi32_a1_indexzext:
97 ; X86-BMI1BMI2: # %bb.0:
98 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
99 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
100 ; X86-BMI1BMI2-NEXT: retl
102 ; X64-NOBMI-LABEL: bzhi32_a1_indexzext:
103 ; X64-NOBMI: # %bb.0:
104 ; X64-NOBMI-NEXT: movl %esi, %ecx
105 ; X64-NOBMI-NEXT: movl $1, %eax
106 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
107 ; X64-NOBMI-NEXT: shll %cl, %eax
108 ; X64-NOBMI-NEXT: decl %eax
109 ; X64-NOBMI-NEXT: andl %edi, %eax
110 ; X64-NOBMI-NEXT: retq
112 ; X64-BMI1NOTBM-LABEL: bzhi32_a1_indexzext:
113 ; X64-BMI1NOTBM: # %bb.0:
114 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
115 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
116 ; X64-BMI1NOTBM-NEXT: retq
118 ; X64-BMI1BMI2-LABEL: bzhi32_a1_indexzext:
119 ; X64-BMI1BMI2: # %bb.0:
120 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
121 ; X64-BMI1BMI2-NEXT: retq
122 %conv = zext i8 %numlowbits to i32
123 %onebit = shl i32 1, %conv
124 %mask = add nsw i32 %onebit, -1
125 %masked = and i32 %mask, %val
129 define i32 @bzhi32_a2_load(i32* %w, i32 %numlowbits) nounwind {
130 ; X86-NOBMI-LABEL: bzhi32_a2_load:
131 ; X86-NOBMI: # %bb.0:
132 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx
133 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
134 ; X86-NOBMI-NEXT: movl $1, %eax
135 ; X86-NOBMI-NEXT: shll %cl, %eax
136 ; X86-NOBMI-NEXT: decl %eax
137 ; X86-NOBMI-NEXT: andl (%edx), %eax
138 ; X86-NOBMI-NEXT: retl
140 ; X86-BMI1NOTBM-LABEL: bzhi32_a2_load:
141 ; X86-BMI1NOTBM: # %bb.0:
142 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
143 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
144 ; X86-BMI1NOTBM-NEXT: shll $8, %ecx
145 ; X86-BMI1NOTBM-NEXT: bextrl %ecx, (%eax), %eax
146 ; X86-BMI1NOTBM-NEXT: retl
148 ; X86-BMI1BMI2-LABEL: bzhi32_a2_load:
149 ; X86-BMI1BMI2: # %bb.0:
150 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
151 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
152 ; X86-BMI1BMI2-NEXT: bzhil %ecx, (%eax), %eax
153 ; X86-BMI1BMI2-NEXT: retl
155 ; X64-NOBMI-LABEL: bzhi32_a2_load:
156 ; X64-NOBMI: # %bb.0:
157 ; X64-NOBMI-NEXT: movl %esi, %ecx
158 ; X64-NOBMI-NEXT: movl $1, %eax
159 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
160 ; X64-NOBMI-NEXT: shll %cl, %eax
161 ; X64-NOBMI-NEXT: decl %eax
162 ; X64-NOBMI-NEXT: andl (%rdi), %eax
163 ; X64-NOBMI-NEXT: retq
165 ; X64-BMI1NOTBM-LABEL: bzhi32_a2_load:
166 ; X64-BMI1NOTBM: # %bb.0:
167 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
168 ; X64-BMI1NOTBM-NEXT: bextrl %esi, (%rdi), %eax
169 ; X64-BMI1NOTBM-NEXT: retq
171 ; X64-BMI1BMI2-LABEL: bzhi32_a2_load:
172 ; X64-BMI1BMI2: # %bb.0:
173 ; X64-BMI1BMI2-NEXT: bzhil %esi, (%rdi), %eax
174 ; X64-BMI1BMI2-NEXT: retq
175 %val = load i32, i32* %w
176 %onebit = shl i32 1, %numlowbits
177 %mask = add nsw i32 %onebit, -1
178 %masked = and i32 %mask, %val
182 define i32 @bzhi32_a3_load_indexzext(i32* %w, i8 zeroext %numlowbits) nounwind {
183 ; X86-NOBMI-LABEL: bzhi32_a3_load_indexzext:
184 ; X86-NOBMI: # %bb.0:
185 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx
186 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
187 ; X86-NOBMI-NEXT: movl $1, %eax
188 ; X86-NOBMI-NEXT: shll %cl, %eax
189 ; X86-NOBMI-NEXT: decl %eax
190 ; X86-NOBMI-NEXT: andl (%edx), %eax
191 ; X86-NOBMI-NEXT: retl
193 ; X86-BMI1NOTBM-LABEL: bzhi32_a3_load_indexzext:
194 ; X86-BMI1NOTBM: # %bb.0:
195 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
196 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
197 ; X86-BMI1NOTBM-NEXT: shll $8, %ecx
198 ; X86-BMI1NOTBM-NEXT: bextrl %ecx, (%eax), %eax
199 ; X86-BMI1NOTBM-NEXT: retl
201 ; X86-BMI1BMI2-LABEL: bzhi32_a3_load_indexzext:
202 ; X86-BMI1BMI2: # %bb.0:
203 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
204 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
205 ; X86-BMI1BMI2-NEXT: bzhil %ecx, (%eax), %eax
206 ; X86-BMI1BMI2-NEXT: retl
208 ; X64-NOBMI-LABEL: bzhi32_a3_load_indexzext:
209 ; X64-NOBMI: # %bb.0:
210 ; X64-NOBMI-NEXT: movl %esi, %ecx
211 ; X64-NOBMI-NEXT: movl $1, %eax
212 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
213 ; X64-NOBMI-NEXT: shll %cl, %eax
214 ; X64-NOBMI-NEXT: decl %eax
215 ; X64-NOBMI-NEXT: andl (%rdi), %eax
216 ; X64-NOBMI-NEXT: retq
218 ; X64-BMI1NOTBM-LABEL: bzhi32_a3_load_indexzext:
219 ; X64-BMI1NOTBM: # %bb.0:
220 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
221 ; X64-BMI1NOTBM-NEXT: bextrl %esi, (%rdi), %eax
222 ; X64-BMI1NOTBM-NEXT: retq
224 ; X64-BMI1BMI2-LABEL: bzhi32_a3_load_indexzext:
225 ; X64-BMI1BMI2: # %bb.0:
226 ; X64-BMI1BMI2-NEXT: bzhil %esi, (%rdi), %eax
227 ; X64-BMI1BMI2-NEXT: retq
228 %val = load i32, i32* %w
229 %conv = zext i8 %numlowbits to i32
230 %onebit = shl i32 1, %conv
231 %mask = add nsw i32 %onebit, -1
232 %masked = and i32 %mask, %val
236 define i32 @bzhi32_a4_commutative(i32 %val, i32 %numlowbits) nounwind {
237 ; X86-NOBMI-LABEL: bzhi32_a4_commutative:
238 ; X86-NOBMI: # %bb.0:
239 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
240 ; X86-NOBMI-NEXT: movl $1, %eax
241 ; X86-NOBMI-NEXT: shll %cl, %eax
242 ; X86-NOBMI-NEXT: decl %eax
243 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
244 ; X86-NOBMI-NEXT: retl
246 ; X86-BMI1NOTBM-LABEL: bzhi32_a4_commutative:
247 ; X86-BMI1NOTBM: # %bb.0:
248 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
249 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
250 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
251 ; X86-BMI1NOTBM-NEXT: retl
253 ; X86-BMI1BMI2-LABEL: bzhi32_a4_commutative:
254 ; X86-BMI1BMI2: # %bb.0:
255 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
256 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
257 ; X86-BMI1BMI2-NEXT: retl
259 ; X64-NOBMI-LABEL: bzhi32_a4_commutative:
260 ; X64-NOBMI: # %bb.0:
261 ; X64-NOBMI-NEXT: movl %esi, %ecx
262 ; X64-NOBMI-NEXT: movl $1, %eax
263 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
264 ; X64-NOBMI-NEXT: shll %cl, %eax
265 ; X64-NOBMI-NEXT: decl %eax
266 ; X64-NOBMI-NEXT: andl %edi, %eax
267 ; X64-NOBMI-NEXT: retq
269 ; X64-BMI1NOTBM-LABEL: bzhi32_a4_commutative:
270 ; X64-BMI1NOTBM: # %bb.0:
271 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
272 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
273 ; X64-BMI1NOTBM-NEXT: retq
275 ; X64-BMI1BMI2-LABEL: bzhi32_a4_commutative:
276 ; X64-BMI1BMI2: # %bb.0:
277 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
278 ; X64-BMI1BMI2-NEXT: retq
279 %onebit = shl i32 1, %numlowbits
280 %mask = add nsw i32 %onebit, -1
281 %masked = and i32 %val, %mask ; swapped order
287 define i64 @bzhi64_a0(i64 %val, i64 %numlowbits) nounwind {
288 ; X86-NOBMI-LABEL: bzhi64_a0:
289 ; X86-NOBMI: # %bb.0:
290 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
291 ; X86-NOBMI-NEXT: movl $1, %eax
292 ; X86-NOBMI-NEXT: xorl %edx, %edx
293 ; X86-NOBMI-NEXT: shldl %cl, %eax, %edx
294 ; X86-NOBMI-NEXT: shll %cl, %eax
295 ; X86-NOBMI-NEXT: testb $32, %cl
296 ; X86-NOBMI-NEXT: je .LBB5_2
297 ; X86-NOBMI-NEXT: # %bb.1:
298 ; X86-NOBMI-NEXT: movl %eax, %edx
299 ; X86-NOBMI-NEXT: xorl %eax, %eax
300 ; X86-NOBMI-NEXT: .LBB5_2:
301 ; X86-NOBMI-NEXT: addl $-1, %eax
302 ; X86-NOBMI-NEXT: adcl $-1, %edx
303 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %edx
304 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
305 ; X86-NOBMI-NEXT: retl
307 ; X86-BMI1NOTBM-LABEL: bzhi64_a0:
308 ; X86-BMI1NOTBM: # %bb.0:
309 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
310 ; X86-BMI1NOTBM-NEXT: movl $1, %eax
311 ; X86-BMI1NOTBM-NEXT: xorl %edx, %edx
312 ; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %edx
313 ; X86-BMI1NOTBM-NEXT: shll %cl, %eax
314 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
315 ; X86-BMI1NOTBM-NEXT: je .LBB5_2
316 ; X86-BMI1NOTBM-NEXT: # %bb.1:
317 ; X86-BMI1NOTBM-NEXT: movl %eax, %edx
318 ; X86-BMI1NOTBM-NEXT: xorl %eax, %eax
319 ; X86-BMI1NOTBM-NEXT: .LBB5_2:
320 ; X86-BMI1NOTBM-NEXT: addl $-1, %eax
321 ; X86-BMI1NOTBM-NEXT: adcl $-1, %edx
322 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %edx
323 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %eax
324 ; X86-BMI1NOTBM-NEXT: retl
326 ; X86-BMI1BMI2-LABEL: bzhi64_a0:
327 ; X86-BMI1BMI2: # %bb.0:
328 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
329 ; X86-BMI1BMI2-NEXT: movl $1, %eax
330 ; X86-BMI1BMI2-NEXT: xorl %edx, %edx
331 ; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %edx
332 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %eax
333 ; X86-BMI1BMI2-NEXT: testb $32, %cl
334 ; X86-BMI1BMI2-NEXT: je .LBB5_2
335 ; X86-BMI1BMI2-NEXT: # %bb.1:
336 ; X86-BMI1BMI2-NEXT: movl %eax, %edx
337 ; X86-BMI1BMI2-NEXT: xorl %eax, %eax
338 ; X86-BMI1BMI2-NEXT: .LBB5_2:
339 ; X86-BMI1BMI2-NEXT: addl $-1, %eax
340 ; X86-BMI1BMI2-NEXT: adcl $-1, %edx
341 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %edx
342 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %eax
343 ; X86-BMI1BMI2-NEXT: retl
345 ; X64-NOBMI-LABEL: bzhi64_a0:
346 ; X64-NOBMI: # %bb.0:
347 ; X64-NOBMI-NEXT: movq %rsi, %rcx
348 ; X64-NOBMI-NEXT: movl $1, %eax
349 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
350 ; X64-NOBMI-NEXT: shlq %cl, %rax
351 ; X64-NOBMI-NEXT: decq %rax
352 ; X64-NOBMI-NEXT: andq %rdi, %rax
353 ; X64-NOBMI-NEXT: retq
355 ; X64-BMI1NOTBM-LABEL: bzhi64_a0:
356 ; X64-BMI1NOTBM: # %bb.0:
357 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
358 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, %rdi, %rax
359 ; X64-BMI1NOTBM-NEXT: retq
361 ; X64-BMI1BMI2-LABEL: bzhi64_a0:
362 ; X64-BMI1BMI2: # %bb.0:
363 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, %rdi, %rax
364 ; X64-BMI1BMI2-NEXT: retq
365 %onebit = shl i64 1, %numlowbits
366 %mask = add nsw i64 %onebit, -1
367 %masked = and i64 %mask, %val
371 define i64 @bzhi64_a1_indexzext(i64 %val, i8 zeroext %numlowbits) nounwind {
372 ; X86-NOBMI-LABEL: bzhi64_a1_indexzext:
373 ; X86-NOBMI: # %bb.0:
374 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
375 ; X86-NOBMI-NEXT: movl $1, %eax
376 ; X86-NOBMI-NEXT: xorl %edx, %edx
377 ; X86-NOBMI-NEXT: shldl %cl, %eax, %edx
378 ; X86-NOBMI-NEXT: shll %cl, %eax
379 ; X86-NOBMI-NEXT: testb $32, %cl
380 ; X86-NOBMI-NEXT: je .LBB6_2
381 ; X86-NOBMI-NEXT: # %bb.1:
382 ; X86-NOBMI-NEXT: movl %eax, %edx
383 ; X86-NOBMI-NEXT: xorl %eax, %eax
384 ; X86-NOBMI-NEXT: .LBB6_2:
385 ; X86-NOBMI-NEXT: addl $-1, %eax
386 ; X86-NOBMI-NEXT: adcl $-1, %edx
387 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %edx
388 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
389 ; X86-NOBMI-NEXT: retl
391 ; X86-BMI1NOTBM-LABEL: bzhi64_a1_indexzext:
392 ; X86-BMI1NOTBM: # %bb.0:
393 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
394 ; X86-BMI1NOTBM-NEXT: movl $1, %eax
395 ; X86-BMI1NOTBM-NEXT: xorl %edx, %edx
396 ; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %edx
397 ; X86-BMI1NOTBM-NEXT: shll %cl, %eax
398 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
399 ; X86-BMI1NOTBM-NEXT: je .LBB6_2
400 ; X86-BMI1NOTBM-NEXT: # %bb.1:
401 ; X86-BMI1NOTBM-NEXT: movl %eax, %edx
402 ; X86-BMI1NOTBM-NEXT: xorl %eax, %eax
403 ; X86-BMI1NOTBM-NEXT: .LBB6_2:
404 ; X86-BMI1NOTBM-NEXT: addl $-1, %eax
405 ; X86-BMI1NOTBM-NEXT: adcl $-1, %edx
406 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %edx
407 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %eax
408 ; X86-BMI1NOTBM-NEXT: retl
410 ; X86-BMI1BMI2-LABEL: bzhi64_a1_indexzext:
411 ; X86-BMI1BMI2: # %bb.0:
412 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
413 ; X86-BMI1BMI2-NEXT: movl $1, %eax
414 ; X86-BMI1BMI2-NEXT: xorl %edx, %edx
415 ; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %edx
416 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %eax
417 ; X86-BMI1BMI2-NEXT: testb $32, %cl
418 ; X86-BMI1BMI2-NEXT: je .LBB6_2
419 ; X86-BMI1BMI2-NEXT: # %bb.1:
420 ; X86-BMI1BMI2-NEXT: movl %eax, %edx
421 ; X86-BMI1BMI2-NEXT: xorl %eax, %eax
422 ; X86-BMI1BMI2-NEXT: .LBB6_2:
423 ; X86-BMI1BMI2-NEXT: addl $-1, %eax
424 ; X86-BMI1BMI2-NEXT: adcl $-1, %edx
425 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %edx
426 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %eax
427 ; X86-BMI1BMI2-NEXT: retl
429 ; X64-NOBMI-LABEL: bzhi64_a1_indexzext:
430 ; X64-NOBMI: # %bb.0:
431 ; X64-NOBMI-NEXT: movl %esi, %ecx
432 ; X64-NOBMI-NEXT: movl $1, %eax
433 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
434 ; X64-NOBMI-NEXT: shlq %cl, %rax
435 ; X64-NOBMI-NEXT: decq %rax
436 ; X64-NOBMI-NEXT: andq %rdi, %rax
437 ; X64-NOBMI-NEXT: retq
439 ; X64-BMI1NOTBM-LABEL: bzhi64_a1_indexzext:
440 ; X64-BMI1NOTBM: # %bb.0:
441 ; X64-BMI1NOTBM-NEXT: # kill: def $esi killed $esi def $rsi
442 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
443 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, %rdi, %rax
444 ; X64-BMI1NOTBM-NEXT: retq
446 ; X64-BMI1BMI2-LABEL: bzhi64_a1_indexzext:
447 ; X64-BMI1BMI2: # %bb.0:
448 ; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi
449 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, %rdi, %rax
450 ; X64-BMI1BMI2-NEXT: retq
451 %conv = zext i8 %numlowbits to i64
452 %onebit = shl i64 1, %conv
453 %mask = add nsw i64 %onebit, -1
454 %masked = and i64 %mask, %val
458 define i64 @bzhi64_a2_load(i64* %w, i64 %numlowbits) nounwind {
459 ; X86-NOBMI-LABEL: bzhi64_a2_load:
460 ; X86-NOBMI: # %bb.0:
461 ; X86-NOBMI-NEXT: pushl %esi
462 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi
463 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
464 ; X86-NOBMI-NEXT: movl $1, %eax
465 ; X86-NOBMI-NEXT: xorl %edx, %edx
466 ; X86-NOBMI-NEXT: shldl %cl, %eax, %edx
467 ; X86-NOBMI-NEXT: shll %cl, %eax
468 ; X86-NOBMI-NEXT: testb $32, %cl
469 ; X86-NOBMI-NEXT: je .LBB7_2
470 ; X86-NOBMI-NEXT: # %bb.1:
471 ; X86-NOBMI-NEXT: movl %eax, %edx
472 ; X86-NOBMI-NEXT: xorl %eax, %eax
473 ; X86-NOBMI-NEXT: .LBB7_2:
474 ; X86-NOBMI-NEXT: addl $-1, %eax
475 ; X86-NOBMI-NEXT: adcl $-1, %edx
476 ; X86-NOBMI-NEXT: andl 4(%esi), %edx
477 ; X86-NOBMI-NEXT: andl (%esi), %eax
478 ; X86-NOBMI-NEXT: popl %esi
479 ; X86-NOBMI-NEXT: retl
481 ; X86-BMI1NOTBM-LABEL: bzhi64_a2_load:
482 ; X86-BMI1NOTBM: # %bb.0:
483 ; X86-BMI1NOTBM-NEXT: pushl %esi
484 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi
485 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
486 ; X86-BMI1NOTBM-NEXT: movl $1, %eax
487 ; X86-BMI1NOTBM-NEXT: xorl %edx, %edx
488 ; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %edx
489 ; X86-BMI1NOTBM-NEXT: shll %cl, %eax
490 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
491 ; X86-BMI1NOTBM-NEXT: je .LBB7_2
492 ; X86-BMI1NOTBM-NEXT: # %bb.1:
493 ; X86-BMI1NOTBM-NEXT: movl %eax, %edx
494 ; X86-BMI1NOTBM-NEXT: xorl %eax, %eax
495 ; X86-BMI1NOTBM-NEXT: .LBB7_2:
496 ; X86-BMI1NOTBM-NEXT: addl $-1, %eax
497 ; X86-BMI1NOTBM-NEXT: adcl $-1, %edx
498 ; X86-BMI1NOTBM-NEXT: andl 4(%esi), %edx
499 ; X86-BMI1NOTBM-NEXT: andl (%esi), %eax
500 ; X86-BMI1NOTBM-NEXT: popl %esi
501 ; X86-BMI1NOTBM-NEXT: retl
503 ; X86-BMI1BMI2-LABEL: bzhi64_a2_load:
504 ; X86-BMI1BMI2: # %bb.0:
505 ; X86-BMI1BMI2-NEXT: pushl %esi
506 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi
507 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
508 ; X86-BMI1BMI2-NEXT: movl $1, %eax
509 ; X86-BMI1BMI2-NEXT: xorl %edx, %edx
510 ; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %edx
511 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %eax
512 ; X86-BMI1BMI2-NEXT: testb $32, %cl
513 ; X86-BMI1BMI2-NEXT: je .LBB7_2
514 ; X86-BMI1BMI2-NEXT: # %bb.1:
515 ; X86-BMI1BMI2-NEXT: movl %eax, %edx
516 ; X86-BMI1BMI2-NEXT: xorl %eax, %eax
517 ; X86-BMI1BMI2-NEXT: .LBB7_2:
518 ; X86-BMI1BMI2-NEXT: addl $-1, %eax
519 ; X86-BMI1BMI2-NEXT: adcl $-1, %edx
520 ; X86-BMI1BMI2-NEXT: andl 4(%esi), %edx
521 ; X86-BMI1BMI2-NEXT: andl (%esi), %eax
522 ; X86-BMI1BMI2-NEXT: popl %esi
523 ; X86-BMI1BMI2-NEXT: retl
525 ; X64-NOBMI-LABEL: bzhi64_a2_load:
526 ; X64-NOBMI: # %bb.0:
527 ; X64-NOBMI-NEXT: movq %rsi, %rcx
528 ; X64-NOBMI-NEXT: movl $1, %eax
529 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
530 ; X64-NOBMI-NEXT: shlq %cl, %rax
531 ; X64-NOBMI-NEXT: decq %rax
532 ; X64-NOBMI-NEXT: andq (%rdi), %rax
533 ; X64-NOBMI-NEXT: retq
535 ; X64-BMI1NOTBM-LABEL: bzhi64_a2_load:
536 ; X64-BMI1NOTBM: # %bb.0:
537 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
538 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, (%rdi), %rax
539 ; X64-BMI1NOTBM-NEXT: retq
541 ; X64-BMI1BMI2-LABEL: bzhi64_a2_load:
542 ; X64-BMI1BMI2: # %bb.0:
543 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, (%rdi), %rax
544 ; X64-BMI1BMI2-NEXT: retq
545 %val = load i64, i64* %w
546 %onebit = shl i64 1, %numlowbits
547 %mask = add nsw i64 %onebit, -1
548 %masked = and i64 %mask, %val
552 define i64 @bzhi64_a3_load_indexzext(i64* %w, i8 zeroext %numlowbits) nounwind {
553 ; X86-NOBMI-LABEL: bzhi64_a3_load_indexzext:
554 ; X86-NOBMI: # %bb.0:
555 ; X86-NOBMI-NEXT: pushl %esi
556 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi
557 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
558 ; X86-NOBMI-NEXT: movl $1, %eax
559 ; X86-NOBMI-NEXT: xorl %edx, %edx
560 ; X86-NOBMI-NEXT: shldl %cl, %eax, %edx
561 ; X86-NOBMI-NEXT: shll %cl, %eax
562 ; X86-NOBMI-NEXT: testb $32, %cl
563 ; X86-NOBMI-NEXT: je .LBB8_2
564 ; X86-NOBMI-NEXT: # %bb.1:
565 ; X86-NOBMI-NEXT: movl %eax, %edx
566 ; X86-NOBMI-NEXT: xorl %eax, %eax
567 ; X86-NOBMI-NEXT: .LBB8_2:
568 ; X86-NOBMI-NEXT: addl $-1, %eax
569 ; X86-NOBMI-NEXT: adcl $-1, %edx
570 ; X86-NOBMI-NEXT: andl 4(%esi), %edx
571 ; X86-NOBMI-NEXT: andl (%esi), %eax
572 ; X86-NOBMI-NEXT: popl %esi
573 ; X86-NOBMI-NEXT: retl
575 ; X86-BMI1NOTBM-LABEL: bzhi64_a3_load_indexzext:
576 ; X86-BMI1NOTBM: # %bb.0:
577 ; X86-BMI1NOTBM-NEXT: pushl %esi
578 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi
579 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
580 ; X86-BMI1NOTBM-NEXT: movl $1, %eax
581 ; X86-BMI1NOTBM-NEXT: xorl %edx, %edx
582 ; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %edx
583 ; X86-BMI1NOTBM-NEXT: shll %cl, %eax
584 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
585 ; X86-BMI1NOTBM-NEXT: je .LBB8_2
586 ; X86-BMI1NOTBM-NEXT: # %bb.1:
587 ; X86-BMI1NOTBM-NEXT: movl %eax, %edx
588 ; X86-BMI1NOTBM-NEXT: xorl %eax, %eax
589 ; X86-BMI1NOTBM-NEXT: .LBB8_2:
590 ; X86-BMI1NOTBM-NEXT: addl $-1, %eax
591 ; X86-BMI1NOTBM-NEXT: adcl $-1, %edx
592 ; X86-BMI1NOTBM-NEXT: andl 4(%esi), %edx
593 ; X86-BMI1NOTBM-NEXT: andl (%esi), %eax
594 ; X86-BMI1NOTBM-NEXT: popl %esi
595 ; X86-BMI1NOTBM-NEXT: retl
597 ; X86-BMI1BMI2-LABEL: bzhi64_a3_load_indexzext:
598 ; X86-BMI1BMI2: # %bb.0:
599 ; X86-BMI1BMI2-NEXT: pushl %esi
600 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi
601 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
602 ; X86-BMI1BMI2-NEXT: movl $1, %eax
603 ; X86-BMI1BMI2-NEXT: xorl %edx, %edx
604 ; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %edx
605 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %eax
606 ; X86-BMI1BMI2-NEXT: testb $32, %cl
607 ; X86-BMI1BMI2-NEXT: je .LBB8_2
608 ; X86-BMI1BMI2-NEXT: # %bb.1:
609 ; X86-BMI1BMI2-NEXT: movl %eax, %edx
610 ; X86-BMI1BMI2-NEXT: xorl %eax, %eax
611 ; X86-BMI1BMI2-NEXT: .LBB8_2:
612 ; X86-BMI1BMI2-NEXT: addl $-1, %eax
613 ; X86-BMI1BMI2-NEXT: adcl $-1, %edx
614 ; X86-BMI1BMI2-NEXT: andl 4(%esi), %edx
615 ; X86-BMI1BMI2-NEXT: andl (%esi), %eax
616 ; X86-BMI1BMI2-NEXT: popl %esi
617 ; X86-BMI1BMI2-NEXT: retl
619 ; X64-NOBMI-LABEL: bzhi64_a3_load_indexzext:
620 ; X64-NOBMI: # %bb.0:
621 ; X64-NOBMI-NEXT: movl %esi, %ecx
622 ; X64-NOBMI-NEXT: movl $1, %eax
623 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
624 ; X64-NOBMI-NEXT: shlq %cl, %rax
625 ; X64-NOBMI-NEXT: decq %rax
626 ; X64-NOBMI-NEXT: andq (%rdi), %rax
627 ; X64-NOBMI-NEXT: retq
629 ; X64-BMI1NOTBM-LABEL: bzhi64_a3_load_indexzext:
630 ; X64-BMI1NOTBM: # %bb.0:
631 ; X64-BMI1NOTBM-NEXT: # kill: def $esi killed $esi def $rsi
632 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
633 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, (%rdi), %rax
634 ; X64-BMI1NOTBM-NEXT: retq
636 ; X64-BMI1BMI2-LABEL: bzhi64_a3_load_indexzext:
637 ; X64-BMI1BMI2: # %bb.0:
638 ; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi
639 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, (%rdi), %rax
640 ; X64-BMI1BMI2-NEXT: retq
641 %val = load i64, i64* %w
642 %conv = zext i8 %numlowbits to i64
643 %onebit = shl i64 1, %conv
644 %mask = add nsw i64 %onebit, -1
645 %masked = and i64 %mask, %val
649 define i64 @bzhi64_a4_commutative(i64 %val, i64 %numlowbits) nounwind {
650 ; X86-NOBMI-LABEL: bzhi64_a4_commutative:
651 ; X86-NOBMI: # %bb.0:
652 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
653 ; X86-NOBMI-NEXT: movl $1, %eax
654 ; X86-NOBMI-NEXT: xorl %edx, %edx
655 ; X86-NOBMI-NEXT: shldl %cl, %eax, %edx
656 ; X86-NOBMI-NEXT: shll %cl, %eax
657 ; X86-NOBMI-NEXT: testb $32, %cl
658 ; X86-NOBMI-NEXT: je .LBB9_2
659 ; X86-NOBMI-NEXT: # %bb.1:
660 ; X86-NOBMI-NEXT: movl %eax, %edx
661 ; X86-NOBMI-NEXT: xorl %eax, %eax
662 ; X86-NOBMI-NEXT: .LBB9_2:
663 ; X86-NOBMI-NEXT: addl $-1, %eax
664 ; X86-NOBMI-NEXT: adcl $-1, %edx
665 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %edx
666 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
667 ; X86-NOBMI-NEXT: retl
669 ; X86-BMI1NOTBM-LABEL: bzhi64_a4_commutative:
670 ; X86-BMI1NOTBM: # %bb.0:
671 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
672 ; X86-BMI1NOTBM-NEXT: movl $1, %eax
673 ; X86-BMI1NOTBM-NEXT: xorl %edx, %edx
674 ; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %edx
675 ; X86-BMI1NOTBM-NEXT: shll %cl, %eax
676 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
677 ; X86-BMI1NOTBM-NEXT: je .LBB9_2
678 ; X86-BMI1NOTBM-NEXT: # %bb.1:
679 ; X86-BMI1NOTBM-NEXT: movl %eax, %edx
680 ; X86-BMI1NOTBM-NEXT: xorl %eax, %eax
681 ; X86-BMI1NOTBM-NEXT: .LBB9_2:
682 ; X86-BMI1NOTBM-NEXT: addl $-1, %eax
683 ; X86-BMI1NOTBM-NEXT: adcl $-1, %edx
684 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %edx
685 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %eax
686 ; X86-BMI1NOTBM-NEXT: retl
688 ; X86-BMI1BMI2-LABEL: bzhi64_a4_commutative:
689 ; X86-BMI1BMI2: # %bb.0:
690 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
691 ; X86-BMI1BMI2-NEXT: movl $1, %eax
692 ; X86-BMI1BMI2-NEXT: xorl %edx, %edx
693 ; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %edx
694 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %eax
695 ; X86-BMI1BMI2-NEXT: testb $32, %cl
696 ; X86-BMI1BMI2-NEXT: je .LBB9_2
697 ; X86-BMI1BMI2-NEXT: # %bb.1:
698 ; X86-BMI1BMI2-NEXT: movl %eax, %edx
699 ; X86-BMI1BMI2-NEXT: xorl %eax, %eax
700 ; X86-BMI1BMI2-NEXT: .LBB9_2:
701 ; X86-BMI1BMI2-NEXT: addl $-1, %eax
702 ; X86-BMI1BMI2-NEXT: adcl $-1, %edx
703 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %edx
704 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %eax
705 ; X86-BMI1BMI2-NEXT: retl
707 ; X64-NOBMI-LABEL: bzhi64_a4_commutative:
708 ; X64-NOBMI: # %bb.0:
709 ; X64-NOBMI-NEXT: movq %rsi, %rcx
710 ; X64-NOBMI-NEXT: movl $1, %eax
711 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
712 ; X64-NOBMI-NEXT: shlq %cl, %rax
713 ; X64-NOBMI-NEXT: decq %rax
714 ; X64-NOBMI-NEXT: andq %rdi, %rax
715 ; X64-NOBMI-NEXT: retq
717 ; X64-BMI1NOTBM-LABEL: bzhi64_a4_commutative:
718 ; X64-BMI1NOTBM: # %bb.0:
719 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
720 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, %rdi, %rax
721 ; X64-BMI1NOTBM-NEXT: retq
723 ; X64-BMI1BMI2-LABEL: bzhi64_a4_commutative:
724 ; X64-BMI1BMI2: # %bb.0:
725 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, %rdi, %rax
726 ; X64-BMI1BMI2-NEXT: retq
727 %onebit = shl i64 1, %numlowbits
728 %mask = add nsw i64 %onebit, -1
729 %masked = and i64 %val, %mask ; swapped order
733 ; 64-bit, but with 32-bit output
735 ; Everything done in 64-bit, truncation happens last.
736 define i32 @bzhi64_32_a0(i64 %val, i64 %numlowbits) nounwind {
737 ; X86-NOBMI-LABEL: bzhi64_32_a0:
738 ; X86-NOBMI: # %bb.0:
739 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
740 ; X86-NOBMI-NEXT: movl $1, %edx
741 ; X86-NOBMI-NEXT: shll %cl, %edx
742 ; X86-NOBMI-NEXT: xorl %eax, %eax
743 ; X86-NOBMI-NEXT: testb $32, %cl
744 ; X86-NOBMI-NEXT: jne .LBB10_2
745 ; X86-NOBMI-NEXT: # %bb.1:
746 ; X86-NOBMI-NEXT: movl %edx, %eax
747 ; X86-NOBMI-NEXT: .LBB10_2:
748 ; X86-NOBMI-NEXT: decl %eax
749 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
750 ; X86-NOBMI-NEXT: retl
752 ; X86-BMI1NOTBM-LABEL: bzhi64_32_a0:
753 ; X86-BMI1NOTBM: # %bb.0:
754 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
755 ; X86-BMI1NOTBM-NEXT: movl $1, %edx
756 ; X86-BMI1NOTBM-NEXT: shll %cl, %edx
757 ; X86-BMI1NOTBM-NEXT: xorl %eax, %eax
758 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
759 ; X86-BMI1NOTBM-NEXT: jne .LBB10_2
760 ; X86-BMI1NOTBM-NEXT: # %bb.1:
761 ; X86-BMI1NOTBM-NEXT: movl %edx, %eax
762 ; X86-BMI1NOTBM-NEXT: .LBB10_2:
763 ; X86-BMI1NOTBM-NEXT: decl %eax
764 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %eax
765 ; X86-BMI1NOTBM-NEXT: retl
767 ; X86-BMI1BMI2-LABEL: bzhi64_32_a0:
768 ; X86-BMI1BMI2: # %bb.0:
769 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
770 ; X86-BMI1BMI2-NEXT: xorl %eax, %eax
771 ; X86-BMI1BMI2-NEXT: testb $32, %cl
772 ; X86-BMI1BMI2-NEXT: jne .LBB10_2
773 ; X86-BMI1BMI2-NEXT: # %bb.1:
774 ; X86-BMI1BMI2-NEXT: movl $1, %eax
775 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %eax
776 ; X86-BMI1BMI2-NEXT: .LBB10_2:
777 ; X86-BMI1BMI2-NEXT: decl %eax
778 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %eax
779 ; X86-BMI1BMI2-NEXT: retl
781 ; X64-NOBMI-LABEL: bzhi64_32_a0:
782 ; X64-NOBMI: # %bb.0:
783 ; X64-NOBMI-NEXT: movq %rsi, %rcx
784 ; X64-NOBMI-NEXT: movl $1, %eax
785 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
786 ; X64-NOBMI-NEXT: shlq %cl, %rax
787 ; X64-NOBMI-NEXT: decl %eax
788 ; X64-NOBMI-NEXT: andl %edi, %eax
789 ; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax
790 ; X64-NOBMI-NEXT: retq
792 ; X64-BMI1NOTBM-LABEL: bzhi64_32_a0:
793 ; X64-BMI1NOTBM: # %bb.0:
794 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
795 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
796 ; X64-BMI1NOTBM-NEXT: retq
798 ; X64-BMI1BMI2-LABEL: bzhi64_32_a0:
799 ; X64-BMI1BMI2: # %bb.0:
800 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
801 ; X64-BMI1BMI2-NEXT: retq
802 %onebit = shl i64 1, %numlowbits
803 %mask = add nsw i64 %onebit, -1
804 %masked = and i64 %mask, %val
805 %res = trunc i64 %masked to i32
809 ; Shifting happens in 64-bit, then truncation. Masking is 32-bit.
810 define i32 @bzhi64_32_a1(i64 %val, i32 %numlowbits) nounwind {
811 ; X86-NOBMI-LABEL: bzhi64_32_a1:
812 ; X86-NOBMI: # %bb.0:
813 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
814 ; X86-NOBMI-NEXT: movl $1, %eax
815 ; X86-NOBMI-NEXT: shll %cl, %eax
816 ; X86-NOBMI-NEXT: decl %eax
817 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
818 ; X86-NOBMI-NEXT: retl
820 ; X86-BMI1NOTBM-LABEL: bzhi64_32_a1:
821 ; X86-BMI1NOTBM: # %bb.0:
822 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
823 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
824 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
825 ; X86-BMI1NOTBM-NEXT: retl
827 ; X86-BMI1BMI2-LABEL: bzhi64_32_a1:
828 ; X86-BMI1BMI2: # %bb.0:
829 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
830 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
831 ; X86-BMI1BMI2-NEXT: retl
833 ; X64-NOBMI-LABEL: bzhi64_32_a1:
834 ; X64-NOBMI: # %bb.0:
835 ; X64-NOBMI-NEXT: movl %esi, %ecx
836 ; X64-NOBMI-NEXT: movl $1, %eax
837 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
838 ; X64-NOBMI-NEXT: shll %cl, %eax
839 ; X64-NOBMI-NEXT: decl %eax
840 ; X64-NOBMI-NEXT: andl %edi, %eax
841 ; X64-NOBMI-NEXT: retq
843 ; X64-BMI1NOTBM-LABEL: bzhi64_32_a1:
844 ; X64-BMI1NOTBM: # %bb.0:
845 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
846 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
847 ; X64-BMI1NOTBM-NEXT: retq
849 ; X64-BMI1BMI2-LABEL: bzhi64_32_a1:
850 ; X64-BMI1BMI2: # %bb.0:
851 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
852 ; X64-BMI1BMI2-NEXT: retq
853 %truncval = trunc i64 %val to i32
854 %onebit = shl i32 1, %numlowbits
855 %mask = add nsw i32 %onebit, -1
856 %masked = and i32 %mask, %truncval
860 ; Shifting happens in 64-bit, then truncation (with extra use).
862 define i32 @bzhi64_32_a1_trunc_extrause(i64 %val, i32 %numlowbits) nounwind {
863 ; X86-NOBMI-LABEL: bzhi64_32_a1_trunc_extrause:
864 ; X86-NOBMI: # %bb.0:
865 ; X86-NOBMI-NEXT: pushl %ebx
866 ; X86-NOBMI-NEXT: pushl %esi
867 ; X86-NOBMI-NEXT: pushl %eax
868 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %bl
869 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi
870 ; X86-NOBMI-NEXT: movl %esi, (%esp)
871 ; X86-NOBMI-NEXT: calll use32
872 ; X86-NOBMI-NEXT: movl $1, %eax
873 ; X86-NOBMI-NEXT: movl %ebx, %ecx
874 ; X86-NOBMI-NEXT: shll %cl, %eax
875 ; X86-NOBMI-NEXT: decl %eax
876 ; X86-NOBMI-NEXT: andl %esi, %eax
877 ; X86-NOBMI-NEXT: addl $4, %esp
878 ; X86-NOBMI-NEXT: popl %esi
879 ; X86-NOBMI-NEXT: popl %ebx
880 ; X86-NOBMI-NEXT: retl
882 ; X86-BMI1NOTBM-LABEL: bzhi64_32_a1_trunc_extrause:
883 ; X86-BMI1NOTBM: # %bb.0:
884 ; X86-BMI1NOTBM-NEXT: pushl %ebx
885 ; X86-BMI1NOTBM-NEXT: pushl %esi
886 ; X86-BMI1NOTBM-NEXT: pushl %eax
887 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %bl
888 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi
889 ; X86-BMI1NOTBM-NEXT: movl %esi, (%esp)
890 ; X86-BMI1NOTBM-NEXT: calll use32
891 ; X86-BMI1NOTBM-NEXT: shll $8, %ebx
892 ; X86-BMI1NOTBM-NEXT: bextrl %ebx, %esi, %eax
893 ; X86-BMI1NOTBM-NEXT: addl $4, %esp
894 ; X86-BMI1NOTBM-NEXT: popl %esi
895 ; X86-BMI1NOTBM-NEXT: popl %ebx
896 ; X86-BMI1NOTBM-NEXT: retl
898 ; X86-BMI1BMI2-LABEL: bzhi64_32_a1_trunc_extrause:
899 ; X86-BMI1BMI2: # %bb.0:
900 ; X86-BMI1BMI2-NEXT: pushl %ebx
901 ; X86-BMI1BMI2-NEXT: pushl %esi
902 ; X86-BMI1BMI2-NEXT: pushl %eax
903 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl
904 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi
905 ; X86-BMI1BMI2-NEXT: movl %esi, (%esp)
906 ; X86-BMI1BMI2-NEXT: calll use32
907 ; X86-BMI1BMI2-NEXT: bzhil %ebx, %esi, %eax
908 ; X86-BMI1BMI2-NEXT: addl $4, %esp
909 ; X86-BMI1BMI2-NEXT: popl %esi
910 ; X86-BMI1BMI2-NEXT: popl %ebx
911 ; X86-BMI1BMI2-NEXT: retl
913 ; X64-NOBMI-LABEL: bzhi64_32_a1_trunc_extrause:
914 ; X64-NOBMI: # %bb.0:
915 ; X64-NOBMI-NEXT: pushq %rbp
916 ; X64-NOBMI-NEXT: pushq %rbx
917 ; X64-NOBMI-NEXT: pushq %rax
918 ; X64-NOBMI-NEXT: movl %esi, %ebp
919 ; X64-NOBMI-NEXT: movq %rdi, %rbx
920 ; X64-NOBMI-NEXT: callq use32
921 ; X64-NOBMI-NEXT: movl $1, %eax
922 ; X64-NOBMI-NEXT: movl %ebp, %ecx
923 ; X64-NOBMI-NEXT: shll %cl, %eax
924 ; X64-NOBMI-NEXT: decl %eax
925 ; X64-NOBMI-NEXT: andl %ebx, %eax
926 ; X64-NOBMI-NEXT: addq $8, %rsp
927 ; X64-NOBMI-NEXT: popq %rbx
928 ; X64-NOBMI-NEXT: popq %rbp
929 ; X64-NOBMI-NEXT: retq
931 ; X64-BMI1NOTBM-LABEL: bzhi64_32_a1_trunc_extrause:
932 ; X64-BMI1NOTBM: # %bb.0:
933 ; X64-BMI1NOTBM-NEXT: pushq %r14
934 ; X64-BMI1NOTBM-NEXT: pushq %rbx
935 ; X64-BMI1NOTBM-NEXT: pushq %rax
936 ; X64-BMI1NOTBM-NEXT: movl %esi, %ebx
937 ; X64-BMI1NOTBM-NEXT: movq %rdi, %r14
938 ; X64-BMI1NOTBM-NEXT: callq use32
939 ; X64-BMI1NOTBM-NEXT: shll $8, %ebx
940 ; X64-BMI1NOTBM-NEXT: bextrl %ebx, %r14d, %eax
941 ; X64-BMI1NOTBM-NEXT: addq $8, %rsp
942 ; X64-BMI1NOTBM-NEXT: popq %rbx
943 ; X64-BMI1NOTBM-NEXT: popq %r14
944 ; X64-BMI1NOTBM-NEXT: retq
946 ; X64-BMI1BMI2-LABEL: bzhi64_32_a1_trunc_extrause:
947 ; X64-BMI1BMI2: # %bb.0:
948 ; X64-BMI1BMI2-NEXT: pushq %rbp
949 ; X64-BMI1BMI2-NEXT: pushq %rbx
950 ; X64-BMI1BMI2-NEXT: pushq %rax
951 ; X64-BMI1BMI2-NEXT: movl %esi, %ebp
952 ; X64-BMI1BMI2-NEXT: movq %rdi, %rbx
953 ; X64-BMI1BMI2-NEXT: callq use32
954 ; X64-BMI1BMI2-NEXT: bzhil %ebp, %ebx, %eax
955 ; X64-BMI1BMI2-NEXT: addq $8, %rsp
956 ; X64-BMI1BMI2-NEXT: popq %rbx
957 ; X64-BMI1BMI2-NEXT: popq %rbp
958 ; X64-BMI1BMI2-NEXT: retq
959 %truncval = trunc i64 %val to i32
960 call void @use32(i32 %truncval)
961 %onebit = shl i32 1, %numlowbits
962 %mask = add nsw i32 %onebit, -1
963 %masked = and i32 %mask, %truncval
967 ; Shifting happens in 64-bit. Mask is 32-bit, but extended to 64-bit.
968 ; Masking is 64-bit. Then truncation.
969 define i32 @bzhi64_32_a2(i64 %val, i32 %numlowbits) nounwind {
970 ; X86-NOBMI-LABEL: bzhi64_32_a2:
971 ; X86-NOBMI: # %bb.0:
972 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
973 ; X86-NOBMI-NEXT: movl $1, %eax
974 ; X86-NOBMI-NEXT: shll %cl, %eax
975 ; X86-NOBMI-NEXT: decl %eax
976 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
977 ; X86-NOBMI-NEXT: retl
979 ; X86-BMI1NOTBM-LABEL: bzhi64_32_a2:
980 ; X86-BMI1NOTBM: # %bb.0:
981 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
982 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
983 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
984 ; X86-BMI1NOTBM-NEXT: retl
986 ; X86-BMI1BMI2-LABEL: bzhi64_32_a2:
987 ; X86-BMI1BMI2: # %bb.0:
988 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
989 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
990 ; X86-BMI1BMI2-NEXT: retl
992 ; X64-NOBMI-LABEL: bzhi64_32_a2:
993 ; X64-NOBMI: # %bb.0:
994 ; X64-NOBMI-NEXT: movl %esi, %ecx
995 ; X64-NOBMI-NEXT: movl $1, %eax
996 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
997 ; X64-NOBMI-NEXT: shll %cl, %eax
998 ; X64-NOBMI-NEXT: decl %eax
999 ; X64-NOBMI-NEXT: andl %edi, %eax
1000 ; X64-NOBMI-NEXT: retq
1002 ; X64-BMI1NOTBM-LABEL: bzhi64_32_a2:
1003 ; X64-BMI1NOTBM: # %bb.0:
1004 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1005 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
1006 ; X64-BMI1NOTBM-NEXT: retq
1008 ; X64-BMI1BMI2-LABEL: bzhi64_32_a2:
1009 ; X64-BMI1BMI2: # %bb.0:
1010 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
1011 ; X64-BMI1BMI2-NEXT: retq
1012 %onebit = shl i32 1, %numlowbits
1013 %mask = add nsw i32 %onebit, -1
1014 %zextmask = zext i32 %mask to i64
1015 %masked = and i64 %zextmask, %val
1016 %truncmasked = trunc i64 %masked to i32
1017 ret i32 %truncmasked
1020 ; Shifting happens in 64-bit. Mask is 32-bit, but calculated in 64-bit.
1021 ; Masking is 64-bit. Then truncation.
1022 define i32 @bzhi64_32_a3(i64 %val, i64 %numlowbits) nounwind {
1023 ; X86-NOBMI-LABEL: bzhi64_32_a3:
1024 ; X86-NOBMI: # %bb.0:
1025 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1026 ; X86-NOBMI-NEXT: movl $1, %edx
1027 ; X86-NOBMI-NEXT: shll %cl, %edx
1028 ; X86-NOBMI-NEXT: xorl %eax, %eax
1029 ; X86-NOBMI-NEXT: testb $32, %cl
1030 ; X86-NOBMI-NEXT: jne .LBB14_2
1031 ; X86-NOBMI-NEXT: # %bb.1:
1032 ; X86-NOBMI-NEXT: movl %edx, %eax
1033 ; X86-NOBMI-NEXT: .LBB14_2:
1034 ; X86-NOBMI-NEXT: decl %eax
1035 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
1036 ; X86-NOBMI-NEXT: retl
1038 ; X86-BMI1NOTBM-LABEL: bzhi64_32_a3:
1039 ; X86-BMI1NOTBM: # %bb.0:
1040 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
1041 ; X86-BMI1NOTBM-NEXT: movl $1, %edx
1042 ; X86-BMI1NOTBM-NEXT: shll %cl, %edx
1043 ; X86-BMI1NOTBM-NEXT: xorl %eax, %eax
1044 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
1045 ; X86-BMI1NOTBM-NEXT: jne .LBB14_2
1046 ; X86-BMI1NOTBM-NEXT: # %bb.1:
1047 ; X86-BMI1NOTBM-NEXT: movl %edx, %eax
1048 ; X86-BMI1NOTBM-NEXT: .LBB14_2:
1049 ; X86-BMI1NOTBM-NEXT: decl %eax
1050 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %eax
1051 ; X86-BMI1NOTBM-NEXT: retl
1053 ; X86-BMI1BMI2-LABEL: bzhi64_32_a3:
1054 ; X86-BMI1BMI2: # %bb.0:
1055 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
1056 ; X86-BMI1BMI2-NEXT: xorl %eax, %eax
1057 ; X86-BMI1BMI2-NEXT: testb $32, %cl
1058 ; X86-BMI1BMI2-NEXT: jne .LBB14_2
1059 ; X86-BMI1BMI2-NEXT: # %bb.1:
1060 ; X86-BMI1BMI2-NEXT: movl $1, %eax
1061 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %eax
1062 ; X86-BMI1BMI2-NEXT: .LBB14_2:
1063 ; X86-BMI1BMI2-NEXT: decl %eax
1064 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %eax
1065 ; X86-BMI1BMI2-NEXT: retl
1067 ; X64-NOBMI-LABEL: bzhi64_32_a3:
1068 ; X64-NOBMI: # %bb.0:
1069 ; X64-NOBMI-NEXT: movq %rsi, %rcx
1070 ; X64-NOBMI-NEXT: movl $1, %eax
1071 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
1072 ; X64-NOBMI-NEXT: shlq %cl, %rax
1073 ; X64-NOBMI-NEXT: decl %eax
1074 ; X64-NOBMI-NEXT: andl %edi, %eax
1075 ; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax
1076 ; X64-NOBMI-NEXT: retq
1078 ; X64-BMI1NOTBM-LABEL: bzhi64_32_a3:
1079 ; X64-BMI1NOTBM: # %bb.0:
1080 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1081 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
1082 ; X64-BMI1NOTBM-NEXT: retq
1084 ; X64-BMI1BMI2-LABEL: bzhi64_32_a3:
1085 ; X64-BMI1BMI2: # %bb.0:
1086 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
1087 ; X64-BMI1BMI2-NEXT: retq
1088 %onebit = shl i64 1, %numlowbits
1089 %mask = add nsw i64 %onebit, 4294967295
1090 %masked = and i64 %mask, %val
1091 %truncmasked = trunc i64 %masked to i32
1092 ret i32 %truncmasked
1095 ; ---------------------------------------------------------------------------- ;
1097 ; ---------------------------------------------------------------------------- ;
1099 define i32 @bzhi32_b0(i32 %val, i32 %numlowbits) nounwind {
1100 ; X86-NOBMI-LABEL: bzhi32_b0:
1101 ; X86-NOBMI: # %bb.0:
1102 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1103 ; X86-NOBMI-NEXT: movl $-1, %eax
1104 ; X86-NOBMI-NEXT: shll %cl, %eax
1105 ; X86-NOBMI-NEXT: notl %eax
1106 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
1107 ; X86-NOBMI-NEXT: retl
1109 ; X86-BMI1NOTBM-LABEL: bzhi32_b0:
1110 ; X86-BMI1NOTBM: # %bb.0:
1111 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
1112 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
1113 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
1114 ; X86-BMI1NOTBM-NEXT: retl
1116 ; X86-BMI1BMI2-LABEL: bzhi32_b0:
1117 ; X86-BMI1BMI2: # %bb.0:
1118 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
1119 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
1120 ; X86-BMI1BMI2-NEXT: retl
1122 ; X64-NOBMI-LABEL: bzhi32_b0:
1123 ; X64-NOBMI: # %bb.0:
1124 ; X64-NOBMI-NEXT: movl %esi, %ecx
1125 ; X64-NOBMI-NEXT: movl $-1, %eax
1126 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
1127 ; X64-NOBMI-NEXT: shll %cl, %eax
1128 ; X64-NOBMI-NEXT: notl %eax
1129 ; X64-NOBMI-NEXT: andl %edi, %eax
1130 ; X64-NOBMI-NEXT: retq
1132 ; X64-BMI1NOTBM-LABEL: bzhi32_b0:
1133 ; X64-BMI1NOTBM: # %bb.0:
1134 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1135 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
1136 ; X64-BMI1NOTBM-NEXT: retq
1138 ; X64-BMI1BMI2-LABEL: bzhi32_b0:
1139 ; X64-BMI1BMI2: # %bb.0:
1140 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
1141 ; X64-BMI1BMI2-NEXT: retq
1142 %notmask = shl i32 -1, %numlowbits
1143 %mask = xor i32 %notmask, -1
1144 %masked = and i32 %mask, %val
1148 define i32 @bzhi32_b1_indexzext(i32 %val, i8 zeroext %numlowbits) nounwind {
1149 ; X86-NOBMI-LABEL: bzhi32_b1_indexzext:
1150 ; X86-NOBMI: # %bb.0:
1151 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1152 ; X86-NOBMI-NEXT: movl $-1, %eax
1153 ; X86-NOBMI-NEXT: shll %cl, %eax
1154 ; X86-NOBMI-NEXT: notl %eax
1155 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
1156 ; X86-NOBMI-NEXT: retl
1158 ; X86-BMI1NOTBM-LABEL: bzhi32_b1_indexzext:
1159 ; X86-BMI1NOTBM: # %bb.0:
1160 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
1161 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
1162 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
1163 ; X86-BMI1NOTBM-NEXT: retl
1165 ; X86-BMI1BMI2-LABEL: bzhi32_b1_indexzext:
1166 ; X86-BMI1BMI2: # %bb.0:
1167 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
1168 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
1169 ; X86-BMI1BMI2-NEXT: retl
1171 ; X64-NOBMI-LABEL: bzhi32_b1_indexzext:
1172 ; X64-NOBMI: # %bb.0:
1173 ; X64-NOBMI-NEXT: movl %esi, %ecx
1174 ; X64-NOBMI-NEXT: movl $-1, %eax
1175 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
1176 ; X64-NOBMI-NEXT: shll %cl, %eax
1177 ; X64-NOBMI-NEXT: notl %eax
1178 ; X64-NOBMI-NEXT: andl %edi, %eax
1179 ; X64-NOBMI-NEXT: retq
1181 ; X64-BMI1NOTBM-LABEL: bzhi32_b1_indexzext:
1182 ; X64-BMI1NOTBM: # %bb.0:
1183 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1184 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
1185 ; X64-BMI1NOTBM-NEXT: retq
1187 ; X64-BMI1BMI2-LABEL: bzhi32_b1_indexzext:
1188 ; X64-BMI1BMI2: # %bb.0:
1189 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
1190 ; X64-BMI1BMI2-NEXT: retq
1191 %conv = zext i8 %numlowbits to i32
1192 %notmask = shl i32 -1, %conv
1193 %mask = xor i32 %notmask, -1
1194 %masked = and i32 %mask, %val
1198 define i32 @bzhi32_b2_load(i32* %w, i32 %numlowbits) nounwind {
1199 ; X86-NOBMI-LABEL: bzhi32_b2_load:
1200 ; X86-NOBMI: # %bb.0:
1201 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx
1202 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1203 ; X86-NOBMI-NEXT: movl $-1, %eax
1204 ; X86-NOBMI-NEXT: shll %cl, %eax
1205 ; X86-NOBMI-NEXT: notl %eax
1206 ; X86-NOBMI-NEXT: andl (%edx), %eax
1207 ; X86-NOBMI-NEXT: retl
1209 ; X86-BMI1NOTBM-LABEL: bzhi32_b2_load:
1210 ; X86-BMI1NOTBM: # %bb.0:
1211 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
1212 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
1213 ; X86-BMI1NOTBM-NEXT: shll $8, %ecx
1214 ; X86-BMI1NOTBM-NEXT: bextrl %ecx, (%eax), %eax
1215 ; X86-BMI1NOTBM-NEXT: retl
1217 ; X86-BMI1BMI2-LABEL: bzhi32_b2_load:
1218 ; X86-BMI1BMI2: # %bb.0:
1219 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
1220 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
1221 ; X86-BMI1BMI2-NEXT: bzhil %ecx, (%eax), %eax
1222 ; X86-BMI1BMI2-NEXT: retl
1224 ; X64-NOBMI-LABEL: bzhi32_b2_load:
1225 ; X64-NOBMI: # %bb.0:
1226 ; X64-NOBMI-NEXT: movl %esi, %ecx
1227 ; X64-NOBMI-NEXT: movl $-1, %eax
1228 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
1229 ; X64-NOBMI-NEXT: shll %cl, %eax
1230 ; X64-NOBMI-NEXT: notl %eax
1231 ; X64-NOBMI-NEXT: andl (%rdi), %eax
1232 ; X64-NOBMI-NEXT: retq
1234 ; X64-BMI1NOTBM-LABEL: bzhi32_b2_load:
1235 ; X64-BMI1NOTBM: # %bb.0:
1236 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1237 ; X64-BMI1NOTBM-NEXT: bextrl %esi, (%rdi), %eax
1238 ; X64-BMI1NOTBM-NEXT: retq
1240 ; X64-BMI1BMI2-LABEL: bzhi32_b2_load:
1241 ; X64-BMI1BMI2: # %bb.0:
1242 ; X64-BMI1BMI2-NEXT: bzhil %esi, (%rdi), %eax
1243 ; X64-BMI1BMI2-NEXT: retq
1244 %val = load i32, i32* %w
1245 %notmask = shl i32 -1, %numlowbits
1246 %mask = xor i32 %notmask, -1
1247 %masked = and i32 %mask, %val
1251 define i32 @bzhi32_b3_load_indexzext(i32* %w, i8 zeroext %numlowbits) nounwind {
1252 ; X86-NOBMI-LABEL: bzhi32_b3_load_indexzext:
1253 ; X86-NOBMI: # %bb.0:
1254 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx
1255 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1256 ; X86-NOBMI-NEXT: movl $-1, %eax
1257 ; X86-NOBMI-NEXT: shll %cl, %eax
1258 ; X86-NOBMI-NEXT: notl %eax
1259 ; X86-NOBMI-NEXT: andl (%edx), %eax
1260 ; X86-NOBMI-NEXT: retl
1262 ; X86-BMI1NOTBM-LABEL: bzhi32_b3_load_indexzext:
1263 ; X86-BMI1NOTBM: # %bb.0:
1264 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
1265 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
1266 ; X86-BMI1NOTBM-NEXT: shll $8, %ecx
1267 ; X86-BMI1NOTBM-NEXT: bextrl %ecx, (%eax), %eax
1268 ; X86-BMI1NOTBM-NEXT: retl
1270 ; X86-BMI1BMI2-LABEL: bzhi32_b3_load_indexzext:
1271 ; X86-BMI1BMI2: # %bb.0:
1272 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
1273 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
1274 ; X86-BMI1BMI2-NEXT: bzhil %ecx, (%eax), %eax
1275 ; X86-BMI1BMI2-NEXT: retl
1277 ; X64-NOBMI-LABEL: bzhi32_b3_load_indexzext:
1278 ; X64-NOBMI: # %bb.0:
1279 ; X64-NOBMI-NEXT: movl %esi, %ecx
1280 ; X64-NOBMI-NEXT: movl $-1, %eax
1281 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
1282 ; X64-NOBMI-NEXT: shll %cl, %eax
1283 ; X64-NOBMI-NEXT: notl %eax
1284 ; X64-NOBMI-NEXT: andl (%rdi), %eax
1285 ; X64-NOBMI-NEXT: retq
1287 ; X64-BMI1NOTBM-LABEL: bzhi32_b3_load_indexzext:
1288 ; X64-BMI1NOTBM: # %bb.0:
1289 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1290 ; X64-BMI1NOTBM-NEXT: bextrl %esi, (%rdi), %eax
1291 ; X64-BMI1NOTBM-NEXT: retq
1293 ; X64-BMI1BMI2-LABEL: bzhi32_b3_load_indexzext:
1294 ; X64-BMI1BMI2: # %bb.0:
1295 ; X64-BMI1BMI2-NEXT: bzhil %esi, (%rdi), %eax
1296 ; X64-BMI1BMI2-NEXT: retq
1297 %val = load i32, i32* %w
1298 %conv = zext i8 %numlowbits to i32
1299 %notmask = shl i32 -1, %conv
1300 %mask = xor i32 %notmask, -1
1301 %masked = and i32 %mask, %val
1305 define i32 @bzhi32_b4_commutative(i32 %val, i32 %numlowbits) nounwind {
1306 ; X86-NOBMI-LABEL: bzhi32_b4_commutative:
1307 ; X86-NOBMI: # %bb.0:
1308 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1309 ; X86-NOBMI-NEXT: movl $-1, %eax
1310 ; X86-NOBMI-NEXT: shll %cl, %eax
1311 ; X86-NOBMI-NEXT: notl %eax
1312 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
1313 ; X86-NOBMI-NEXT: retl
1315 ; X86-BMI1NOTBM-LABEL: bzhi32_b4_commutative:
1316 ; X86-BMI1NOTBM: # %bb.0:
1317 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
1318 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
1319 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
1320 ; X86-BMI1NOTBM-NEXT: retl
1322 ; X86-BMI1BMI2-LABEL: bzhi32_b4_commutative:
1323 ; X86-BMI1BMI2: # %bb.0:
1324 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
1325 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
1326 ; X86-BMI1BMI2-NEXT: retl
1328 ; X64-NOBMI-LABEL: bzhi32_b4_commutative:
1329 ; X64-NOBMI: # %bb.0:
1330 ; X64-NOBMI-NEXT: movl %esi, %ecx
1331 ; X64-NOBMI-NEXT: movl $-1, %eax
1332 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
1333 ; X64-NOBMI-NEXT: shll %cl, %eax
1334 ; X64-NOBMI-NEXT: notl %eax
1335 ; X64-NOBMI-NEXT: andl %edi, %eax
1336 ; X64-NOBMI-NEXT: retq
1338 ; X64-BMI1NOTBM-LABEL: bzhi32_b4_commutative:
1339 ; X64-BMI1NOTBM: # %bb.0:
1340 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1341 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
1342 ; X64-BMI1NOTBM-NEXT: retq
1344 ; X64-BMI1BMI2-LABEL: bzhi32_b4_commutative:
1345 ; X64-BMI1BMI2: # %bb.0:
1346 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
1347 ; X64-BMI1BMI2-NEXT: retq
1348 %notmask = shl i32 -1, %numlowbits
1349 %mask = xor i32 %notmask, -1
1350 %masked = and i32 %val, %mask ; swapped order
1356 define i64 @bzhi64_b0(i64 %val, i64 %numlowbits) nounwind {
1357 ; X86-NOBMI-LABEL: bzhi64_b0:
1358 ; X86-NOBMI: # %bb.0:
1359 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1360 ; X86-NOBMI-NEXT: movl $-1, %edx
1361 ; X86-NOBMI-NEXT: movl $-1, %eax
1362 ; X86-NOBMI-NEXT: shll %cl, %eax
1363 ; X86-NOBMI-NEXT: shldl %cl, %edx, %edx
1364 ; X86-NOBMI-NEXT: testb $32, %cl
1365 ; X86-NOBMI-NEXT: je .LBB20_2
1366 ; X86-NOBMI-NEXT: # %bb.1:
1367 ; X86-NOBMI-NEXT: movl %eax, %edx
1368 ; X86-NOBMI-NEXT: xorl %eax, %eax
1369 ; X86-NOBMI-NEXT: .LBB20_2:
1370 ; X86-NOBMI-NEXT: notl %edx
1371 ; X86-NOBMI-NEXT: notl %eax
1372 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %edx
1373 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
1374 ; X86-NOBMI-NEXT: retl
1376 ; X86-BMI1NOTBM-LABEL: bzhi64_b0:
1377 ; X86-BMI1NOTBM: # %bb.0:
1378 ; X86-BMI1NOTBM-NEXT: pushl %esi
1379 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
1380 ; X86-BMI1NOTBM-NEXT: movl $-1, %eax
1381 ; X86-BMI1NOTBM-NEXT: movl $-1, %esi
1382 ; X86-BMI1NOTBM-NEXT: shll %cl, %esi
1383 ; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %eax
1384 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
1385 ; X86-BMI1NOTBM-NEXT: je .LBB20_2
1386 ; X86-BMI1NOTBM-NEXT: # %bb.1:
1387 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
1388 ; X86-BMI1NOTBM-NEXT: xorl %esi, %esi
1389 ; X86-BMI1NOTBM-NEXT: .LBB20_2:
1390 ; X86-BMI1NOTBM-NEXT: andnl {{[0-9]+}}(%esp), %eax, %edx
1391 ; X86-BMI1NOTBM-NEXT: andnl {{[0-9]+}}(%esp), %esi, %eax
1392 ; X86-BMI1NOTBM-NEXT: popl %esi
1393 ; X86-BMI1NOTBM-NEXT: retl
1395 ; X86-BMI1BMI2-LABEL: bzhi64_b0:
1396 ; X86-BMI1BMI2: # %bb.0:
1397 ; X86-BMI1BMI2-NEXT: pushl %esi
1398 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
1399 ; X86-BMI1BMI2-NEXT: movl $-1, %eax
1400 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %esi
1401 ; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %eax
1402 ; X86-BMI1BMI2-NEXT: testb $32, %cl
1403 ; X86-BMI1BMI2-NEXT: je .LBB20_2
1404 ; X86-BMI1BMI2-NEXT: # %bb.1:
1405 ; X86-BMI1BMI2-NEXT: movl %esi, %eax
1406 ; X86-BMI1BMI2-NEXT: xorl %esi, %esi
1407 ; X86-BMI1BMI2-NEXT: .LBB20_2:
1408 ; X86-BMI1BMI2-NEXT: andnl {{[0-9]+}}(%esp), %eax, %edx
1409 ; X86-BMI1BMI2-NEXT: andnl {{[0-9]+}}(%esp), %esi, %eax
1410 ; X86-BMI1BMI2-NEXT: popl %esi
1411 ; X86-BMI1BMI2-NEXT: retl
1413 ; X64-NOBMI-LABEL: bzhi64_b0:
1414 ; X64-NOBMI: # %bb.0:
1415 ; X64-NOBMI-NEXT: movq %rsi, %rcx
1416 ; X64-NOBMI-NEXT: movq $-1, %rax
1417 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
1418 ; X64-NOBMI-NEXT: shlq %cl, %rax
1419 ; X64-NOBMI-NEXT: notq %rax
1420 ; X64-NOBMI-NEXT: andq %rdi, %rax
1421 ; X64-NOBMI-NEXT: retq
1423 ; X64-BMI1NOTBM-LABEL: bzhi64_b0:
1424 ; X64-BMI1NOTBM: # %bb.0:
1425 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1426 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, %rdi, %rax
1427 ; X64-BMI1NOTBM-NEXT: retq
1429 ; X64-BMI1BMI2-LABEL: bzhi64_b0:
1430 ; X64-BMI1BMI2: # %bb.0:
1431 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, %rdi, %rax
1432 ; X64-BMI1BMI2-NEXT: retq
1433 %notmask = shl i64 -1, %numlowbits
1434 %mask = xor i64 %notmask, -1
1435 %masked = and i64 %mask, %val
1439 define i64 @bzhi64_b1_indexzext(i64 %val, i8 zeroext %numlowbits) nounwind {
1440 ; X86-NOBMI-LABEL: bzhi64_b1_indexzext:
1441 ; X86-NOBMI: # %bb.0:
1442 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1443 ; X86-NOBMI-NEXT: movl $-1, %edx
1444 ; X86-NOBMI-NEXT: movl $-1, %eax
1445 ; X86-NOBMI-NEXT: shll %cl, %eax
1446 ; X86-NOBMI-NEXT: shldl %cl, %edx, %edx
1447 ; X86-NOBMI-NEXT: testb $32, %cl
1448 ; X86-NOBMI-NEXT: je .LBB21_2
1449 ; X86-NOBMI-NEXT: # %bb.1:
1450 ; X86-NOBMI-NEXT: movl %eax, %edx
1451 ; X86-NOBMI-NEXT: xorl %eax, %eax
1452 ; X86-NOBMI-NEXT: .LBB21_2:
1453 ; X86-NOBMI-NEXT: notl %edx
1454 ; X86-NOBMI-NEXT: notl %eax
1455 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %edx
1456 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
1457 ; X86-NOBMI-NEXT: retl
1459 ; X86-BMI1NOTBM-LABEL: bzhi64_b1_indexzext:
1460 ; X86-BMI1NOTBM: # %bb.0:
1461 ; X86-BMI1NOTBM-NEXT: pushl %esi
1462 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
1463 ; X86-BMI1NOTBM-NEXT: movl $-1, %eax
1464 ; X86-BMI1NOTBM-NEXT: movl $-1, %esi
1465 ; X86-BMI1NOTBM-NEXT: shll %cl, %esi
1466 ; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %eax
1467 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
1468 ; X86-BMI1NOTBM-NEXT: je .LBB21_2
1469 ; X86-BMI1NOTBM-NEXT: # %bb.1:
1470 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
1471 ; X86-BMI1NOTBM-NEXT: xorl %esi, %esi
1472 ; X86-BMI1NOTBM-NEXT: .LBB21_2:
1473 ; X86-BMI1NOTBM-NEXT: andnl {{[0-9]+}}(%esp), %eax, %edx
1474 ; X86-BMI1NOTBM-NEXT: andnl {{[0-9]+}}(%esp), %esi, %eax
1475 ; X86-BMI1NOTBM-NEXT: popl %esi
1476 ; X86-BMI1NOTBM-NEXT: retl
1478 ; X86-BMI1BMI2-LABEL: bzhi64_b1_indexzext:
1479 ; X86-BMI1BMI2: # %bb.0:
1480 ; X86-BMI1BMI2-NEXT: pushl %esi
1481 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
1482 ; X86-BMI1BMI2-NEXT: movl $-1, %eax
1483 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %esi
1484 ; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %eax
1485 ; X86-BMI1BMI2-NEXT: testb $32, %cl
1486 ; X86-BMI1BMI2-NEXT: je .LBB21_2
1487 ; X86-BMI1BMI2-NEXT: # %bb.1:
1488 ; X86-BMI1BMI2-NEXT: movl %esi, %eax
1489 ; X86-BMI1BMI2-NEXT: xorl %esi, %esi
1490 ; X86-BMI1BMI2-NEXT: .LBB21_2:
1491 ; X86-BMI1BMI2-NEXT: andnl {{[0-9]+}}(%esp), %eax, %edx
1492 ; X86-BMI1BMI2-NEXT: andnl {{[0-9]+}}(%esp), %esi, %eax
1493 ; X86-BMI1BMI2-NEXT: popl %esi
1494 ; X86-BMI1BMI2-NEXT: retl
1496 ; X64-NOBMI-LABEL: bzhi64_b1_indexzext:
1497 ; X64-NOBMI: # %bb.0:
1498 ; X64-NOBMI-NEXT: movl %esi, %ecx
1499 ; X64-NOBMI-NEXT: movq $-1, %rax
1500 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
1501 ; X64-NOBMI-NEXT: shlq %cl, %rax
1502 ; X64-NOBMI-NEXT: notq %rax
1503 ; X64-NOBMI-NEXT: andq %rdi, %rax
1504 ; X64-NOBMI-NEXT: retq
1506 ; X64-BMI1NOTBM-LABEL: bzhi64_b1_indexzext:
1507 ; X64-BMI1NOTBM: # %bb.0:
1508 ; X64-BMI1NOTBM-NEXT: # kill: def $esi killed $esi def $rsi
1509 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1510 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, %rdi, %rax
1511 ; X64-BMI1NOTBM-NEXT: retq
1513 ; X64-BMI1BMI2-LABEL: bzhi64_b1_indexzext:
1514 ; X64-BMI1BMI2: # %bb.0:
1515 ; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi
1516 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, %rdi, %rax
1517 ; X64-BMI1BMI2-NEXT: retq
1518 %conv = zext i8 %numlowbits to i64
1519 %notmask = shl i64 -1, %conv
1520 %mask = xor i64 %notmask, -1
1521 %masked = and i64 %mask, %val
1525 define i64 @bzhi64_b2_load(i64* %w, i64 %numlowbits) nounwind {
1526 ; X86-NOBMI-LABEL: bzhi64_b2_load:
1527 ; X86-NOBMI: # %bb.0:
1528 ; X86-NOBMI-NEXT: pushl %esi
1529 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi
1530 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1531 ; X86-NOBMI-NEXT: movl $-1, %edx
1532 ; X86-NOBMI-NEXT: movl $-1, %eax
1533 ; X86-NOBMI-NEXT: shll %cl, %eax
1534 ; X86-NOBMI-NEXT: shldl %cl, %edx, %edx
1535 ; X86-NOBMI-NEXT: testb $32, %cl
1536 ; X86-NOBMI-NEXT: je .LBB22_2
1537 ; X86-NOBMI-NEXT: # %bb.1:
1538 ; X86-NOBMI-NEXT: movl %eax, %edx
1539 ; X86-NOBMI-NEXT: xorl %eax, %eax
1540 ; X86-NOBMI-NEXT: .LBB22_2:
1541 ; X86-NOBMI-NEXT: notl %edx
1542 ; X86-NOBMI-NEXT: notl %eax
1543 ; X86-NOBMI-NEXT: andl 4(%esi), %edx
1544 ; X86-NOBMI-NEXT: andl (%esi), %eax
1545 ; X86-NOBMI-NEXT: popl %esi
1546 ; X86-NOBMI-NEXT: retl
1548 ; X86-BMI1NOTBM-LABEL: bzhi64_b2_load:
1549 ; X86-BMI1NOTBM: # %bb.0:
1550 ; X86-BMI1NOTBM-NEXT: pushl %esi
1551 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
1552 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
1553 ; X86-BMI1NOTBM-NEXT: movl $-1, %edx
1554 ; X86-BMI1NOTBM-NEXT: movl $-1, %esi
1555 ; X86-BMI1NOTBM-NEXT: shll %cl, %esi
1556 ; X86-BMI1NOTBM-NEXT: shldl %cl, %edx, %edx
1557 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
1558 ; X86-BMI1NOTBM-NEXT: je .LBB22_2
1559 ; X86-BMI1NOTBM-NEXT: # %bb.1:
1560 ; X86-BMI1NOTBM-NEXT: movl %esi, %edx
1561 ; X86-BMI1NOTBM-NEXT: xorl %esi, %esi
1562 ; X86-BMI1NOTBM-NEXT: .LBB22_2:
1563 ; X86-BMI1NOTBM-NEXT: andnl 4(%eax), %edx, %edx
1564 ; X86-BMI1NOTBM-NEXT: andnl (%eax), %esi, %eax
1565 ; X86-BMI1NOTBM-NEXT: popl %esi
1566 ; X86-BMI1NOTBM-NEXT: retl
1568 ; X86-BMI1BMI2-LABEL: bzhi64_b2_load:
1569 ; X86-BMI1BMI2: # %bb.0:
1570 ; X86-BMI1BMI2-NEXT: pushl %esi
1571 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
1572 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
1573 ; X86-BMI1BMI2-NEXT: movl $-1, %edx
1574 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %edx, %esi
1575 ; X86-BMI1BMI2-NEXT: shldl %cl, %edx, %edx
1576 ; X86-BMI1BMI2-NEXT: testb $32, %cl
1577 ; X86-BMI1BMI2-NEXT: je .LBB22_2
1578 ; X86-BMI1BMI2-NEXT: # %bb.1:
1579 ; X86-BMI1BMI2-NEXT: movl %esi, %edx
1580 ; X86-BMI1BMI2-NEXT: xorl %esi, %esi
1581 ; X86-BMI1BMI2-NEXT: .LBB22_2:
1582 ; X86-BMI1BMI2-NEXT: andnl 4(%eax), %edx, %edx
1583 ; X86-BMI1BMI2-NEXT: andnl (%eax), %esi, %eax
1584 ; X86-BMI1BMI2-NEXT: popl %esi
1585 ; X86-BMI1BMI2-NEXT: retl
1587 ; X64-NOBMI-LABEL: bzhi64_b2_load:
1588 ; X64-NOBMI: # %bb.0:
1589 ; X64-NOBMI-NEXT: movq %rsi, %rcx
1590 ; X64-NOBMI-NEXT: movq $-1, %rax
1591 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
1592 ; X64-NOBMI-NEXT: shlq %cl, %rax
1593 ; X64-NOBMI-NEXT: notq %rax
1594 ; X64-NOBMI-NEXT: andq (%rdi), %rax
1595 ; X64-NOBMI-NEXT: retq
1597 ; X64-BMI1NOTBM-LABEL: bzhi64_b2_load:
1598 ; X64-BMI1NOTBM: # %bb.0:
1599 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1600 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, (%rdi), %rax
1601 ; X64-BMI1NOTBM-NEXT: retq
1603 ; X64-BMI1BMI2-LABEL: bzhi64_b2_load:
1604 ; X64-BMI1BMI2: # %bb.0:
1605 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, (%rdi), %rax
1606 ; X64-BMI1BMI2-NEXT: retq
1607 %val = load i64, i64* %w
1608 %notmask = shl i64 -1, %numlowbits
1609 %mask = xor i64 %notmask, -1
1610 %masked = and i64 %mask, %val
1614 define i64 @bzhi64_b3_load_indexzext(i64* %w, i8 zeroext %numlowbits) nounwind {
1615 ; X86-NOBMI-LABEL: bzhi64_b3_load_indexzext:
1616 ; X86-NOBMI: # %bb.0:
1617 ; X86-NOBMI-NEXT: pushl %esi
1618 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi
1619 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1620 ; X86-NOBMI-NEXT: movl $-1, %edx
1621 ; X86-NOBMI-NEXT: movl $-1, %eax
1622 ; X86-NOBMI-NEXT: shll %cl, %eax
1623 ; X86-NOBMI-NEXT: shldl %cl, %edx, %edx
1624 ; X86-NOBMI-NEXT: testb $32, %cl
1625 ; X86-NOBMI-NEXT: je .LBB23_2
1626 ; X86-NOBMI-NEXT: # %bb.1:
1627 ; X86-NOBMI-NEXT: movl %eax, %edx
1628 ; X86-NOBMI-NEXT: xorl %eax, %eax
1629 ; X86-NOBMI-NEXT: .LBB23_2:
1630 ; X86-NOBMI-NEXT: notl %edx
1631 ; X86-NOBMI-NEXT: notl %eax
1632 ; X86-NOBMI-NEXT: andl 4(%esi), %edx
1633 ; X86-NOBMI-NEXT: andl (%esi), %eax
1634 ; X86-NOBMI-NEXT: popl %esi
1635 ; X86-NOBMI-NEXT: retl
1637 ; X86-BMI1NOTBM-LABEL: bzhi64_b3_load_indexzext:
1638 ; X86-BMI1NOTBM: # %bb.0:
1639 ; X86-BMI1NOTBM-NEXT: pushl %esi
1640 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
1641 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
1642 ; X86-BMI1NOTBM-NEXT: movl $-1, %edx
1643 ; X86-BMI1NOTBM-NEXT: movl $-1, %esi
1644 ; X86-BMI1NOTBM-NEXT: shll %cl, %esi
1645 ; X86-BMI1NOTBM-NEXT: shldl %cl, %edx, %edx
1646 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
1647 ; X86-BMI1NOTBM-NEXT: je .LBB23_2
1648 ; X86-BMI1NOTBM-NEXT: # %bb.1:
1649 ; X86-BMI1NOTBM-NEXT: movl %esi, %edx
1650 ; X86-BMI1NOTBM-NEXT: xorl %esi, %esi
1651 ; X86-BMI1NOTBM-NEXT: .LBB23_2:
1652 ; X86-BMI1NOTBM-NEXT: andnl 4(%eax), %edx, %edx
1653 ; X86-BMI1NOTBM-NEXT: andnl (%eax), %esi, %eax
1654 ; X86-BMI1NOTBM-NEXT: popl %esi
1655 ; X86-BMI1NOTBM-NEXT: retl
1657 ; X86-BMI1BMI2-LABEL: bzhi64_b3_load_indexzext:
1658 ; X86-BMI1BMI2: # %bb.0:
1659 ; X86-BMI1BMI2-NEXT: pushl %esi
1660 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
1661 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
1662 ; X86-BMI1BMI2-NEXT: movl $-1, %edx
1663 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %edx, %esi
1664 ; X86-BMI1BMI2-NEXT: shldl %cl, %edx, %edx
1665 ; X86-BMI1BMI2-NEXT: testb $32, %cl
1666 ; X86-BMI1BMI2-NEXT: je .LBB23_2
1667 ; X86-BMI1BMI2-NEXT: # %bb.1:
1668 ; X86-BMI1BMI2-NEXT: movl %esi, %edx
1669 ; X86-BMI1BMI2-NEXT: xorl %esi, %esi
1670 ; X86-BMI1BMI2-NEXT: .LBB23_2:
1671 ; X86-BMI1BMI2-NEXT: andnl 4(%eax), %edx, %edx
1672 ; X86-BMI1BMI2-NEXT: andnl (%eax), %esi, %eax
1673 ; X86-BMI1BMI2-NEXT: popl %esi
1674 ; X86-BMI1BMI2-NEXT: retl
1676 ; X64-NOBMI-LABEL: bzhi64_b3_load_indexzext:
1677 ; X64-NOBMI: # %bb.0:
1678 ; X64-NOBMI-NEXT: movl %esi, %ecx
1679 ; X64-NOBMI-NEXT: movq $-1, %rax
1680 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
1681 ; X64-NOBMI-NEXT: shlq %cl, %rax
1682 ; X64-NOBMI-NEXT: notq %rax
1683 ; X64-NOBMI-NEXT: andq (%rdi), %rax
1684 ; X64-NOBMI-NEXT: retq
1686 ; X64-BMI1NOTBM-LABEL: bzhi64_b3_load_indexzext:
1687 ; X64-BMI1NOTBM: # %bb.0:
1688 ; X64-BMI1NOTBM-NEXT: # kill: def $esi killed $esi def $rsi
1689 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1690 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, (%rdi), %rax
1691 ; X64-BMI1NOTBM-NEXT: retq
1693 ; X64-BMI1BMI2-LABEL: bzhi64_b3_load_indexzext:
1694 ; X64-BMI1BMI2: # %bb.0:
1695 ; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi
1696 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, (%rdi), %rax
1697 ; X64-BMI1BMI2-NEXT: retq
1698 %val = load i64, i64* %w
1699 %conv = zext i8 %numlowbits to i64
1700 %notmask = shl i64 -1, %conv
1701 %mask = xor i64 %notmask, -1
1702 %masked = and i64 %mask, %val
1706 define i64 @bzhi64_b4_commutative(i64 %val, i64 %numlowbits) nounwind {
1707 ; X86-NOBMI-LABEL: bzhi64_b4_commutative:
1708 ; X86-NOBMI: # %bb.0:
1709 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1710 ; X86-NOBMI-NEXT: movl $-1, %edx
1711 ; X86-NOBMI-NEXT: movl $-1, %eax
1712 ; X86-NOBMI-NEXT: shll %cl, %eax
1713 ; X86-NOBMI-NEXT: shldl %cl, %edx, %edx
1714 ; X86-NOBMI-NEXT: testb $32, %cl
1715 ; X86-NOBMI-NEXT: je .LBB24_2
1716 ; X86-NOBMI-NEXT: # %bb.1:
1717 ; X86-NOBMI-NEXT: movl %eax, %edx
1718 ; X86-NOBMI-NEXT: xorl %eax, %eax
1719 ; X86-NOBMI-NEXT: .LBB24_2:
1720 ; X86-NOBMI-NEXT: notl %edx
1721 ; X86-NOBMI-NEXT: notl %eax
1722 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %edx
1723 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
1724 ; X86-NOBMI-NEXT: retl
1726 ; X86-BMI1NOTBM-LABEL: bzhi64_b4_commutative:
1727 ; X86-BMI1NOTBM: # %bb.0:
1728 ; X86-BMI1NOTBM-NEXT: pushl %esi
1729 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
1730 ; X86-BMI1NOTBM-NEXT: movl $-1, %eax
1731 ; X86-BMI1NOTBM-NEXT: movl $-1, %esi
1732 ; X86-BMI1NOTBM-NEXT: shll %cl, %esi
1733 ; X86-BMI1NOTBM-NEXT: shldl %cl, %eax, %eax
1734 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
1735 ; X86-BMI1NOTBM-NEXT: je .LBB24_2
1736 ; X86-BMI1NOTBM-NEXT: # %bb.1:
1737 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
1738 ; X86-BMI1NOTBM-NEXT: xorl %esi, %esi
1739 ; X86-BMI1NOTBM-NEXT: .LBB24_2:
1740 ; X86-BMI1NOTBM-NEXT: andnl {{[0-9]+}}(%esp), %eax, %edx
1741 ; X86-BMI1NOTBM-NEXT: andnl {{[0-9]+}}(%esp), %esi, %eax
1742 ; X86-BMI1NOTBM-NEXT: popl %esi
1743 ; X86-BMI1NOTBM-NEXT: retl
1745 ; X86-BMI1BMI2-LABEL: bzhi64_b4_commutative:
1746 ; X86-BMI1BMI2: # %bb.0:
1747 ; X86-BMI1BMI2-NEXT: pushl %esi
1748 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
1749 ; X86-BMI1BMI2-NEXT: movl $-1, %eax
1750 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %esi
1751 ; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %eax
1752 ; X86-BMI1BMI2-NEXT: testb $32, %cl
1753 ; X86-BMI1BMI2-NEXT: je .LBB24_2
1754 ; X86-BMI1BMI2-NEXT: # %bb.1:
1755 ; X86-BMI1BMI2-NEXT: movl %esi, %eax
1756 ; X86-BMI1BMI2-NEXT: xorl %esi, %esi
1757 ; X86-BMI1BMI2-NEXT: .LBB24_2:
1758 ; X86-BMI1BMI2-NEXT: andnl {{[0-9]+}}(%esp), %eax, %edx
1759 ; X86-BMI1BMI2-NEXT: andnl {{[0-9]+}}(%esp), %esi, %eax
1760 ; X86-BMI1BMI2-NEXT: popl %esi
1761 ; X86-BMI1BMI2-NEXT: retl
1763 ; X64-NOBMI-LABEL: bzhi64_b4_commutative:
1764 ; X64-NOBMI: # %bb.0:
1765 ; X64-NOBMI-NEXT: movq %rsi, %rcx
1766 ; X64-NOBMI-NEXT: movq $-1, %rax
1767 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
1768 ; X64-NOBMI-NEXT: shlq %cl, %rax
1769 ; X64-NOBMI-NEXT: notq %rax
1770 ; X64-NOBMI-NEXT: andq %rdi, %rax
1771 ; X64-NOBMI-NEXT: retq
1773 ; X64-BMI1NOTBM-LABEL: bzhi64_b4_commutative:
1774 ; X64-BMI1NOTBM: # %bb.0:
1775 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1776 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, %rdi, %rax
1777 ; X64-BMI1NOTBM-NEXT: retq
1779 ; X64-BMI1BMI2-LABEL: bzhi64_b4_commutative:
1780 ; X64-BMI1BMI2: # %bb.0:
1781 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, %rdi, %rax
1782 ; X64-BMI1BMI2-NEXT: retq
1783 %notmask = shl i64 -1, %numlowbits
1784 %mask = xor i64 %notmask, -1
1785 %masked = and i64 %val, %mask ; swapped order
1789 ; 64-bit, but with 32-bit output
1791 ; Everything done in 64-bit, truncation happens last.
1792 define i32 @bzhi64_32_b0(i64 %val, i8 %numlowbits) nounwind {
1793 ; X86-NOBMI-LABEL: bzhi64_32_b0:
1794 ; X86-NOBMI: # %bb.0:
1795 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1796 ; X86-NOBMI-NEXT: movl $-1, %edx
1797 ; X86-NOBMI-NEXT: shll %cl, %edx
1798 ; X86-NOBMI-NEXT: xorl %eax, %eax
1799 ; X86-NOBMI-NEXT: testb $32, %cl
1800 ; X86-NOBMI-NEXT: jne .LBB25_2
1801 ; X86-NOBMI-NEXT: # %bb.1:
1802 ; X86-NOBMI-NEXT: movl %edx, %eax
1803 ; X86-NOBMI-NEXT: .LBB25_2:
1804 ; X86-NOBMI-NEXT: notl %eax
1805 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
1806 ; X86-NOBMI-NEXT: retl
1808 ; X86-BMI1NOTBM-LABEL: bzhi64_32_b0:
1809 ; X86-BMI1NOTBM: # %bb.0:
1810 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
1811 ; X86-BMI1NOTBM-NEXT: movl $-1, %eax
1812 ; X86-BMI1NOTBM-NEXT: shll %cl, %eax
1813 ; X86-BMI1NOTBM-NEXT: xorl %edx, %edx
1814 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
1815 ; X86-BMI1NOTBM-NEXT: jne .LBB25_2
1816 ; X86-BMI1NOTBM-NEXT: # %bb.1:
1817 ; X86-BMI1NOTBM-NEXT: movl %eax, %edx
1818 ; X86-BMI1NOTBM-NEXT: .LBB25_2:
1819 ; X86-BMI1NOTBM-NEXT: andnl {{[0-9]+}}(%esp), %edx, %eax
1820 ; X86-BMI1NOTBM-NEXT: retl
1822 ; X86-BMI1BMI2-LABEL: bzhi64_32_b0:
1823 ; X86-BMI1BMI2: # %bb.0:
1824 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
1825 ; X86-BMI1BMI2-NEXT: xorl %ecx, %ecx
1826 ; X86-BMI1BMI2-NEXT: testb $32, %al
1827 ; X86-BMI1BMI2-NEXT: jne .LBB25_2
1828 ; X86-BMI1BMI2-NEXT: # %bb.1:
1829 ; X86-BMI1BMI2-NEXT: movl $-1, %ecx
1830 ; X86-BMI1BMI2-NEXT: shlxl %eax, %ecx, %ecx
1831 ; X86-BMI1BMI2-NEXT: .LBB25_2:
1832 ; X86-BMI1BMI2-NEXT: andnl {{[0-9]+}}(%esp), %ecx, %eax
1833 ; X86-BMI1BMI2-NEXT: retl
1835 ; X64-NOBMI-LABEL: bzhi64_32_b0:
1836 ; X64-NOBMI: # %bb.0:
1837 ; X64-NOBMI-NEXT: movl %esi, %ecx
1838 ; X64-NOBMI-NEXT: movq $-1, %rax
1839 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
1840 ; X64-NOBMI-NEXT: shlq %cl, %rax
1841 ; X64-NOBMI-NEXT: notl %eax
1842 ; X64-NOBMI-NEXT: andl %edi, %eax
1843 ; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax
1844 ; X64-NOBMI-NEXT: retq
1846 ; X64-BMI1NOTBM-LABEL: bzhi64_32_b0:
1847 ; X64-BMI1NOTBM: # %bb.0:
1848 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1849 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
1850 ; X64-BMI1NOTBM-NEXT: retq
1852 ; X64-BMI1BMI2-LABEL: bzhi64_32_b0:
1853 ; X64-BMI1BMI2: # %bb.0:
1854 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
1855 ; X64-BMI1BMI2-NEXT: retq
1856 %widenumlowbits = zext i8 %numlowbits to i64
1857 %notmask = shl nsw i64 -1, %widenumlowbits
1858 %mask = xor i64 %notmask, -1
1859 %wideres = and i64 %val, %mask
1860 %res = trunc i64 %wideres to i32
1864 ; Shifting happens in 64-bit, then truncation. Masking is 32-bit.
1865 define i32 @bzhi64_32_b1(i64 %val, i8 %numlowbits) nounwind {
1866 ; X86-NOBMI-LABEL: bzhi64_32_b1:
1867 ; X86-NOBMI: # %bb.0:
1868 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1869 ; X86-NOBMI-NEXT: movl $-1, %eax
1870 ; X86-NOBMI-NEXT: shll %cl, %eax
1871 ; X86-NOBMI-NEXT: notl %eax
1872 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
1873 ; X86-NOBMI-NEXT: retl
1875 ; X86-BMI1NOTBM-LABEL: bzhi64_32_b1:
1876 ; X86-BMI1NOTBM: # %bb.0:
1877 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
1878 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
1879 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
1880 ; X86-BMI1NOTBM-NEXT: retl
1882 ; X86-BMI1BMI2-LABEL: bzhi64_32_b1:
1883 ; X86-BMI1BMI2: # %bb.0:
1884 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
1885 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
1886 ; X86-BMI1BMI2-NEXT: retl
1888 ; X64-NOBMI-LABEL: bzhi64_32_b1:
1889 ; X64-NOBMI: # %bb.0:
1890 ; X64-NOBMI-NEXT: movl %esi, %ecx
1891 ; X64-NOBMI-NEXT: movl $-1, %eax
1892 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
1893 ; X64-NOBMI-NEXT: shll %cl, %eax
1894 ; X64-NOBMI-NEXT: notl %eax
1895 ; X64-NOBMI-NEXT: andl %edi, %eax
1896 ; X64-NOBMI-NEXT: retq
1898 ; X64-BMI1NOTBM-LABEL: bzhi64_32_b1:
1899 ; X64-BMI1NOTBM: # %bb.0:
1900 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1901 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
1902 ; X64-BMI1NOTBM-NEXT: retq
1904 ; X64-BMI1BMI2-LABEL: bzhi64_32_b1:
1905 ; X64-BMI1BMI2: # %bb.0:
1906 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
1907 ; X64-BMI1BMI2-NEXT: retq
1908 %truncval = trunc i64 %val to i32
1909 %widenumlowbits = zext i8 %numlowbits to i32
1910 %notmask = shl nsw i32 -1, %widenumlowbits
1911 %mask = xor i32 %notmask, -1
1912 %res = and i32 %truncval, %mask
1916 ; Shifting happens in 64-bit. Mask is 32-bit, but extended to 64-bit.
1917 ; Masking is 64-bit. Then truncation.
1918 define i32 @bzhi64_32_b2(i64 %val, i8 %numlowbits) nounwind {
1919 ; X86-NOBMI-LABEL: bzhi64_32_b2:
1920 ; X86-NOBMI: # %bb.0:
1921 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1922 ; X86-NOBMI-NEXT: movl $-1, %eax
1923 ; X86-NOBMI-NEXT: shll %cl, %eax
1924 ; X86-NOBMI-NEXT: notl %eax
1925 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
1926 ; X86-NOBMI-NEXT: retl
1928 ; X86-BMI1NOTBM-LABEL: bzhi64_32_b2:
1929 ; X86-BMI1NOTBM: # %bb.0:
1930 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
1931 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
1932 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
1933 ; X86-BMI1NOTBM-NEXT: retl
1935 ; X86-BMI1BMI2-LABEL: bzhi64_32_b2:
1936 ; X86-BMI1BMI2: # %bb.0:
1937 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
1938 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
1939 ; X86-BMI1BMI2-NEXT: retl
1941 ; X64-NOBMI-LABEL: bzhi64_32_b2:
1942 ; X64-NOBMI: # %bb.0:
1943 ; X64-NOBMI-NEXT: movl %esi, %ecx
1944 ; X64-NOBMI-NEXT: movl $-1, %eax
1945 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
1946 ; X64-NOBMI-NEXT: shll %cl, %eax
1947 ; X64-NOBMI-NEXT: notl %eax
1948 ; X64-NOBMI-NEXT: andl %edi, %eax
1949 ; X64-NOBMI-NEXT: retq
1951 ; X64-BMI1NOTBM-LABEL: bzhi64_32_b2:
1952 ; X64-BMI1NOTBM: # %bb.0:
1953 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
1954 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
1955 ; X64-BMI1NOTBM-NEXT: retq
1957 ; X64-BMI1BMI2-LABEL: bzhi64_32_b2:
1958 ; X64-BMI1BMI2: # %bb.0:
1959 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
1960 ; X64-BMI1BMI2-NEXT: retq
1961 %widenumlowbits = zext i8 %numlowbits to i32
1962 %notmask = shl nsw i32 -1, %widenumlowbits
1963 %mask = xor i32 %notmask, -1
1964 %zextmask = zext i32 %mask to i64
1965 %wideres = and i64 %val, %zextmask
1966 %res = trunc i64 %wideres to i32
1970 ; Shifting happens in 64-bit. Mask is 32-bit, but calculated in 64-bit.
1971 ; Masking is 64-bit. Then truncation.
1972 define i32 @bzhi64_32_b3(i64 %val, i8 %numlowbits) nounwind {
1973 ; X86-NOBMI-LABEL: bzhi64_32_b3:
1974 ; X86-NOBMI: # %bb.0:
1975 ; X86-NOBMI-NEXT: movb {{[0-9]+}}(%esp), %cl
1976 ; X86-NOBMI-NEXT: movl $-1, %edx
1977 ; X86-NOBMI-NEXT: shll %cl, %edx
1978 ; X86-NOBMI-NEXT: xorl %eax, %eax
1979 ; X86-NOBMI-NEXT: testb $32, %cl
1980 ; X86-NOBMI-NEXT: jne .LBB28_2
1981 ; X86-NOBMI-NEXT: # %bb.1:
1982 ; X86-NOBMI-NEXT: movl %edx, %eax
1983 ; X86-NOBMI-NEXT: .LBB28_2:
1984 ; X86-NOBMI-NEXT: notl %eax
1985 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
1986 ; X86-NOBMI-NEXT: retl
1988 ; X86-BMI1NOTBM-LABEL: bzhi64_32_b3:
1989 ; X86-BMI1NOTBM: # %bb.0:
1990 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
1991 ; X86-BMI1NOTBM-NEXT: movl $-1, %eax
1992 ; X86-BMI1NOTBM-NEXT: shll %cl, %eax
1993 ; X86-BMI1NOTBM-NEXT: xorl %edx, %edx
1994 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
1995 ; X86-BMI1NOTBM-NEXT: jne .LBB28_2
1996 ; X86-BMI1NOTBM-NEXT: # %bb.1:
1997 ; X86-BMI1NOTBM-NEXT: movl %eax, %edx
1998 ; X86-BMI1NOTBM-NEXT: .LBB28_2:
1999 ; X86-BMI1NOTBM-NEXT: andnl {{[0-9]+}}(%esp), %edx, %eax
2000 ; X86-BMI1NOTBM-NEXT: retl
2002 ; X86-BMI1BMI2-LABEL: bzhi64_32_b3:
2003 ; X86-BMI1BMI2: # %bb.0:
2004 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
2005 ; X86-BMI1BMI2-NEXT: xorl %ecx, %ecx
2006 ; X86-BMI1BMI2-NEXT: testb $32, %al
2007 ; X86-BMI1BMI2-NEXT: jne .LBB28_2
2008 ; X86-BMI1BMI2-NEXT: # %bb.1:
2009 ; X86-BMI1BMI2-NEXT: movl $-1, %ecx
2010 ; X86-BMI1BMI2-NEXT: shlxl %eax, %ecx, %ecx
2011 ; X86-BMI1BMI2-NEXT: .LBB28_2:
2012 ; X86-BMI1BMI2-NEXT: andnl {{[0-9]+}}(%esp), %ecx, %eax
2013 ; X86-BMI1BMI2-NEXT: retl
2015 ; X64-NOBMI-LABEL: bzhi64_32_b3:
2016 ; X64-NOBMI: # %bb.0:
2017 ; X64-NOBMI-NEXT: movl %esi, %ecx
2018 ; X64-NOBMI-NEXT: movl $4294967295, %eax # imm = 0xFFFFFFFF
2019 ; X64-NOBMI-NEXT: movl $4294967295, %edx # imm = 0xFFFFFFFF
2020 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
2021 ; X64-NOBMI-NEXT: shlq %cl, %rdx
2022 ; X64-NOBMI-NEXT: xorl %edx, %eax
2023 ; X64-NOBMI-NEXT: andl %edi, %eax
2024 ; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax
2025 ; X64-NOBMI-NEXT: retq
2027 ; X64-BMI1NOTBM-LABEL: bzhi64_32_b3:
2028 ; X64-BMI1NOTBM: # %bb.0:
2029 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
2030 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
2031 ; X64-BMI1NOTBM-NEXT: retq
2033 ; X64-BMI1BMI2-LABEL: bzhi64_32_b3:
2034 ; X64-BMI1BMI2: # %bb.0:
2035 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
2036 ; X64-BMI1BMI2-NEXT: retq
2037 %widenumlowbits = zext i8 %numlowbits to i64
2038 %notmask = shl nsw i64 4294967295, %widenumlowbits
2039 %mask = xor i64 %notmask, 4294967295
2040 %wideres = and i64 %val, %mask
2041 %res = trunc i64 %wideres to i32
2045 ; ---------------------------------------------------------------------------- ;
2047 ; ---------------------------------------------------------------------------- ;
2049 declare void @use32(i32)
2051 define i32 @bzhi32_c0(i32 %val, i32 %numlowbits) nounwind {
2052 ; X86-NOBMI-LABEL: bzhi32_c0:
2053 ; X86-NOBMI: # %bb.0:
2054 ; X86-NOBMI-NEXT: pushl %esi
2055 ; X86-NOBMI-NEXT: subl $8, %esp
2056 ; X86-NOBMI-NEXT: xorl %ecx, %ecx
2057 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
2058 ; X86-NOBMI-NEXT: movl $-1, %esi
2059 ; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
2060 ; X86-NOBMI-NEXT: shrl %cl, %esi
2061 ; X86-NOBMI-NEXT: movl %esi, (%esp)
2062 ; X86-NOBMI-NEXT: calll use32
2063 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %esi
2064 ; X86-NOBMI-NEXT: movl %esi, %eax
2065 ; X86-NOBMI-NEXT: addl $8, %esp
2066 ; X86-NOBMI-NEXT: popl %esi
2067 ; X86-NOBMI-NEXT: retl
2069 ; X86-BMI1NOTBM-LABEL: bzhi32_c0:
2070 ; X86-BMI1NOTBM: # %bb.0:
2071 ; X86-BMI1NOTBM-NEXT: pushl %esi
2072 ; X86-BMI1NOTBM-NEXT: subl $8, %esp
2073 ; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx
2074 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
2075 ; X86-BMI1NOTBM-NEXT: movl $-1, %esi
2076 ; X86-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx
2077 ; X86-BMI1NOTBM-NEXT: shrl %cl, %esi
2078 ; X86-BMI1NOTBM-NEXT: movl %esi, (%esp)
2079 ; X86-BMI1NOTBM-NEXT: calll use32
2080 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %esi
2081 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
2082 ; X86-BMI1NOTBM-NEXT: addl $8, %esp
2083 ; X86-BMI1NOTBM-NEXT: popl %esi
2084 ; X86-BMI1NOTBM-NEXT: retl
2086 ; X86-BMI1BMI2-LABEL: bzhi32_c0:
2087 ; X86-BMI1BMI2: # %bb.0:
2088 ; X86-BMI1BMI2-NEXT: pushl %ebx
2089 ; X86-BMI1BMI2-NEXT: subl $8, %esp
2090 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl
2091 ; X86-BMI1BMI2-NEXT: movl %ebx, %eax
2092 ; X86-BMI1BMI2-NEXT: negb %al
2093 ; X86-BMI1BMI2-NEXT: movl $-1, %ecx
2094 ; X86-BMI1BMI2-NEXT: shrxl %eax, %ecx, %eax
2095 ; X86-BMI1BMI2-NEXT: movl %eax, (%esp)
2096 ; X86-BMI1BMI2-NEXT: calll use32
2097 ; X86-BMI1BMI2-NEXT: bzhil %ebx, {{[0-9]+}}(%esp), %eax
2098 ; X86-BMI1BMI2-NEXT: addl $8, %esp
2099 ; X86-BMI1BMI2-NEXT: popl %ebx
2100 ; X86-BMI1BMI2-NEXT: retl
2102 ; X64-NOBMI-LABEL: bzhi32_c0:
2103 ; X64-NOBMI: # %bb.0:
2104 ; X64-NOBMI-NEXT: pushq %rbp
2105 ; X64-NOBMI-NEXT: pushq %rbx
2106 ; X64-NOBMI-NEXT: pushq %rax
2107 ; X64-NOBMI-NEXT: movl %esi, %ecx
2108 ; X64-NOBMI-NEXT: movl %edi, %ebx
2109 ; X64-NOBMI-NEXT: negb %cl
2110 ; X64-NOBMI-NEXT: movl $-1, %ebp
2111 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
2112 ; X64-NOBMI-NEXT: shrl %cl, %ebp
2113 ; X64-NOBMI-NEXT: movl %ebp, %edi
2114 ; X64-NOBMI-NEXT: callq use32
2115 ; X64-NOBMI-NEXT: andl %ebx, %ebp
2116 ; X64-NOBMI-NEXT: movl %ebp, %eax
2117 ; X64-NOBMI-NEXT: addq $8, %rsp
2118 ; X64-NOBMI-NEXT: popq %rbx
2119 ; X64-NOBMI-NEXT: popq %rbp
2120 ; X64-NOBMI-NEXT: retq
2122 ; X64-BMI1NOTBM-LABEL: bzhi32_c0:
2123 ; X64-BMI1NOTBM: # %bb.0:
2124 ; X64-BMI1NOTBM-NEXT: pushq %rbp
2125 ; X64-BMI1NOTBM-NEXT: pushq %rbx
2126 ; X64-BMI1NOTBM-NEXT: pushq %rax
2127 ; X64-BMI1NOTBM-NEXT: movl %esi, %ecx
2128 ; X64-BMI1NOTBM-NEXT: movl %edi, %ebx
2129 ; X64-BMI1NOTBM-NEXT: negb %cl
2130 ; X64-BMI1NOTBM-NEXT: movl $-1, %ebp
2131 ; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx
2132 ; X64-BMI1NOTBM-NEXT: shrl %cl, %ebp
2133 ; X64-BMI1NOTBM-NEXT: movl %ebp, %edi
2134 ; X64-BMI1NOTBM-NEXT: callq use32
2135 ; X64-BMI1NOTBM-NEXT: andl %ebx, %ebp
2136 ; X64-BMI1NOTBM-NEXT: movl %ebp, %eax
2137 ; X64-BMI1NOTBM-NEXT: addq $8, %rsp
2138 ; X64-BMI1NOTBM-NEXT: popq %rbx
2139 ; X64-BMI1NOTBM-NEXT: popq %rbp
2140 ; X64-BMI1NOTBM-NEXT: retq
2142 ; X64-BMI1BMI2-LABEL: bzhi32_c0:
2143 ; X64-BMI1BMI2: # %bb.0:
2144 ; X64-BMI1BMI2-NEXT: pushq %rbp
2145 ; X64-BMI1BMI2-NEXT: pushq %rbx
2146 ; X64-BMI1BMI2-NEXT: pushq %rax
2147 ; X64-BMI1BMI2-NEXT: movl %esi, %ebx
2148 ; X64-BMI1BMI2-NEXT: movl %edi, %ebp
2149 ; X64-BMI1BMI2-NEXT: movl %ebx, %eax
2150 ; X64-BMI1BMI2-NEXT: negb %al
2151 ; X64-BMI1BMI2-NEXT: movl $-1, %ecx
2152 ; X64-BMI1BMI2-NEXT: shrxl %eax, %ecx, %edi
2153 ; X64-BMI1BMI2-NEXT: callq use32
2154 ; X64-BMI1BMI2-NEXT: bzhil %ebx, %ebp, %eax
2155 ; X64-BMI1BMI2-NEXT: addq $8, %rsp
2156 ; X64-BMI1BMI2-NEXT: popq %rbx
2157 ; X64-BMI1BMI2-NEXT: popq %rbp
2158 ; X64-BMI1BMI2-NEXT: retq
2159 %numhighbits = sub i32 32, %numlowbits
2160 %mask = lshr i32 -1, %numhighbits
2161 call void @use32(i32 %mask)
2162 %masked = and i32 %mask, %val
2166 define i32 @bzhi32_c1_indexzext(i32 %val, i8 %numlowbits) nounwind {
2167 ; X86-NOBMI-LABEL: bzhi32_c1_indexzext:
2168 ; X86-NOBMI: # %bb.0:
2169 ; X86-NOBMI-NEXT: pushl %esi
2170 ; X86-NOBMI-NEXT: subl $8, %esp
2171 ; X86-NOBMI-NEXT: xorl %ecx, %ecx
2172 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
2173 ; X86-NOBMI-NEXT: movl $-1, %esi
2174 ; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
2175 ; X86-NOBMI-NEXT: shrl %cl, %esi
2176 ; X86-NOBMI-NEXT: movl %esi, (%esp)
2177 ; X86-NOBMI-NEXT: calll use32
2178 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %esi
2179 ; X86-NOBMI-NEXT: movl %esi, %eax
2180 ; X86-NOBMI-NEXT: addl $8, %esp
2181 ; X86-NOBMI-NEXT: popl %esi
2182 ; X86-NOBMI-NEXT: retl
2184 ; X86-BMI1NOTBM-LABEL: bzhi32_c1_indexzext:
2185 ; X86-BMI1NOTBM: # %bb.0:
2186 ; X86-BMI1NOTBM-NEXT: pushl %esi
2187 ; X86-BMI1NOTBM-NEXT: subl $8, %esp
2188 ; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx
2189 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
2190 ; X86-BMI1NOTBM-NEXT: movl $-1, %esi
2191 ; X86-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx
2192 ; X86-BMI1NOTBM-NEXT: shrl %cl, %esi
2193 ; X86-BMI1NOTBM-NEXT: movl %esi, (%esp)
2194 ; X86-BMI1NOTBM-NEXT: calll use32
2195 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %esi
2196 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
2197 ; X86-BMI1NOTBM-NEXT: addl $8, %esp
2198 ; X86-BMI1NOTBM-NEXT: popl %esi
2199 ; X86-BMI1NOTBM-NEXT: retl
2201 ; X86-BMI1BMI2-LABEL: bzhi32_c1_indexzext:
2202 ; X86-BMI1BMI2: # %bb.0:
2203 ; X86-BMI1BMI2-NEXT: pushl %ebx
2204 ; X86-BMI1BMI2-NEXT: subl $8, %esp
2205 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl
2206 ; X86-BMI1BMI2-NEXT: movl %ebx, %eax
2207 ; X86-BMI1BMI2-NEXT: negb %al
2208 ; X86-BMI1BMI2-NEXT: movl $-1, %ecx
2209 ; X86-BMI1BMI2-NEXT: shrxl %eax, %ecx, %eax
2210 ; X86-BMI1BMI2-NEXT: movl %eax, (%esp)
2211 ; X86-BMI1BMI2-NEXT: calll use32
2212 ; X86-BMI1BMI2-NEXT: bzhil %ebx, {{[0-9]+}}(%esp), %eax
2213 ; X86-BMI1BMI2-NEXT: addl $8, %esp
2214 ; X86-BMI1BMI2-NEXT: popl %ebx
2215 ; X86-BMI1BMI2-NEXT: retl
2217 ; X64-NOBMI-LABEL: bzhi32_c1_indexzext:
2218 ; X64-NOBMI: # %bb.0:
2219 ; X64-NOBMI-NEXT: pushq %rbp
2220 ; X64-NOBMI-NEXT: pushq %rbx
2221 ; X64-NOBMI-NEXT: pushq %rax
2222 ; X64-NOBMI-NEXT: movl %esi, %ecx
2223 ; X64-NOBMI-NEXT: movl %edi, %ebx
2224 ; X64-NOBMI-NEXT: negb %cl
2225 ; X64-NOBMI-NEXT: movl $-1, %ebp
2226 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
2227 ; X64-NOBMI-NEXT: shrl %cl, %ebp
2228 ; X64-NOBMI-NEXT: movl %ebp, %edi
2229 ; X64-NOBMI-NEXT: callq use32
2230 ; X64-NOBMI-NEXT: andl %ebx, %ebp
2231 ; X64-NOBMI-NEXT: movl %ebp, %eax
2232 ; X64-NOBMI-NEXT: addq $8, %rsp
2233 ; X64-NOBMI-NEXT: popq %rbx
2234 ; X64-NOBMI-NEXT: popq %rbp
2235 ; X64-NOBMI-NEXT: retq
2237 ; X64-BMI1NOTBM-LABEL: bzhi32_c1_indexzext:
2238 ; X64-BMI1NOTBM: # %bb.0:
2239 ; X64-BMI1NOTBM-NEXT: pushq %rbp
2240 ; X64-BMI1NOTBM-NEXT: pushq %rbx
2241 ; X64-BMI1NOTBM-NEXT: pushq %rax
2242 ; X64-BMI1NOTBM-NEXT: movl %esi, %ecx
2243 ; X64-BMI1NOTBM-NEXT: movl %edi, %ebx
2244 ; X64-BMI1NOTBM-NEXT: negb %cl
2245 ; X64-BMI1NOTBM-NEXT: movl $-1, %ebp
2246 ; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx
2247 ; X64-BMI1NOTBM-NEXT: shrl %cl, %ebp
2248 ; X64-BMI1NOTBM-NEXT: movl %ebp, %edi
2249 ; X64-BMI1NOTBM-NEXT: callq use32
2250 ; X64-BMI1NOTBM-NEXT: andl %ebx, %ebp
2251 ; X64-BMI1NOTBM-NEXT: movl %ebp, %eax
2252 ; X64-BMI1NOTBM-NEXT: addq $8, %rsp
2253 ; X64-BMI1NOTBM-NEXT: popq %rbx
2254 ; X64-BMI1NOTBM-NEXT: popq %rbp
2255 ; X64-BMI1NOTBM-NEXT: retq
2257 ; X64-BMI1BMI2-LABEL: bzhi32_c1_indexzext:
2258 ; X64-BMI1BMI2: # %bb.0:
2259 ; X64-BMI1BMI2-NEXT: pushq %rbp
2260 ; X64-BMI1BMI2-NEXT: pushq %rbx
2261 ; X64-BMI1BMI2-NEXT: pushq %rax
2262 ; X64-BMI1BMI2-NEXT: movl %esi, %ebx
2263 ; X64-BMI1BMI2-NEXT: movl %edi, %ebp
2264 ; X64-BMI1BMI2-NEXT: movl %ebx, %eax
2265 ; X64-BMI1BMI2-NEXT: negb %al
2266 ; X64-BMI1BMI2-NEXT: movl $-1, %ecx
2267 ; X64-BMI1BMI2-NEXT: shrxl %eax, %ecx, %edi
2268 ; X64-BMI1BMI2-NEXT: callq use32
2269 ; X64-BMI1BMI2-NEXT: bzhil %ebx, %ebp, %eax
2270 ; X64-BMI1BMI2-NEXT: addq $8, %rsp
2271 ; X64-BMI1BMI2-NEXT: popq %rbx
2272 ; X64-BMI1BMI2-NEXT: popq %rbp
2273 ; X64-BMI1BMI2-NEXT: retq
2274 %numhighbits = sub i8 32, %numlowbits
2275 %sh_prom = zext i8 %numhighbits to i32
2276 %mask = lshr i32 -1, %sh_prom
2277 call void @use32(i32 %mask)
2278 %masked = and i32 %mask, %val
2282 define i32 @bzhi32_c2_load(i32* %w, i32 %numlowbits) nounwind {
2283 ; X86-NOBMI-LABEL: bzhi32_c2_load:
2284 ; X86-NOBMI: # %bb.0:
2285 ; X86-NOBMI-NEXT: pushl %esi
2286 ; X86-NOBMI-NEXT: subl $8, %esp
2287 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
2288 ; X86-NOBMI-NEXT: xorl %ecx, %ecx
2289 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
2290 ; X86-NOBMI-NEXT: movl $-1, %edx
2291 ; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
2292 ; X86-NOBMI-NEXT: shrl %cl, %edx
2293 ; X86-NOBMI-NEXT: movl (%eax), %esi
2294 ; X86-NOBMI-NEXT: andl %edx, %esi
2295 ; X86-NOBMI-NEXT: movl %edx, (%esp)
2296 ; X86-NOBMI-NEXT: calll use32
2297 ; X86-NOBMI-NEXT: movl %esi, %eax
2298 ; X86-NOBMI-NEXT: addl $8, %esp
2299 ; X86-NOBMI-NEXT: popl %esi
2300 ; X86-NOBMI-NEXT: retl
2302 ; X86-BMI1NOTBM-LABEL: bzhi32_c2_load:
2303 ; X86-BMI1NOTBM: # %bb.0:
2304 ; X86-BMI1NOTBM-NEXT: pushl %esi
2305 ; X86-BMI1NOTBM-NEXT: subl $8, %esp
2306 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
2307 ; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx
2308 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
2309 ; X86-BMI1NOTBM-NEXT: movl $-1, %edx
2310 ; X86-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx
2311 ; X86-BMI1NOTBM-NEXT: shrl %cl, %edx
2312 ; X86-BMI1NOTBM-NEXT: movl (%eax), %esi
2313 ; X86-BMI1NOTBM-NEXT: andl %edx, %esi
2314 ; X86-BMI1NOTBM-NEXT: movl %edx, (%esp)
2315 ; X86-BMI1NOTBM-NEXT: calll use32
2316 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
2317 ; X86-BMI1NOTBM-NEXT: addl $8, %esp
2318 ; X86-BMI1NOTBM-NEXT: popl %esi
2319 ; X86-BMI1NOTBM-NEXT: retl
2321 ; X86-BMI1BMI2-LABEL: bzhi32_c2_load:
2322 ; X86-BMI1BMI2: # %bb.0:
2323 ; X86-BMI1BMI2-NEXT: pushl %esi
2324 ; X86-BMI1BMI2-NEXT: subl $8, %esp
2325 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
2326 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
2327 ; X86-BMI1BMI2-NEXT: bzhil %ecx, (%eax), %esi
2328 ; X86-BMI1BMI2-NEXT: # kill: def $cl killed $cl killed $ecx def $ecx
2329 ; X86-BMI1BMI2-NEXT: negb %cl
2330 ; X86-BMI1BMI2-NEXT: movl $-1, %eax
2331 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %eax
2332 ; X86-BMI1BMI2-NEXT: movl %eax, (%esp)
2333 ; X86-BMI1BMI2-NEXT: calll use32
2334 ; X86-BMI1BMI2-NEXT: movl %esi, %eax
2335 ; X86-BMI1BMI2-NEXT: addl $8, %esp
2336 ; X86-BMI1BMI2-NEXT: popl %esi
2337 ; X86-BMI1BMI2-NEXT: retl
2339 ; X64-NOBMI-LABEL: bzhi32_c2_load:
2340 ; X64-NOBMI: # %bb.0:
2341 ; X64-NOBMI-NEXT: pushq %rbx
2342 ; X64-NOBMI-NEXT: movl %esi, %ecx
2343 ; X64-NOBMI-NEXT: negb %cl
2344 ; X64-NOBMI-NEXT: movl $-1, %eax
2345 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
2346 ; X64-NOBMI-NEXT: shrl %cl, %eax
2347 ; X64-NOBMI-NEXT: movl (%rdi), %ebx
2348 ; X64-NOBMI-NEXT: andl %eax, %ebx
2349 ; X64-NOBMI-NEXT: movl %eax, %edi
2350 ; X64-NOBMI-NEXT: callq use32
2351 ; X64-NOBMI-NEXT: movl %ebx, %eax
2352 ; X64-NOBMI-NEXT: popq %rbx
2353 ; X64-NOBMI-NEXT: retq
2355 ; X64-BMI1NOTBM-LABEL: bzhi32_c2_load:
2356 ; X64-BMI1NOTBM: # %bb.0:
2357 ; X64-BMI1NOTBM-NEXT: pushq %rbx
2358 ; X64-BMI1NOTBM-NEXT: movl %esi, %ecx
2359 ; X64-BMI1NOTBM-NEXT: negb %cl
2360 ; X64-BMI1NOTBM-NEXT: movl $-1, %eax
2361 ; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx
2362 ; X64-BMI1NOTBM-NEXT: shrl %cl, %eax
2363 ; X64-BMI1NOTBM-NEXT: movl (%rdi), %ebx
2364 ; X64-BMI1NOTBM-NEXT: andl %eax, %ebx
2365 ; X64-BMI1NOTBM-NEXT: movl %eax, %edi
2366 ; X64-BMI1NOTBM-NEXT: callq use32
2367 ; X64-BMI1NOTBM-NEXT: movl %ebx, %eax
2368 ; X64-BMI1NOTBM-NEXT: popq %rbx
2369 ; X64-BMI1NOTBM-NEXT: retq
2371 ; X64-BMI1BMI2-LABEL: bzhi32_c2_load:
2372 ; X64-BMI1BMI2: # %bb.0:
2373 ; X64-BMI1BMI2-NEXT: pushq %rbx
2374 ; X64-BMI1BMI2-NEXT: bzhil %esi, (%rdi), %ebx
2375 ; X64-BMI1BMI2-NEXT: # kill: def $sil killed $sil killed $esi def $esi
2376 ; X64-BMI1BMI2-NEXT: negb %sil
2377 ; X64-BMI1BMI2-NEXT: movl $-1, %eax
2378 ; X64-BMI1BMI2-NEXT: shrxl %esi, %eax, %edi
2379 ; X64-BMI1BMI2-NEXT: callq use32
2380 ; X64-BMI1BMI2-NEXT: movl %ebx, %eax
2381 ; X64-BMI1BMI2-NEXT: popq %rbx
2382 ; X64-BMI1BMI2-NEXT: retq
2383 %val = load i32, i32* %w
2384 %numhighbits = sub i32 32, %numlowbits
2385 %mask = lshr i32 -1, %numhighbits
2386 call void @use32(i32 %mask)
2387 %masked = and i32 %mask, %val
2391 define i32 @bzhi32_c3_load_indexzext(i32* %w, i8 %numlowbits) nounwind {
2392 ; X86-NOBMI-LABEL: bzhi32_c3_load_indexzext:
2393 ; X86-NOBMI: # %bb.0:
2394 ; X86-NOBMI-NEXT: pushl %esi
2395 ; X86-NOBMI-NEXT: subl $8, %esp
2396 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
2397 ; X86-NOBMI-NEXT: xorl %ecx, %ecx
2398 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
2399 ; X86-NOBMI-NEXT: movl $-1, %edx
2400 ; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
2401 ; X86-NOBMI-NEXT: shrl %cl, %edx
2402 ; X86-NOBMI-NEXT: movl (%eax), %esi
2403 ; X86-NOBMI-NEXT: andl %edx, %esi
2404 ; X86-NOBMI-NEXT: movl %edx, (%esp)
2405 ; X86-NOBMI-NEXT: calll use32
2406 ; X86-NOBMI-NEXT: movl %esi, %eax
2407 ; X86-NOBMI-NEXT: addl $8, %esp
2408 ; X86-NOBMI-NEXT: popl %esi
2409 ; X86-NOBMI-NEXT: retl
2411 ; X86-BMI1NOTBM-LABEL: bzhi32_c3_load_indexzext:
2412 ; X86-BMI1NOTBM: # %bb.0:
2413 ; X86-BMI1NOTBM-NEXT: pushl %esi
2414 ; X86-BMI1NOTBM-NEXT: subl $8, %esp
2415 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
2416 ; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx
2417 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
2418 ; X86-BMI1NOTBM-NEXT: movl $-1, %edx
2419 ; X86-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx
2420 ; X86-BMI1NOTBM-NEXT: shrl %cl, %edx
2421 ; X86-BMI1NOTBM-NEXT: movl (%eax), %esi
2422 ; X86-BMI1NOTBM-NEXT: andl %edx, %esi
2423 ; X86-BMI1NOTBM-NEXT: movl %edx, (%esp)
2424 ; X86-BMI1NOTBM-NEXT: calll use32
2425 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
2426 ; X86-BMI1NOTBM-NEXT: addl $8, %esp
2427 ; X86-BMI1NOTBM-NEXT: popl %esi
2428 ; X86-BMI1NOTBM-NEXT: retl
2430 ; X86-BMI1BMI2-LABEL: bzhi32_c3_load_indexzext:
2431 ; X86-BMI1BMI2: # %bb.0:
2432 ; X86-BMI1BMI2-NEXT: pushl %esi
2433 ; X86-BMI1BMI2-NEXT: subl $8, %esp
2434 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
2435 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
2436 ; X86-BMI1BMI2-NEXT: bzhil %ecx, (%eax), %esi
2437 ; X86-BMI1BMI2-NEXT: # kill: def $cl killed $cl killed $ecx def $ecx
2438 ; X86-BMI1BMI2-NEXT: negb %cl
2439 ; X86-BMI1BMI2-NEXT: movl $-1, %eax
2440 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %eax
2441 ; X86-BMI1BMI2-NEXT: movl %eax, (%esp)
2442 ; X86-BMI1BMI2-NEXT: calll use32
2443 ; X86-BMI1BMI2-NEXT: movl %esi, %eax
2444 ; X86-BMI1BMI2-NEXT: addl $8, %esp
2445 ; X86-BMI1BMI2-NEXT: popl %esi
2446 ; X86-BMI1BMI2-NEXT: retl
2448 ; X64-NOBMI-LABEL: bzhi32_c3_load_indexzext:
2449 ; X64-NOBMI: # %bb.0:
2450 ; X64-NOBMI-NEXT: pushq %rbx
2451 ; X64-NOBMI-NEXT: movl %esi, %ecx
2452 ; X64-NOBMI-NEXT: negb %cl
2453 ; X64-NOBMI-NEXT: movl $-1, %eax
2454 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
2455 ; X64-NOBMI-NEXT: shrl %cl, %eax
2456 ; X64-NOBMI-NEXT: movl (%rdi), %ebx
2457 ; X64-NOBMI-NEXT: andl %eax, %ebx
2458 ; X64-NOBMI-NEXT: movl %eax, %edi
2459 ; X64-NOBMI-NEXT: callq use32
2460 ; X64-NOBMI-NEXT: movl %ebx, %eax
2461 ; X64-NOBMI-NEXT: popq %rbx
2462 ; X64-NOBMI-NEXT: retq
2464 ; X64-BMI1NOTBM-LABEL: bzhi32_c3_load_indexzext:
2465 ; X64-BMI1NOTBM: # %bb.0:
2466 ; X64-BMI1NOTBM-NEXT: pushq %rbx
2467 ; X64-BMI1NOTBM-NEXT: movl %esi, %ecx
2468 ; X64-BMI1NOTBM-NEXT: negb %cl
2469 ; X64-BMI1NOTBM-NEXT: movl $-1, %eax
2470 ; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx
2471 ; X64-BMI1NOTBM-NEXT: shrl %cl, %eax
2472 ; X64-BMI1NOTBM-NEXT: movl (%rdi), %ebx
2473 ; X64-BMI1NOTBM-NEXT: andl %eax, %ebx
2474 ; X64-BMI1NOTBM-NEXT: movl %eax, %edi
2475 ; X64-BMI1NOTBM-NEXT: callq use32
2476 ; X64-BMI1NOTBM-NEXT: movl %ebx, %eax
2477 ; X64-BMI1NOTBM-NEXT: popq %rbx
2478 ; X64-BMI1NOTBM-NEXT: retq
2480 ; X64-BMI1BMI2-LABEL: bzhi32_c3_load_indexzext:
2481 ; X64-BMI1BMI2: # %bb.0:
2482 ; X64-BMI1BMI2-NEXT: pushq %rbx
2483 ; X64-BMI1BMI2-NEXT: bzhil %esi, (%rdi), %ebx
2484 ; X64-BMI1BMI2-NEXT: # kill: def $sil killed $sil killed $esi def $esi
2485 ; X64-BMI1BMI2-NEXT: negb %sil
2486 ; X64-BMI1BMI2-NEXT: movl $-1, %eax
2487 ; X64-BMI1BMI2-NEXT: shrxl %esi, %eax, %edi
2488 ; X64-BMI1BMI2-NEXT: callq use32
2489 ; X64-BMI1BMI2-NEXT: movl %ebx, %eax
2490 ; X64-BMI1BMI2-NEXT: popq %rbx
2491 ; X64-BMI1BMI2-NEXT: retq
2492 %val = load i32, i32* %w
2493 %numhighbits = sub i8 32, %numlowbits
2494 %sh_prom = zext i8 %numhighbits to i32
2495 %mask = lshr i32 -1, %sh_prom
2496 call void @use32(i32 %mask)
2497 %masked = and i32 %mask, %val
2501 define i32 @bzhi32_c4_commutative(i32 %val, i32 %numlowbits) nounwind {
2502 ; X86-NOBMI-LABEL: bzhi32_c4_commutative:
2503 ; X86-NOBMI: # %bb.0:
2504 ; X86-NOBMI-NEXT: pushl %esi
2505 ; X86-NOBMI-NEXT: subl $8, %esp
2506 ; X86-NOBMI-NEXT: xorl %ecx, %ecx
2507 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
2508 ; X86-NOBMI-NEXT: movl $-1, %esi
2509 ; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
2510 ; X86-NOBMI-NEXT: shrl %cl, %esi
2511 ; X86-NOBMI-NEXT: movl %esi, (%esp)
2512 ; X86-NOBMI-NEXT: calll use32
2513 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %esi
2514 ; X86-NOBMI-NEXT: movl %esi, %eax
2515 ; X86-NOBMI-NEXT: addl $8, %esp
2516 ; X86-NOBMI-NEXT: popl %esi
2517 ; X86-NOBMI-NEXT: retl
2519 ; X86-BMI1NOTBM-LABEL: bzhi32_c4_commutative:
2520 ; X86-BMI1NOTBM: # %bb.0:
2521 ; X86-BMI1NOTBM-NEXT: pushl %esi
2522 ; X86-BMI1NOTBM-NEXT: subl $8, %esp
2523 ; X86-BMI1NOTBM-NEXT: xorl %ecx, %ecx
2524 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
2525 ; X86-BMI1NOTBM-NEXT: movl $-1, %esi
2526 ; X86-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx
2527 ; X86-BMI1NOTBM-NEXT: shrl %cl, %esi
2528 ; X86-BMI1NOTBM-NEXT: movl %esi, (%esp)
2529 ; X86-BMI1NOTBM-NEXT: calll use32
2530 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %esi
2531 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
2532 ; X86-BMI1NOTBM-NEXT: addl $8, %esp
2533 ; X86-BMI1NOTBM-NEXT: popl %esi
2534 ; X86-BMI1NOTBM-NEXT: retl
2536 ; X86-BMI1BMI2-LABEL: bzhi32_c4_commutative:
2537 ; X86-BMI1BMI2: # %bb.0:
2538 ; X86-BMI1BMI2-NEXT: pushl %ebx
2539 ; X86-BMI1BMI2-NEXT: subl $8, %esp
2540 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %bl
2541 ; X86-BMI1BMI2-NEXT: movl %ebx, %eax
2542 ; X86-BMI1BMI2-NEXT: negb %al
2543 ; X86-BMI1BMI2-NEXT: movl $-1, %ecx
2544 ; X86-BMI1BMI2-NEXT: shrxl %eax, %ecx, %eax
2545 ; X86-BMI1BMI2-NEXT: movl %eax, (%esp)
2546 ; X86-BMI1BMI2-NEXT: calll use32
2547 ; X86-BMI1BMI2-NEXT: bzhil %ebx, {{[0-9]+}}(%esp), %eax
2548 ; X86-BMI1BMI2-NEXT: addl $8, %esp
2549 ; X86-BMI1BMI2-NEXT: popl %ebx
2550 ; X86-BMI1BMI2-NEXT: retl
2552 ; X64-NOBMI-LABEL: bzhi32_c4_commutative:
2553 ; X64-NOBMI: # %bb.0:
2554 ; X64-NOBMI-NEXT: pushq %rbp
2555 ; X64-NOBMI-NEXT: pushq %rbx
2556 ; X64-NOBMI-NEXT: pushq %rax
2557 ; X64-NOBMI-NEXT: movl %esi, %ecx
2558 ; X64-NOBMI-NEXT: movl %edi, %ebx
2559 ; X64-NOBMI-NEXT: negb %cl
2560 ; X64-NOBMI-NEXT: movl $-1, %ebp
2561 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
2562 ; X64-NOBMI-NEXT: shrl %cl, %ebp
2563 ; X64-NOBMI-NEXT: movl %ebp, %edi
2564 ; X64-NOBMI-NEXT: callq use32
2565 ; X64-NOBMI-NEXT: andl %ebx, %ebp
2566 ; X64-NOBMI-NEXT: movl %ebp, %eax
2567 ; X64-NOBMI-NEXT: addq $8, %rsp
2568 ; X64-NOBMI-NEXT: popq %rbx
2569 ; X64-NOBMI-NEXT: popq %rbp
2570 ; X64-NOBMI-NEXT: retq
2572 ; X64-BMI1NOTBM-LABEL: bzhi32_c4_commutative:
2573 ; X64-BMI1NOTBM: # %bb.0:
2574 ; X64-BMI1NOTBM-NEXT: pushq %rbp
2575 ; X64-BMI1NOTBM-NEXT: pushq %rbx
2576 ; X64-BMI1NOTBM-NEXT: pushq %rax
2577 ; X64-BMI1NOTBM-NEXT: movl %esi, %ecx
2578 ; X64-BMI1NOTBM-NEXT: movl %edi, %ebx
2579 ; X64-BMI1NOTBM-NEXT: negb %cl
2580 ; X64-BMI1NOTBM-NEXT: movl $-1, %ebp
2581 ; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx
2582 ; X64-BMI1NOTBM-NEXT: shrl %cl, %ebp
2583 ; X64-BMI1NOTBM-NEXT: movl %ebp, %edi
2584 ; X64-BMI1NOTBM-NEXT: callq use32
2585 ; X64-BMI1NOTBM-NEXT: andl %ebx, %ebp
2586 ; X64-BMI1NOTBM-NEXT: movl %ebp, %eax
2587 ; X64-BMI1NOTBM-NEXT: addq $8, %rsp
2588 ; X64-BMI1NOTBM-NEXT: popq %rbx
2589 ; X64-BMI1NOTBM-NEXT: popq %rbp
2590 ; X64-BMI1NOTBM-NEXT: retq
2592 ; X64-BMI1BMI2-LABEL: bzhi32_c4_commutative:
2593 ; X64-BMI1BMI2: # %bb.0:
2594 ; X64-BMI1BMI2-NEXT: pushq %rbp
2595 ; X64-BMI1BMI2-NEXT: pushq %rbx
2596 ; X64-BMI1BMI2-NEXT: pushq %rax
2597 ; X64-BMI1BMI2-NEXT: movl %esi, %ebx
2598 ; X64-BMI1BMI2-NEXT: movl %edi, %ebp
2599 ; X64-BMI1BMI2-NEXT: movl %ebx, %eax
2600 ; X64-BMI1BMI2-NEXT: negb %al
2601 ; X64-BMI1BMI2-NEXT: movl $-1, %ecx
2602 ; X64-BMI1BMI2-NEXT: shrxl %eax, %ecx, %edi
2603 ; X64-BMI1BMI2-NEXT: callq use32
2604 ; X64-BMI1BMI2-NEXT: bzhil %ebx, %ebp, %eax
2605 ; X64-BMI1BMI2-NEXT: addq $8, %rsp
2606 ; X64-BMI1BMI2-NEXT: popq %rbx
2607 ; X64-BMI1BMI2-NEXT: popq %rbp
2608 ; X64-BMI1BMI2-NEXT: retq
2609 %numhighbits = sub i32 32, %numlowbits
2610 %mask = lshr i32 -1, %numhighbits
2611 call void @use32(i32 %mask)
2612 %masked = and i32 %val, %mask ; swapped order
2618 declare void @use64(i64)
2620 define i64 @bzhi64_c0(i64 %val, i64 %numlowbits) nounwind {
2621 ; X86-NOBMI-LABEL: bzhi64_c0:
2622 ; X86-NOBMI: # %bb.0:
2623 ; X86-NOBMI-NEXT: pushl %edi
2624 ; X86-NOBMI-NEXT: pushl %esi
2625 ; X86-NOBMI-NEXT: pushl %eax
2626 ; X86-NOBMI-NEXT: movb $64, %cl
2627 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
2628 ; X86-NOBMI-NEXT: movl $-1, %esi
2629 ; X86-NOBMI-NEXT: movl $-1, %edi
2630 ; X86-NOBMI-NEXT: shrl %cl, %edi
2631 ; X86-NOBMI-NEXT: shrdl %cl, %esi, %esi
2632 ; X86-NOBMI-NEXT: testb $32, %cl
2633 ; X86-NOBMI-NEXT: je .LBB34_2
2634 ; X86-NOBMI-NEXT: # %bb.1:
2635 ; X86-NOBMI-NEXT: movl %edi, %esi
2636 ; X86-NOBMI-NEXT: xorl %edi, %edi
2637 ; X86-NOBMI-NEXT: .LBB34_2:
2638 ; X86-NOBMI-NEXT: subl $8, %esp
2639 ; X86-NOBMI-NEXT: pushl %edi
2640 ; X86-NOBMI-NEXT: pushl %esi
2641 ; X86-NOBMI-NEXT: calll use64
2642 ; X86-NOBMI-NEXT: addl $16, %esp
2643 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %esi
2644 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %edi
2645 ; X86-NOBMI-NEXT: movl %esi, %eax
2646 ; X86-NOBMI-NEXT: movl %edi, %edx
2647 ; X86-NOBMI-NEXT: addl $4, %esp
2648 ; X86-NOBMI-NEXT: popl %esi
2649 ; X86-NOBMI-NEXT: popl %edi
2650 ; X86-NOBMI-NEXT: retl
2652 ; X86-BMI1NOTBM-LABEL: bzhi64_c0:
2653 ; X86-BMI1NOTBM: # %bb.0:
2654 ; X86-BMI1NOTBM-NEXT: pushl %edi
2655 ; X86-BMI1NOTBM-NEXT: pushl %esi
2656 ; X86-BMI1NOTBM-NEXT: pushl %eax
2657 ; X86-BMI1NOTBM-NEXT: movb $64, %cl
2658 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
2659 ; X86-BMI1NOTBM-NEXT: movl $-1, %esi
2660 ; X86-BMI1NOTBM-NEXT: movl $-1, %edi
2661 ; X86-BMI1NOTBM-NEXT: shrl %cl, %edi
2662 ; X86-BMI1NOTBM-NEXT: shrdl %cl, %esi, %esi
2663 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
2664 ; X86-BMI1NOTBM-NEXT: je .LBB34_2
2665 ; X86-BMI1NOTBM-NEXT: # %bb.1:
2666 ; X86-BMI1NOTBM-NEXT: movl %edi, %esi
2667 ; X86-BMI1NOTBM-NEXT: xorl %edi, %edi
2668 ; X86-BMI1NOTBM-NEXT: .LBB34_2:
2669 ; X86-BMI1NOTBM-NEXT: subl $8, %esp
2670 ; X86-BMI1NOTBM-NEXT: pushl %edi
2671 ; X86-BMI1NOTBM-NEXT: pushl %esi
2672 ; X86-BMI1NOTBM-NEXT: calll use64
2673 ; X86-BMI1NOTBM-NEXT: addl $16, %esp
2674 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %esi
2675 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %edi
2676 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
2677 ; X86-BMI1NOTBM-NEXT: movl %edi, %edx
2678 ; X86-BMI1NOTBM-NEXT: addl $4, %esp
2679 ; X86-BMI1NOTBM-NEXT: popl %esi
2680 ; X86-BMI1NOTBM-NEXT: popl %edi
2681 ; X86-BMI1NOTBM-NEXT: retl
2683 ; X86-BMI1BMI2-LABEL: bzhi64_c0:
2684 ; X86-BMI1BMI2: # %bb.0:
2685 ; X86-BMI1BMI2-NEXT: pushl %edi
2686 ; X86-BMI1BMI2-NEXT: pushl %esi
2687 ; X86-BMI1BMI2-NEXT: pushl %eax
2688 ; X86-BMI1BMI2-NEXT: movb $64, %cl
2689 ; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl
2690 ; X86-BMI1BMI2-NEXT: movl $-1, %esi
2691 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edi
2692 ; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %esi
2693 ; X86-BMI1BMI2-NEXT: testb $32, %cl
2694 ; X86-BMI1BMI2-NEXT: je .LBB34_2
2695 ; X86-BMI1BMI2-NEXT: # %bb.1:
2696 ; X86-BMI1BMI2-NEXT: movl %edi, %esi
2697 ; X86-BMI1BMI2-NEXT: xorl %edi, %edi
2698 ; X86-BMI1BMI2-NEXT: .LBB34_2:
2699 ; X86-BMI1BMI2-NEXT: subl $8, %esp
2700 ; X86-BMI1BMI2-NEXT: pushl %edi
2701 ; X86-BMI1BMI2-NEXT: pushl %esi
2702 ; X86-BMI1BMI2-NEXT: calll use64
2703 ; X86-BMI1BMI2-NEXT: addl $16, %esp
2704 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %esi
2705 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %edi
2706 ; X86-BMI1BMI2-NEXT: movl %esi, %eax
2707 ; X86-BMI1BMI2-NEXT: movl %edi, %edx
2708 ; X86-BMI1BMI2-NEXT: addl $4, %esp
2709 ; X86-BMI1BMI2-NEXT: popl %esi
2710 ; X86-BMI1BMI2-NEXT: popl %edi
2711 ; X86-BMI1BMI2-NEXT: retl
2713 ; X64-NOBMI-LABEL: bzhi64_c0:
2714 ; X64-NOBMI: # %bb.0:
2715 ; X64-NOBMI-NEXT: pushq %r14
2716 ; X64-NOBMI-NEXT: pushq %rbx
2717 ; X64-NOBMI-NEXT: pushq %rax
2718 ; X64-NOBMI-NEXT: movq %rsi, %rcx
2719 ; X64-NOBMI-NEXT: movq %rdi, %r14
2720 ; X64-NOBMI-NEXT: negb %cl
2721 ; X64-NOBMI-NEXT: movq $-1, %rbx
2722 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
2723 ; X64-NOBMI-NEXT: shrq %cl, %rbx
2724 ; X64-NOBMI-NEXT: movq %rbx, %rdi
2725 ; X64-NOBMI-NEXT: callq use64
2726 ; X64-NOBMI-NEXT: andq %r14, %rbx
2727 ; X64-NOBMI-NEXT: movq %rbx, %rax
2728 ; X64-NOBMI-NEXT: addq $8, %rsp
2729 ; X64-NOBMI-NEXT: popq %rbx
2730 ; X64-NOBMI-NEXT: popq %r14
2731 ; X64-NOBMI-NEXT: retq
2733 ; X64-BMI1NOTBM-LABEL: bzhi64_c0:
2734 ; X64-BMI1NOTBM: # %bb.0:
2735 ; X64-BMI1NOTBM-NEXT: pushq %r14
2736 ; X64-BMI1NOTBM-NEXT: pushq %rbx
2737 ; X64-BMI1NOTBM-NEXT: pushq %rax
2738 ; X64-BMI1NOTBM-NEXT: movq %rsi, %rcx
2739 ; X64-BMI1NOTBM-NEXT: movq %rdi, %r14
2740 ; X64-BMI1NOTBM-NEXT: negb %cl
2741 ; X64-BMI1NOTBM-NEXT: movq $-1, %rbx
2742 ; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $rcx
2743 ; X64-BMI1NOTBM-NEXT: shrq %cl, %rbx
2744 ; X64-BMI1NOTBM-NEXT: movq %rbx, %rdi
2745 ; X64-BMI1NOTBM-NEXT: callq use64
2746 ; X64-BMI1NOTBM-NEXT: andq %r14, %rbx
2747 ; X64-BMI1NOTBM-NEXT: movq %rbx, %rax
2748 ; X64-BMI1NOTBM-NEXT: addq $8, %rsp
2749 ; X64-BMI1NOTBM-NEXT: popq %rbx
2750 ; X64-BMI1NOTBM-NEXT: popq %r14
2751 ; X64-BMI1NOTBM-NEXT: retq
2753 ; X64-BMI1BMI2-LABEL: bzhi64_c0:
2754 ; X64-BMI1BMI2: # %bb.0:
2755 ; X64-BMI1BMI2-NEXT: pushq %r14
2756 ; X64-BMI1BMI2-NEXT: pushq %rbx
2757 ; X64-BMI1BMI2-NEXT: pushq %rax
2758 ; X64-BMI1BMI2-NEXT: movq %rsi, %rbx
2759 ; X64-BMI1BMI2-NEXT: movq %rdi, %r14
2760 ; X64-BMI1BMI2-NEXT: movl %ebx, %eax
2761 ; X64-BMI1BMI2-NEXT: negb %al
2762 ; X64-BMI1BMI2-NEXT: movq $-1, %rcx
2763 ; X64-BMI1BMI2-NEXT: shrxq %rax, %rcx, %rdi
2764 ; X64-BMI1BMI2-NEXT: callq use64
2765 ; X64-BMI1BMI2-NEXT: bzhiq %rbx, %r14, %rax
2766 ; X64-BMI1BMI2-NEXT: addq $8, %rsp
2767 ; X64-BMI1BMI2-NEXT: popq %rbx
2768 ; X64-BMI1BMI2-NEXT: popq %r14
2769 ; X64-BMI1BMI2-NEXT: retq
2770 %numhighbits = sub i64 64, %numlowbits
2771 %mask = lshr i64 -1, %numhighbits
2772 call void @use64(i64 %mask)
2773 %masked = and i64 %mask, %val
2777 define i64 @bzhi64_c1_indexzext(i64 %val, i8 %numlowbits) nounwind {
2778 ; X86-NOBMI-LABEL: bzhi64_c1_indexzext:
2779 ; X86-NOBMI: # %bb.0:
2780 ; X86-NOBMI-NEXT: pushl %edi
2781 ; X86-NOBMI-NEXT: pushl %esi
2782 ; X86-NOBMI-NEXT: pushl %eax
2783 ; X86-NOBMI-NEXT: movb $64, %cl
2784 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
2785 ; X86-NOBMI-NEXT: movl $-1, %esi
2786 ; X86-NOBMI-NEXT: movl $-1, %edi
2787 ; X86-NOBMI-NEXT: shrl %cl, %edi
2788 ; X86-NOBMI-NEXT: shrdl %cl, %esi, %esi
2789 ; X86-NOBMI-NEXT: testb $32, %cl
2790 ; X86-NOBMI-NEXT: je .LBB35_2
2791 ; X86-NOBMI-NEXT: # %bb.1:
2792 ; X86-NOBMI-NEXT: movl %edi, %esi
2793 ; X86-NOBMI-NEXT: xorl %edi, %edi
2794 ; X86-NOBMI-NEXT: .LBB35_2:
2795 ; X86-NOBMI-NEXT: subl $8, %esp
2796 ; X86-NOBMI-NEXT: pushl %edi
2797 ; X86-NOBMI-NEXT: pushl %esi
2798 ; X86-NOBMI-NEXT: calll use64
2799 ; X86-NOBMI-NEXT: addl $16, %esp
2800 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %esi
2801 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %edi
2802 ; X86-NOBMI-NEXT: movl %esi, %eax
2803 ; X86-NOBMI-NEXT: movl %edi, %edx
2804 ; X86-NOBMI-NEXT: addl $4, %esp
2805 ; X86-NOBMI-NEXT: popl %esi
2806 ; X86-NOBMI-NEXT: popl %edi
2807 ; X86-NOBMI-NEXT: retl
2809 ; X86-BMI1NOTBM-LABEL: bzhi64_c1_indexzext:
2810 ; X86-BMI1NOTBM: # %bb.0:
2811 ; X86-BMI1NOTBM-NEXT: pushl %edi
2812 ; X86-BMI1NOTBM-NEXT: pushl %esi
2813 ; X86-BMI1NOTBM-NEXT: pushl %eax
2814 ; X86-BMI1NOTBM-NEXT: movb $64, %cl
2815 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
2816 ; X86-BMI1NOTBM-NEXT: movl $-1, %esi
2817 ; X86-BMI1NOTBM-NEXT: movl $-1, %edi
2818 ; X86-BMI1NOTBM-NEXT: shrl %cl, %edi
2819 ; X86-BMI1NOTBM-NEXT: shrdl %cl, %esi, %esi
2820 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
2821 ; X86-BMI1NOTBM-NEXT: je .LBB35_2
2822 ; X86-BMI1NOTBM-NEXT: # %bb.1:
2823 ; X86-BMI1NOTBM-NEXT: movl %edi, %esi
2824 ; X86-BMI1NOTBM-NEXT: xorl %edi, %edi
2825 ; X86-BMI1NOTBM-NEXT: .LBB35_2:
2826 ; X86-BMI1NOTBM-NEXT: subl $8, %esp
2827 ; X86-BMI1NOTBM-NEXT: pushl %edi
2828 ; X86-BMI1NOTBM-NEXT: pushl %esi
2829 ; X86-BMI1NOTBM-NEXT: calll use64
2830 ; X86-BMI1NOTBM-NEXT: addl $16, %esp
2831 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %esi
2832 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %edi
2833 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
2834 ; X86-BMI1NOTBM-NEXT: movl %edi, %edx
2835 ; X86-BMI1NOTBM-NEXT: addl $4, %esp
2836 ; X86-BMI1NOTBM-NEXT: popl %esi
2837 ; X86-BMI1NOTBM-NEXT: popl %edi
2838 ; X86-BMI1NOTBM-NEXT: retl
2840 ; X86-BMI1BMI2-LABEL: bzhi64_c1_indexzext:
2841 ; X86-BMI1BMI2: # %bb.0:
2842 ; X86-BMI1BMI2-NEXT: pushl %edi
2843 ; X86-BMI1BMI2-NEXT: pushl %esi
2844 ; X86-BMI1BMI2-NEXT: pushl %eax
2845 ; X86-BMI1BMI2-NEXT: movb $64, %cl
2846 ; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl
2847 ; X86-BMI1BMI2-NEXT: movl $-1, %esi
2848 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edi
2849 ; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %esi
2850 ; X86-BMI1BMI2-NEXT: testb $32, %cl
2851 ; X86-BMI1BMI2-NEXT: je .LBB35_2
2852 ; X86-BMI1BMI2-NEXT: # %bb.1:
2853 ; X86-BMI1BMI2-NEXT: movl %edi, %esi
2854 ; X86-BMI1BMI2-NEXT: xorl %edi, %edi
2855 ; X86-BMI1BMI2-NEXT: .LBB35_2:
2856 ; X86-BMI1BMI2-NEXT: subl $8, %esp
2857 ; X86-BMI1BMI2-NEXT: pushl %edi
2858 ; X86-BMI1BMI2-NEXT: pushl %esi
2859 ; X86-BMI1BMI2-NEXT: calll use64
2860 ; X86-BMI1BMI2-NEXT: addl $16, %esp
2861 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %esi
2862 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %edi
2863 ; X86-BMI1BMI2-NEXT: movl %esi, %eax
2864 ; X86-BMI1BMI2-NEXT: movl %edi, %edx
2865 ; X86-BMI1BMI2-NEXT: addl $4, %esp
2866 ; X86-BMI1BMI2-NEXT: popl %esi
2867 ; X86-BMI1BMI2-NEXT: popl %edi
2868 ; X86-BMI1BMI2-NEXT: retl
2870 ; X64-NOBMI-LABEL: bzhi64_c1_indexzext:
2871 ; X64-NOBMI: # %bb.0:
2872 ; X64-NOBMI-NEXT: pushq %r14
2873 ; X64-NOBMI-NEXT: pushq %rbx
2874 ; X64-NOBMI-NEXT: pushq %rax
2875 ; X64-NOBMI-NEXT: movl %esi, %ecx
2876 ; X64-NOBMI-NEXT: movq %rdi, %r14
2877 ; X64-NOBMI-NEXT: negb %cl
2878 ; X64-NOBMI-NEXT: movq $-1, %rbx
2879 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
2880 ; X64-NOBMI-NEXT: shrq %cl, %rbx
2881 ; X64-NOBMI-NEXT: movq %rbx, %rdi
2882 ; X64-NOBMI-NEXT: callq use64
2883 ; X64-NOBMI-NEXT: andq %r14, %rbx
2884 ; X64-NOBMI-NEXT: movq %rbx, %rax
2885 ; X64-NOBMI-NEXT: addq $8, %rsp
2886 ; X64-NOBMI-NEXT: popq %rbx
2887 ; X64-NOBMI-NEXT: popq %r14
2888 ; X64-NOBMI-NEXT: retq
2890 ; X64-BMI1NOTBM-LABEL: bzhi64_c1_indexzext:
2891 ; X64-BMI1NOTBM: # %bb.0:
2892 ; X64-BMI1NOTBM-NEXT: pushq %r14
2893 ; X64-BMI1NOTBM-NEXT: pushq %rbx
2894 ; X64-BMI1NOTBM-NEXT: pushq %rax
2895 ; X64-BMI1NOTBM-NEXT: movl %esi, %ecx
2896 ; X64-BMI1NOTBM-NEXT: movq %rdi, %r14
2897 ; X64-BMI1NOTBM-NEXT: negb %cl
2898 ; X64-BMI1NOTBM-NEXT: movq $-1, %rbx
2899 ; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx
2900 ; X64-BMI1NOTBM-NEXT: shrq %cl, %rbx
2901 ; X64-BMI1NOTBM-NEXT: movq %rbx, %rdi
2902 ; X64-BMI1NOTBM-NEXT: callq use64
2903 ; X64-BMI1NOTBM-NEXT: andq %r14, %rbx
2904 ; X64-BMI1NOTBM-NEXT: movq %rbx, %rax
2905 ; X64-BMI1NOTBM-NEXT: addq $8, %rsp
2906 ; X64-BMI1NOTBM-NEXT: popq %rbx
2907 ; X64-BMI1NOTBM-NEXT: popq %r14
2908 ; X64-BMI1NOTBM-NEXT: retq
2910 ; X64-BMI1BMI2-LABEL: bzhi64_c1_indexzext:
2911 ; X64-BMI1BMI2: # %bb.0:
2912 ; X64-BMI1BMI2-NEXT: pushq %r14
2913 ; X64-BMI1BMI2-NEXT: pushq %rbx
2914 ; X64-BMI1BMI2-NEXT: pushq %rax
2915 ; X64-BMI1BMI2-NEXT: movl %esi, %ebx
2916 ; X64-BMI1BMI2-NEXT: movq %rdi, %r14
2917 ; X64-BMI1BMI2-NEXT: movl %ebx, %eax
2918 ; X64-BMI1BMI2-NEXT: negb %al
2919 ; X64-BMI1BMI2-NEXT: movq $-1, %rcx
2920 ; X64-BMI1BMI2-NEXT: shrxq %rax, %rcx, %rdi
2921 ; X64-BMI1BMI2-NEXT: callq use64
2922 ; X64-BMI1BMI2-NEXT: bzhiq %rbx, %r14, %rax
2923 ; X64-BMI1BMI2-NEXT: addq $8, %rsp
2924 ; X64-BMI1BMI2-NEXT: popq %rbx
2925 ; X64-BMI1BMI2-NEXT: popq %r14
2926 ; X64-BMI1BMI2-NEXT: retq
2927 %numhighbits = sub i8 64, %numlowbits
2928 %sh_prom = zext i8 %numhighbits to i64
2929 %mask = lshr i64 -1, %sh_prom
2930 call void @use64(i64 %mask)
2931 %masked = and i64 %mask, %val
2935 define i64 @bzhi64_c2_load(i64* %w, i64 %numlowbits) nounwind {
2936 ; X86-NOBMI-LABEL: bzhi64_c2_load:
2937 ; X86-NOBMI: # %bb.0:
2938 ; X86-NOBMI-NEXT: pushl %ebx
2939 ; X86-NOBMI-NEXT: pushl %edi
2940 ; X86-NOBMI-NEXT: pushl %esi
2941 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx
2942 ; X86-NOBMI-NEXT: movb $64, %cl
2943 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
2944 ; X86-NOBMI-NEXT: movl $-1, %eax
2945 ; X86-NOBMI-NEXT: movl $-1, %ebx
2946 ; X86-NOBMI-NEXT: shrl %cl, %ebx
2947 ; X86-NOBMI-NEXT: shrdl %cl, %eax, %eax
2948 ; X86-NOBMI-NEXT: testb $32, %cl
2949 ; X86-NOBMI-NEXT: je .LBB36_2
2950 ; X86-NOBMI-NEXT: # %bb.1:
2951 ; X86-NOBMI-NEXT: movl %ebx, %eax
2952 ; X86-NOBMI-NEXT: xorl %ebx, %ebx
2953 ; X86-NOBMI-NEXT: .LBB36_2:
2954 ; X86-NOBMI-NEXT: movl (%edx), %esi
2955 ; X86-NOBMI-NEXT: andl %eax, %esi
2956 ; X86-NOBMI-NEXT: movl 4(%edx), %edi
2957 ; X86-NOBMI-NEXT: andl %ebx, %edi
2958 ; X86-NOBMI-NEXT: subl $8, %esp
2959 ; X86-NOBMI-NEXT: pushl %ebx
2960 ; X86-NOBMI-NEXT: pushl %eax
2961 ; X86-NOBMI-NEXT: calll use64
2962 ; X86-NOBMI-NEXT: addl $16, %esp
2963 ; X86-NOBMI-NEXT: movl %esi, %eax
2964 ; X86-NOBMI-NEXT: movl %edi, %edx
2965 ; X86-NOBMI-NEXT: popl %esi
2966 ; X86-NOBMI-NEXT: popl %edi
2967 ; X86-NOBMI-NEXT: popl %ebx
2968 ; X86-NOBMI-NEXT: retl
2970 ; X86-BMI1NOTBM-LABEL: bzhi64_c2_load:
2971 ; X86-BMI1NOTBM: # %bb.0:
2972 ; X86-BMI1NOTBM-NEXT: pushl %ebx
2973 ; X86-BMI1NOTBM-NEXT: pushl %edi
2974 ; X86-BMI1NOTBM-NEXT: pushl %esi
2975 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edx
2976 ; X86-BMI1NOTBM-NEXT: movb $64, %cl
2977 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
2978 ; X86-BMI1NOTBM-NEXT: movl $-1, %eax
2979 ; X86-BMI1NOTBM-NEXT: movl $-1, %ebx
2980 ; X86-BMI1NOTBM-NEXT: shrl %cl, %ebx
2981 ; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %eax
2982 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
2983 ; X86-BMI1NOTBM-NEXT: je .LBB36_2
2984 ; X86-BMI1NOTBM-NEXT: # %bb.1:
2985 ; X86-BMI1NOTBM-NEXT: movl %ebx, %eax
2986 ; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx
2987 ; X86-BMI1NOTBM-NEXT: .LBB36_2:
2988 ; X86-BMI1NOTBM-NEXT: movl (%edx), %esi
2989 ; X86-BMI1NOTBM-NEXT: andl %eax, %esi
2990 ; X86-BMI1NOTBM-NEXT: movl 4(%edx), %edi
2991 ; X86-BMI1NOTBM-NEXT: andl %ebx, %edi
2992 ; X86-BMI1NOTBM-NEXT: subl $8, %esp
2993 ; X86-BMI1NOTBM-NEXT: pushl %ebx
2994 ; X86-BMI1NOTBM-NEXT: pushl %eax
2995 ; X86-BMI1NOTBM-NEXT: calll use64
2996 ; X86-BMI1NOTBM-NEXT: addl $16, %esp
2997 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
2998 ; X86-BMI1NOTBM-NEXT: movl %edi, %edx
2999 ; X86-BMI1NOTBM-NEXT: popl %esi
3000 ; X86-BMI1NOTBM-NEXT: popl %edi
3001 ; X86-BMI1NOTBM-NEXT: popl %ebx
3002 ; X86-BMI1NOTBM-NEXT: retl
3004 ; X86-BMI1BMI2-LABEL: bzhi64_c2_load:
3005 ; X86-BMI1BMI2: # %bb.0:
3006 ; X86-BMI1BMI2-NEXT: pushl %ebx
3007 ; X86-BMI1BMI2-NEXT: pushl %edi
3008 ; X86-BMI1BMI2-NEXT: pushl %esi
3009 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx
3010 ; X86-BMI1BMI2-NEXT: movb $64, %cl
3011 ; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl
3012 ; X86-BMI1BMI2-NEXT: movl $-1, %eax
3013 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %ebx
3014 ; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %eax
3015 ; X86-BMI1BMI2-NEXT: testb $32, %cl
3016 ; X86-BMI1BMI2-NEXT: je .LBB36_2
3017 ; X86-BMI1BMI2-NEXT: # %bb.1:
3018 ; X86-BMI1BMI2-NEXT: movl %ebx, %eax
3019 ; X86-BMI1BMI2-NEXT: xorl %ebx, %ebx
3020 ; X86-BMI1BMI2-NEXT: .LBB36_2:
3021 ; X86-BMI1BMI2-NEXT: movl (%edx), %esi
3022 ; X86-BMI1BMI2-NEXT: andl %eax, %esi
3023 ; X86-BMI1BMI2-NEXT: movl 4(%edx), %edi
3024 ; X86-BMI1BMI2-NEXT: andl %ebx, %edi
3025 ; X86-BMI1BMI2-NEXT: subl $8, %esp
3026 ; X86-BMI1BMI2-NEXT: pushl %ebx
3027 ; X86-BMI1BMI2-NEXT: pushl %eax
3028 ; X86-BMI1BMI2-NEXT: calll use64
3029 ; X86-BMI1BMI2-NEXT: addl $16, %esp
3030 ; X86-BMI1BMI2-NEXT: movl %esi, %eax
3031 ; X86-BMI1BMI2-NEXT: movl %edi, %edx
3032 ; X86-BMI1BMI2-NEXT: popl %esi
3033 ; X86-BMI1BMI2-NEXT: popl %edi
3034 ; X86-BMI1BMI2-NEXT: popl %ebx
3035 ; X86-BMI1BMI2-NEXT: retl
3037 ; X64-NOBMI-LABEL: bzhi64_c2_load:
3038 ; X64-NOBMI: # %bb.0:
3039 ; X64-NOBMI-NEXT: pushq %rbx
3040 ; X64-NOBMI-NEXT: movq %rsi, %rcx
3041 ; X64-NOBMI-NEXT: negb %cl
3042 ; X64-NOBMI-NEXT: movq $-1, %rax
3043 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
3044 ; X64-NOBMI-NEXT: shrq %cl, %rax
3045 ; X64-NOBMI-NEXT: movq (%rdi), %rbx
3046 ; X64-NOBMI-NEXT: andq %rax, %rbx
3047 ; X64-NOBMI-NEXT: movq %rax, %rdi
3048 ; X64-NOBMI-NEXT: callq use64
3049 ; X64-NOBMI-NEXT: movq %rbx, %rax
3050 ; X64-NOBMI-NEXT: popq %rbx
3051 ; X64-NOBMI-NEXT: retq
3053 ; X64-BMI1NOTBM-LABEL: bzhi64_c2_load:
3054 ; X64-BMI1NOTBM: # %bb.0:
3055 ; X64-BMI1NOTBM-NEXT: pushq %rbx
3056 ; X64-BMI1NOTBM-NEXT: movq %rsi, %rcx
3057 ; X64-BMI1NOTBM-NEXT: negb %cl
3058 ; X64-BMI1NOTBM-NEXT: movq $-1, %rax
3059 ; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $rcx
3060 ; X64-BMI1NOTBM-NEXT: shrq %cl, %rax
3061 ; X64-BMI1NOTBM-NEXT: movq (%rdi), %rbx
3062 ; X64-BMI1NOTBM-NEXT: andq %rax, %rbx
3063 ; X64-BMI1NOTBM-NEXT: movq %rax, %rdi
3064 ; X64-BMI1NOTBM-NEXT: callq use64
3065 ; X64-BMI1NOTBM-NEXT: movq %rbx, %rax
3066 ; X64-BMI1NOTBM-NEXT: popq %rbx
3067 ; X64-BMI1NOTBM-NEXT: retq
3069 ; X64-BMI1BMI2-LABEL: bzhi64_c2_load:
3070 ; X64-BMI1BMI2: # %bb.0:
3071 ; X64-BMI1BMI2-NEXT: pushq %rbx
3072 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, (%rdi), %rbx
3073 ; X64-BMI1BMI2-NEXT: # kill: def $sil killed $sil killed $rsi def $rsi
3074 ; X64-BMI1BMI2-NEXT: negb %sil
3075 ; X64-BMI1BMI2-NEXT: movq $-1, %rax
3076 ; X64-BMI1BMI2-NEXT: shrxq %rsi, %rax, %rdi
3077 ; X64-BMI1BMI2-NEXT: callq use64
3078 ; X64-BMI1BMI2-NEXT: movq %rbx, %rax
3079 ; X64-BMI1BMI2-NEXT: popq %rbx
3080 ; X64-BMI1BMI2-NEXT: retq
3081 %val = load i64, i64* %w
3082 %numhighbits = sub i64 64, %numlowbits
3083 %mask = lshr i64 -1, %numhighbits
3084 call void @use64(i64 %mask)
3085 %masked = and i64 %mask, %val
3089 define i64 @bzhi64_c3_load_indexzext(i64* %w, i8 %numlowbits) nounwind {
3090 ; X86-NOBMI-LABEL: bzhi64_c3_load_indexzext:
3091 ; X86-NOBMI: # %bb.0:
3092 ; X86-NOBMI-NEXT: pushl %ebx
3093 ; X86-NOBMI-NEXT: pushl %edi
3094 ; X86-NOBMI-NEXT: pushl %esi
3095 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx
3096 ; X86-NOBMI-NEXT: movb $64, %cl
3097 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
3098 ; X86-NOBMI-NEXT: movl $-1, %eax
3099 ; X86-NOBMI-NEXT: movl $-1, %ebx
3100 ; X86-NOBMI-NEXT: shrl %cl, %ebx
3101 ; X86-NOBMI-NEXT: shrdl %cl, %eax, %eax
3102 ; X86-NOBMI-NEXT: testb $32, %cl
3103 ; X86-NOBMI-NEXT: je .LBB37_2
3104 ; X86-NOBMI-NEXT: # %bb.1:
3105 ; X86-NOBMI-NEXT: movl %ebx, %eax
3106 ; X86-NOBMI-NEXT: xorl %ebx, %ebx
3107 ; X86-NOBMI-NEXT: .LBB37_2:
3108 ; X86-NOBMI-NEXT: movl (%edx), %esi
3109 ; X86-NOBMI-NEXT: andl %eax, %esi
3110 ; X86-NOBMI-NEXT: movl 4(%edx), %edi
3111 ; X86-NOBMI-NEXT: andl %ebx, %edi
3112 ; X86-NOBMI-NEXT: subl $8, %esp
3113 ; X86-NOBMI-NEXT: pushl %ebx
3114 ; X86-NOBMI-NEXT: pushl %eax
3115 ; X86-NOBMI-NEXT: calll use64
3116 ; X86-NOBMI-NEXT: addl $16, %esp
3117 ; X86-NOBMI-NEXT: movl %esi, %eax
3118 ; X86-NOBMI-NEXT: movl %edi, %edx
3119 ; X86-NOBMI-NEXT: popl %esi
3120 ; X86-NOBMI-NEXT: popl %edi
3121 ; X86-NOBMI-NEXT: popl %ebx
3122 ; X86-NOBMI-NEXT: retl
3124 ; X86-BMI1NOTBM-LABEL: bzhi64_c3_load_indexzext:
3125 ; X86-BMI1NOTBM: # %bb.0:
3126 ; X86-BMI1NOTBM-NEXT: pushl %ebx
3127 ; X86-BMI1NOTBM-NEXT: pushl %edi
3128 ; X86-BMI1NOTBM-NEXT: pushl %esi
3129 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edx
3130 ; X86-BMI1NOTBM-NEXT: movb $64, %cl
3131 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
3132 ; X86-BMI1NOTBM-NEXT: movl $-1, %eax
3133 ; X86-BMI1NOTBM-NEXT: movl $-1, %ebx
3134 ; X86-BMI1NOTBM-NEXT: shrl %cl, %ebx
3135 ; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %eax
3136 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
3137 ; X86-BMI1NOTBM-NEXT: je .LBB37_2
3138 ; X86-BMI1NOTBM-NEXT: # %bb.1:
3139 ; X86-BMI1NOTBM-NEXT: movl %ebx, %eax
3140 ; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx
3141 ; X86-BMI1NOTBM-NEXT: .LBB37_2:
3142 ; X86-BMI1NOTBM-NEXT: movl (%edx), %esi
3143 ; X86-BMI1NOTBM-NEXT: andl %eax, %esi
3144 ; X86-BMI1NOTBM-NEXT: movl 4(%edx), %edi
3145 ; X86-BMI1NOTBM-NEXT: andl %ebx, %edi
3146 ; X86-BMI1NOTBM-NEXT: subl $8, %esp
3147 ; X86-BMI1NOTBM-NEXT: pushl %ebx
3148 ; X86-BMI1NOTBM-NEXT: pushl %eax
3149 ; X86-BMI1NOTBM-NEXT: calll use64
3150 ; X86-BMI1NOTBM-NEXT: addl $16, %esp
3151 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
3152 ; X86-BMI1NOTBM-NEXT: movl %edi, %edx
3153 ; X86-BMI1NOTBM-NEXT: popl %esi
3154 ; X86-BMI1NOTBM-NEXT: popl %edi
3155 ; X86-BMI1NOTBM-NEXT: popl %ebx
3156 ; X86-BMI1NOTBM-NEXT: retl
3158 ; X86-BMI1BMI2-LABEL: bzhi64_c3_load_indexzext:
3159 ; X86-BMI1BMI2: # %bb.0:
3160 ; X86-BMI1BMI2-NEXT: pushl %ebx
3161 ; X86-BMI1BMI2-NEXT: pushl %edi
3162 ; X86-BMI1BMI2-NEXT: pushl %esi
3163 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx
3164 ; X86-BMI1BMI2-NEXT: movb $64, %cl
3165 ; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl
3166 ; X86-BMI1BMI2-NEXT: movl $-1, %eax
3167 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %eax, %ebx
3168 ; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %eax
3169 ; X86-BMI1BMI2-NEXT: testb $32, %cl
3170 ; X86-BMI1BMI2-NEXT: je .LBB37_2
3171 ; X86-BMI1BMI2-NEXT: # %bb.1:
3172 ; X86-BMI1BMI2-NEXT: movl %ebx, %eax
3173 ; X86-BMI1BMI2-NEXT: xorl %ebx, %ebx
3174 ; X86-BMI1BMI2-NEXT: .LBB37_2:
3175 ; X86-BMI1BMI2-NEXT: movl (%edx), %esi
3176 ; X86-BMI1BMI2-NEXT: andl %eax, %esi
3177 ; X86-BMI1BMI2-NEXT: movl 4(%edx), %edi
3178 ; X86-BMI1BMI2-NEXT: andl %ebx, %edi
3179 ; X86-BMI1BMI2-NEXT: subl $8, %esp
3180 ; X86-BMI1BMI2-NEXT: pushl %ebx
3181 ; X86-BMI1BMI2-NEXT: pushl %eax
3182 ; X86-BMI1BMI2-NEXT: calll use64
3183 ; X86-BMI1BMI2-NEXT: addl $16, %esp
3184 ; X86-BMI1BMI2-NEXT: movl %esi, %eax
3185 ; X86-BMI1BMI2-NEXT: movl %edi, %edx
3186 ; X86-BMI1BMI2-NEXT: popl %esi
3187 ; X86-BMI1BMI2-NEXT: popl %edi
3188 ; X86-BMI1BMI2-NEXT: popl %ebx
3189 ; X86-BMI1BMI2-NEXT: retl
3191 ; X64-NOBMI-LABEL: bzhi64_c3_load_indexzext:
3192 ; X64-NOBMI: # %bb.0:
3193 ; X64-NOBMI-NEXT: pushq %rbx
3194 ; X64-NOBMI-NEXT: movl %esi, %ecx
3195 ; X64-NOBMI-NEXT: negb %cl
3196 ; X64-NOBMI-NEXT: movq $-1, %rax
3197 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3198 ; X64-NOBMI-NEXT: shrq %cl, %rax
3199 ; X64-NOBMI-NEXT: movq (%rdi), %rbx
3200 ; X64-NOBMI-NEXT: andq %rax, %rbx
3201 ; X64-NOBMI-NEXT: movq %rax, %rdi
3202 ; X64-NOBMI-NEXT: callq use64
3203 ; X64-NOBMI-NEXT: movq %rbx, %rax
3204 ; X64-NOBMI-NEXT: popq %rbx
3205 ; X64-NOBMI-NEXT: retq
3207 ; X64-BMI1NOTBM-LABEL: bzhi64_c3_load_indexzext:
3208 ; X64-BMI1NOTBM: # %bb.0:
3209 ; X64-BMI1NOTBM-NEXT: pushq %rbx
3210 ; X64-BMI1NOTBM-NEXT: movl %esi, %ecx
3211 ; X64-BMI1NOTBM-NEXT: negb %cl
3212 ; X64-BMI1NOTBM-NEXT: movq $-1, %rax
3213 ; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $ecx
3214 ; X64-BMI1NOTBM-NEXT: shrq %cl, %rax
3215 ; X64-BMI1NOTBM-NEXT: movq (%rdi), %rbx
3216 ; X64-BMI1NOTBM-NEXT: andq %rax, %rbx
3217 ; X64-BMI1NOTBM-NEXT: movq %rax, %rdi
3218 ; X64-BMI1NOTBM-NEXT: callq use64
3219 ; X64-BMI1NOTBM-NEXT: movq %rbx, %rax
3220 ; X64-BMI1NOTBM-NEXT: popq %rbx
3221 ; X64-BMI1NOTBM-NEXT: retq
3223 ; X64-BMI1BMI2-LABEL: bzhi64_c3_load_indexzext:
3224 ; X64-BMI1BMI2: # %bb.0:
3225 ; X64-BMI1BMI2-NEXT: pushq %rbx
3226 ; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi
3227 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, (%rdi), %rbx
3228 ; X64-BMI1BMI2-NEXT: # kill: def $sil killed $sil killed $rsi def $rsi
3229 ; X64-BMI1BMI2-NEXT: negb %sil
3230 ; X64-BMI1BMI2-NEXT: movq $-1, %rax
3231 ; X64-BMI1BMI2-NEXT: shrxq %rsi, %rax, %rdi
3232 ; X64-BMI1BMI2-NEXT: callq use64
3233 ; X64-BMI1BMI2-NEXT: movq %rbx, %rax
3234 ; X64-BMI1BMI2-NEXT: popq %rbx
3235 ; X64-BMI1BMI2-NEXT: retq
3236 %val = load i64, i64* %w
3237 %numhighbits = sub i8 64, %numlowbits
3238 %sh_prom = zext i8 %numhighbits to i64
3239 %mask = lshr i64 -1, %sh_prom
3240 call void @use64(i64 %mask)
3241 %masked = and i64 %mask, %val
3245 define i64 @bzhi64_c4_commutative(i64 %val, i64 %numlowbits) nounwind {
3246 ; X86-NOBMI-LABEL: bzhi64_c4_commutative:
3247 ; X86-NOBMI: # %bb.0:
3248 ; X86-NOBMI-NEXT: pushl %edi
3249 ; X86-NOBMI-NEXT: pushl %esi
3250 ; X86-NOBMI-NEXT: pushl %eax
3251 ; X86-NOBMI-NEXT: movb $64, %cl
3252 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
3253 ; X86-NOBMI-NEXT: movl $-1, %esi
3254 ; X86-NOBMI-NEXT: movl $-1, %edi
3255 ; X86-NOBMI-NEXT: shrl %cl, %edi
3256 ; X86-NOBMI-NEXT: shrdl %cl, %esi, %esi
3257 ; X86-NOBMI-NEXT: testb $32, %cl
3258 ; X86-NOBMI-NEXT: je .LBB38_2
3259 ; X86-NOBMI-NEXT: # %bb.1:
3260 ; X86-NOBMI-NEXT: movl %edi, %esi
3261 ; X86-NOBMI-NEXT: xorl %edi, %edi
3262 ; X86-NOBMI-NEXT: .LBB38_2:
3263 ; X86-NOBMI-NEXT: subl $8, %esp
3264 ; X86-NOBMI-NEXT: pushl %edi
3265 ; X86-NOBMI-NEXT: pushl %esi
3266 ; X86-NOBMI-NEXT: calll use64
3267 ; X86-NOBMI-NEXT: addl $16, %esp
3268 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %esi
3269 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %edi
3270 ; X86-NOBMI-NEXT: movl %esi, %eax
3271 ; X86-NOBMI-NEXT: movl %edi, %edx
3272 ; X86-NOBMI-NEXT: addl $4, %esp
3273 ; X86-NOBMI-NEXT: popl %esi
3274 ; X86-NOBMI-NEXT: popl %edi
3275 ; X86-NOBMI-NEXT: retl
3277 ; X86-BMI1NOTBM-LABEL: bzhi64_c4_commutative:
3278 ; X86-BMI1NOTBM: # %bb.0:
3279 ; X86-BMI1NOTBM-NEXT: pushl %edi
3280 ; X86-BMI1NOTBM-NEXT: pushl %esi
3281 ; X86-BMI1NOTBM-NEXT: pushl %eax
3282 ; X86-BMI1NOTBM-NEXT: movb $64, %cl
3283 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
3284 ; X86-BMI1NOTBM-NEXT: movl $-1, %esi
3285 ; X86-BMI1NOTBM-NEXT: movl $-1, %edi
3286 ; X86-BMI1NOTBM-NEXT: shrl %cl, %edi
3287 ; X86-BMI1NOTBM-NEXT: shrdl %cl, %esi, %esi
3288 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
3289 ; X86-BMI1NOTBM-NEXT: je .LBB38_2
3290 ; X86-BMI1NOTBM-NEXT: # %bb.1:
3291 ; X86-BMI1NOTBM-NEXT: movl %edi, %esi
3292 ; X86-BMI1NOTBM-NEXT: xorl %edi, %edi
3293 ; X86-BMI1NOTBM-NEXT: .LBB38_2:
3294 ; X86-BMI1NOTBM-NEXT: subl $8, %esp
3295 ; X86-BMI1NOTBM-NEXT: pushl %edi
3296 ; X86-BMI1NOTBM-NEXT: pushl %esi
3297 ; X86-BMI1NOTBM-NEXT: calll use64
3298 ; X86-BMI1NOTBM-NEXT: addl $16, %esp
3299 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %esi
3300 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %edi
3301 ; X86-BMI1NOTBM-NEXT: movl %esi, %eax
3302 ; X86-BMI1NOTBM-NEXT: movl %edi, %edx
3303 ; X86-BMI1NOTBM-NEXT: addl $4, %esp
3304 ; X86-BMI1NOTBM-NEXT: popl %esi
3305 ; X86-BMI1NOTBM-NEXT: popl %edi
3306 ; X86-BMI1NOTBM-NEXT: retl
3308 ; X86-BMI1BMI2-LABEL: bzhi64_c4_commutative:
3309 ; X86-BMI1BMI2: # %bb.0:
3310 ; X86-BMI1BMI2-NEXT: pushl %edi
3311 ; X86-BMI1BMI2-NEXT: pushl %esi
3312 ; X86-BMI1BMI2-NEXT: pushl %eax
3313 ; X86-BMI1BMI2-NEXT: movb $64, %cl
3314 ; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl
3315 ; X86-BMI1BMI2-NEXT: movl $-1, %esi
3316 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %edi
3317 ; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %esi
3318 ; X86-BMI1BMI2-NEXT: testb $32, %cl
3319 ; X86-BMI1BMI2-NEXT: je .LBB38_2
3320 ; X86-BMI1BMI2-NEXT: # %bb.1:
3321 ; X86-BMI1BMI2-NEXT: movl %edi, %esi
3322 ; X86-BMI1BMI2-NEXT: xorl %edi, %edi
3323 ; X86-BMI1BMI2-NEXT: .LBB38_2:
3324 ; X86-BMI1BMI2-NEXT: subl $8, %esp
3325 ; X86-BMI1BMI2-NEXT: pushl %edi
3326 ; X86-BMI1BMI2-NEXT: pushl %esi
3327 ; X86-BMI1BMI2-NEXT: calll use64
3328 ; X86-BMI1BMI2-NEXT: addl $16, %esp
3329 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %esi
3330 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %edi
3331 ; X86-BMI1BMI2-NEXT: movl %esi, %eax
3332 ; X86-BMI1BMI2-NEXT: movl %edi, %edx
3333 ; X86-BMI1BMI2-NEXT: addl $4, %esp
3334 ; X86-BMI1BMI2-NEXT: popl %esi
3335 ; X86-BMI1BMI2-NEXT: popl %edi
3336 ; X86-BMI1BMI2-NEXT: retl
3338 ; X64-NOBMI-LABEL: bzhi64_c4_commutative:
3339 ; X64-NOBMI: # %bb.0:
3340 ; X64-NOBMI-NEXT: pushq %r14
3341 ; X64-NOBMI-NEXT: pushq %rbx
3342 ; X64-NOBMI-NEXT: pushq %rax
3343 ; X64-NOBMI-NEXT: movq %rsi, %rcx
3344 ; X64-NOBMI-NEXT: movq %rdi, %r14
3345 ; X64-NOBMI-NEXT: negb %cl
3346 ; X64-NOBMI-NEXT: movq $-1, %rbx
3347 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
3348 ; X64-NOBMI-NEXT: shrq %cl, %rbx
3349 ; X64-NOBMI-NEXT: movq %rbx, %rdi
3350 ; X64-NOBMI-NEXT: callq use64
3351 ; X64-NOBMI-NEXT: andq %r14, %rbx
3352 ; X64-NOBMI-NEXT: movq %rbx, %rax
3353 ; X64-NOBMI-NEXT: addq $8, %rsp
3354 ; X64-NOBMI-NEXT: popq %rbx
3355 ; X64-NOBMI-NEXT: popq %r14
3356 ; X64-NOBMI-NEXT: retq
3358 ; X64-BMI1NOTBM-LABEL: bzhi64_c4_commutative:
3359 ; X64-BMI1NOTBM: # %bb.0:
3360 ; X64-BMI1NOTBM-NEXT: pushq %r14
3361 ; X64-BMI1NOTBM-NEXT: pushq %rbx
3362 ; X64-BMI1NOTBM-NEXT: pushq %rax
3363 ; X64-BMI1NOTBM-NEXT: movq %rsi, %rcx
3364 ; X64-BMI1NOTBM-NEXT: movq %rdi, %r14
3365 ; X64-BMI1NOTBM-NEXT: negb %cl
3366 ; X64-BMI1NOTBM-NEXT: movq $-1, %rbx
3367 ; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $rcx
3368 ; X64-BMI1NOTBM-NEXT: shrq %cl, %rbx
3369 ; X64-BMI1NOTBM-NEXT: movq %rbx, %rdi
3370 ; X64-BMI1NOTBM-NEXT: callq use64
3371 ; X64-BMI1NOTBM-NEXT: andq %r14, %rbx
3372 ; X64-BMI1NOTBM-NEXT: movq %rbx, %rax
3373 ; X64-BMI1NOTBM-NEXT: addq $8, %rsp
3374 ; X64-BMI1NOTBM-NEXT: popq %rbx
3375 ; X64-BMI1NOTBM-NEXT: popq %r14
3376 ; X64-BMI1NOTBM-NEXT: retq
3378 ; X64-BMI1BMI2-LABEL: bzhi64_c4_commutative:
3379 ; X64-BMI1BMI2: # %bb.0:
3380 ; X64-BMI1BMI2-NEXT: pushq %r14
3381 ; X64-BMI1BMI2-NEXT: pushq %rbx
3382 ; X64-BMI1BMI2-NEXT: pushq %rax
3383 ; X64-BMI1BMI2-NEXT: movq %rsi, %rbx
3384 ; X64-BMI1BMI2-NEXT: movq %rdi, %r14
3385 ; X64-BMI1BMI2-NEXT: movl %ebx, %eax
3386 ; X64-BMI1BMI2-NEXT: negb %al
3387 ; X64-BMI1BMI2-NEXT: movq $-1, %rcx
3388 ; X64-BMI1BMI2-NEXT: shrxq %rax, %rcx, %rdi
3389 ; X64-BMI1BMI2-NEXT: callq use64
3390 ; X64-BMI1BMI2-NEXT: bzhiq %rbx, %r14, %rax
3391 ; X64-BMI1BMI2-NEXT: addq $8, %rsp
3392 ; X64-BMI1BMI2-NEXT: popq %rbx
3393 ; X64-BMI1BMI2-NEXT: popq %r14
3394 ; X64-BMI1BMI2-NEXT: retq
3395 %numhighbits = sub i64 64, %numlowbits
3396 %mask = lshr i64 -1, %numhighbits
3397 call void @use64(i64 %mask)
3398 %masked = and i64 %val, %mask ; swapped order
3402 ; 64-bit, but with 32-bit output
3404 ; Everything done in 64-bit, truncation happens last.
3405 define i32 @bzhi64_32_c0(i64 %val, i64 %numlowbits) nounwind {
3406 ; X86-NOBMI-LABEL: bzhi64_32_c0:
3407 ; X86-NOBMI: # %bb.0:
3408 ; X86-NOBMI-NEXT: movb $64, %cl
3409 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
3410 ; X86-NOBMI-NEXT: movl $-1, %edx
3411 ; X86-NOBMI-NEXT: movl $-1, %eax
3412 ; X86-NOBMI-NEXT: shrl %cl, %eax
3413 ; X86-NOBMI-NEXT: shrdl %cl, %edx, %edx
3414 ; X86-NOBMI-NEXT: testb $32, %cl
3415 ; X86-NOBMI-NEXT: jne .LBB39_2
3416 ; X86-NOBMI-NEXT: # %bb.1:
3417 ; X86-NOBMI-NEXT: movl %edx, %eax
3418 ; X86-NOBMI-NEXT: .LBB39_2:
3419 ; X86-NOBMI-NEXT: andl {{[0-9]+}}(%esp), %eax
3420 ; X86-NOBMI-NEXT: retl
3422 ; X86-BMI1NOTBM-LABEL: bzhi64_32_c0:
3423 ; X86-BMI1NOTBM: # %bb.0:
3424 ; X86-BMI1NOTBM-NEXT: movb $64, %cl
3425 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
3426 ; X86-BMI1NOTBM-NEXT: movl $-1, %edx
3427 ; X86-BMI1NOTBM-NEXT: movl $-1, %eax
3428 ; X86-BMI1NOTBM-NEXT: shrl %cl, %eax
3429 ; X86-BMI1NOTBM-NEXT: shrdl %cl, %edx, %edx
3430 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
3431 ; X86-BMI1NOTBM-NEXT: jne .LBB39_2
3432 ; X86-BMI1NOTBM-NEXT: # %bb.1:
3433 ; X86-BMI1NOTBM-NEXT: movl %edx, %eax
3434 ; X86-BMI1NOTBM-NEXT: .LBB39_2:
3435 ; X86-BMI1NOTBM-NEXT: andl {{[0-9]+}}(%esp), %eax
3436 ; X86-BMI1NOTBM-NEXT: retl
3438 ; X86-BMI1BMI2-LABEL: bzhi64_32_c0:
3439 ; X86-BMI1BMI2: # %bb.0:
3440 ; X86-BMI1BMI2-NEXT: movb $64, %cl
3441 ; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl
3442 ; X86-BMI1BMI2-NEXT: movl $-1, %edx
3443 ; X86-BMI1BMI2-NEXT: movl $-1, %eax
3444 ; X86-BMI1BMI2-NEXT: shrdl %cl, %eax, %eax
3445 ; X86-BMI1BMI2-NEXT: testb $32, %cl
3446 ; X86-BMI1BMI2-NEXT: je .LBB39_2
3447 ; X86-BMI1BMI2-NEXT: # %bb.1:
3448 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %eax
3449 ; X86-BMI1BMI2-NEXT: .LBB39_2:
3450 ; X86-BMI1BMI2-NEXT: andl {{[0-9]+}}(%esp), %eax
3451 ; X86-BMI1BMI2-NEXT: retl
3453 ; X64-NOBMI-LABEL: bzhi64_32_c0:
3454 ; X64-NOBMI: # %bb.0:
3455 ; X64-NOBMI-NEXT: movq %rsi, %rcx
3456 ; X64-NOBMI-NEXT: negb %cl
3457 ; X64-NOBMI-NEXT: movq $-1, %rax
3458 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
3459 ; X64-NOBMI-NEXT: shrq %cl, %rax
3460 ; X64-NOBMI-NEXT: andl %edi, %eax
3461 ; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax
3462 ; X64-NOBMI-NEXT: retq
3464 ; X64-BMI1NOTBM-LABEL: bzhi64_32_c0:
3465 ; X64-BMI1NOTBM: # %bb.0:
3466 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
3467 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
3468 ; X64-BMI1NOTBM-NEXT: retq
3470 ; X64-BMI1BMI2-LABEL: bzhi64_32_c0:
3471 ; X64-BMI1BMI2: # %bb.0:
3472 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
3473 ; X64-BMI1BMI2-NEXT: retq
3474 %numhighbits = sub i64 64, %numlowbits
3475 %mask = lshr i64 -1, %numhighbits
3476 %masked = and i64 %mask, %val
3477 %res = trunc i64 %masked to i32
3481 ; Shifting happens in 64-bit, then truncation. Masking is 32-bit.
3482 define i32 @bzhi64_32_c1(i64 %val, i32 %numlowbits) nounwind {
3483 ; X86-NOBMI-LABEL: bzhi64_32_c1:
3484 ; X86-NOBMI: # %bb.0:
3485 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
3486 ; X86-NOBMI-NEXT: xorl %ecx, %ecx
3487 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
3488 ; X86-NOBMI-NEXT: shll %cl, %eax
3489 ; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3490 ; X86-NOBMI-NEXT: shrl %cl, %eax
3491 ; X86-NOBMI-NEXT: retl
3493 ; X86-BMI1NOTBM-LABEL: bzhi64_32_c1:
3494 ; X86-BMI1NOTBM: # %bb.0:
3495 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
3496 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
3497 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
3498 ; X86-BMI1NOTBM-NEXT: retl
3500 ; X86-BMI1BMI2-LABEL: bzhi64_32_c1:
3501 ; X86-BMI1BMI2: # %bb.0:
3502 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
3503 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
3504 ; X86-BMI1BMI2-NEXT: retl
3506 ; X64-NOBMI-LABEL: bzhi64_32_c1:
3507 ; X64-NOBMI: # %bb.0:
3508 ; X64-NOBMI-NEXT: movl %esi, %ecx
3509 ; X64-NOBMI-NEXT: movq %rdi, %rax
3510 ; X64-NOBMI-NEXT: negb %cl
3511 ; X64-NOBMI-NEXT: shll %cl, %eax
3512 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3513 ; X64-NOBMI-NEXT: shrl %cl, %eax
3514 ; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax
3515 ; X64-NOBMI-NEXT: retq
3517 ; X64-BMI1NOTBM-LABEL: bzhi64_32_c1:
3518 ; X64-BMI1NOTBM: # %bb.0:
3519 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
3520 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
3521 ; X64-BMI1NOTBM-NEXT: retq
3523 ; X64-BMI1BMI2-LABEL: bzhi64_32_c1:
3524 ; X64-BMI1BMI2: # %bb.0:
3525 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
3526 ; X64-BMI1BMI2-NEXT: retq
3527 %truncval = trunc i64 %val to i32
3528 %numhighbits = sub i32 32, %numlowbits
3529 %mask = lshr i32 -1, %numhighbits
3530 %masked = and i32 %mask, %truncval
3534 ; Shifting happens in 64-bit. Mask is 32-bit, but extended to 64-bit.
3535 ; Masking is 64-bit. Then truncation.
3536 define i32 @bzhi64_32_c2(i64 %val, i32 %numlowbits) nounwind {
3537 ; X86-NOBMI-LABEL: bzhi64_32_c2:
3538 ; X86-NOBMI: # %bb.0:
3539 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
3540 ; X86-NOBMI-NEXT: xorl %ecx, %ecx
3541 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
3542 ; X86-NOBMI-NEXT: shll %cl, %eax
3543 ; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3544 ; X86-NOBMI-NEXT: shrl %cl, %eax
3545 ; X86-NOBMI-NEXT: retl
3547 ; X86-BMI1NOTBM-LABEL: bzhi64_32_c2:
3548 ; X86-BMI1NOTBM: # %bb.0:
3549 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
3550 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
3551 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
3552 ; X86-BMI1NOTBM-NEXT: retl
3554 ; X86-BMI1BMI2-LABEL: bzhi64_32_c2:
3555 ; X86-BMI1BMI2: # %bb.0:
3556 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
3557 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
3558 ; X86-BMI1BMI2-NEXT: retl
3560 ; X64-NOBMI-LABEL: bzhi64_32_c2:
3561 ; X64-NOBMI: # %bb.0:
3562 ; X64-NOBMI-NEXT: movl %esi, %ecx
3563 ; X64-NOBMI-NEXT: movq %rdi, %rax
3564 ; X64-NOBMI-NEXT: negb %cl
3565 ; X64-NOBMI-NEXT: shll %cl, %eax
3566 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3567 ; X64-NOBMI-NEXT: shrl %cl, %eax
3568 ; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax
3569 ; X64-NOBMI-NEXT: retq
3571 ; X64-BMI1NOTBM-LABEL: bzhi64_32_c2:
3572 ; X64-BMI1NOTBM: # %bb.0:
3573 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
3574 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
3575 ; X64-BMI1NOTBM-NEXT: retq
3577 ; X64-BMI1BMI2-LABEL: bzhi64_32_c2:
3578 ; X64-BMI1BMI2: # %bb.0:
3579 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
3580 ; X64-BMI1BMI2-NEXT: retq
3581 %numhighbits = sub i32 32, %numlowbits
3582 %mask = lshr i32 -1, %numhighbits
3583 %zextmask = zext i32 %mask to i64
3584 %masked = and i64 %zextmask, %val
3585 %truncmasked = trunc i64 %masked to i32
3586 ret i32 %truncmasked
3589 ; Shifting happens in 64-bit. Mask is 32-bit, but calculated in 64-bit.
3590 ; Masking is 64-bit. Then truncation.
3591 define i32 @bzhi64_32_c3(i64 %val, i64 %numlowbits) nounwind {
3592 ; X86-LABEL: bzhi64_32_c3:
3594 ; X86-NEXT: movb $64, %cl
3595 ; X86-NEXT: subb {{[0-9]+}}(%esp), %cl
3596 ; X86-NEXT: xorl %eax, %eax
3597 ; X86-NEXT: movl $-1, %edx
3598 ; X86-NEXT: shrdl %cl, %eax, %edx
3599 ; X86-NEXT: testb $32, %cl
3600 ; X86-NEXT: jne .LBB42_2
3601 ; X86-NEXT: # %bb.1:
3602 ; X86-NEXT: movl %edx, %eax
3603 ; X86-NEXT: .LBB42_2:
3604 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
3607 ; X64-NOBMI-LABEL: bzhi64_32_c3:
3608 ; X64-NOBMI: # %bb.0:
3609 ; X64-NOBMI-NEXT: movq %rsi, %rcx
3610 ; X64-NOBMI-NEXT: negb %cl
3611 ; X64-NOBMI-NEXT: movl $4294967295, %eax # imm = 0xFFFFFFFF
3612 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
3613 ; X64-NOBMI-NEXT: shrq %cl, %rax
3614 ; X64-NOBMI-NEXT: andl %edi, %eax
3615 ; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax
3616 ; X64-NOBMI-NEXT: retq
3618 ; X64-BMI1NOTBM-LABEL: bzhi64_32_c3:
3619 ; X64-BMI1NOTBM: # %bb.0:
3620 ; X64-BMI1NOTBM-NEXT: movq %rsi, %rcx
3621 ; X64-BMI1NOTBM-NEXT: negb %cl
3622 ; X64-BMI1NOTBM-NEXT: movl $4294967295, %eax # imm = 0xFFFFFFFF
3623 ; X64-BMI1NOTBM-NEXT: # kill: def $cl killed $cl killed $rcx
3624 ; X64-BMI1NOTBM-NEXT: shrq %cl, %rax
3625 ; X64-BMI1NOTBM-NEXT: andl %edi, %eax
3626 ; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax
3627 ; X64-BMI1NOTBM-NEXT: retq
3629 ; X64-BMI1BMI2-LABEL: bzhi64_32_c3:
3630 ; X64-BMI1BMI2: # %bb.0:
3631 ; X64-BMI1BMI2-NEXT: negb %sil
3632 ; X64-BMI1BMI2-NEXT: movl $4294967295, %eax # imm = 0xFFFFFFFF
3633 ; X64-BMI1BMI2-NEXT: shrxq %rsi, %rax, %rax
3634 ; X64-BMI1BMI2-NEXT: andl %edi, %eax
3635 ; X64-BMI1BMI2-NEXT: # kill: def $eax killed $eax killed $rax
3636 ; X64-BMI1BMI2-NEXT: retq
3637 %numhighbits = sub i64 64, %numlowbits
3638 %mask = lshr i64 4294967295, %numhighbits
3639 %masked = and i64 %mask, %val
3640 %truncmasked = trunc i64 %masked to i32
3641 ret i32 %truncmasked
3644 ; ---------------------------------------------------------------------------- ;
3645 ; Pattern d. 32-bit.
3646 ; ---------------------------------------------------------------------------- ;
3648 define i32 @bzhi32_d0(i32 %val, i32 %numlowbits) nounwind {
3649 ; X86-NOBMI-LABEL: bzhi32_d0:
3650 ; X86-NOBMI: # %bb.0:
3651 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
3652 ; X86-NOBMI-NEXT: xorl %ecx, %ecx
3653 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
3654 ; X86-NOBMI-NEXT: shll %cl, %eax
3655 ; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3656 ; X86-NOBMI-NEXT: shrl %cl, %eax
3657 ; X86-NOBMI-NEXT: retl
3659 ; X86-BMI1NOTBM-LABEL: bzhi32_d0:
3660 ; X86-BMI1NOTBM: # %bb.0:
3661 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
3662 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
3663 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
3664 ; X86-BMI1NOTBM-NEXT: retl
3666 ; X86-BMI1BMI2-LABEL: bzhi32_d0:
3667 ; X86-BMI1BMI2: # %bb.0:
3668 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
3669 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
3670 ; X86-BMI1BMI2-NEXT: retl
3672 ; X64-NOBMI-LABEL: bzhi32_d0:
3673 ; X64-NOBMI: # %bb.0:
3674 ; X64-NOBMI-NEXT: movl %esi, %ecx
3675 ; X64-NOBMI-NEXT: movl %edi, %eax
3676 ; X64-NOBMI-NEXT: negb %cl
3677 ; X64-NOBMI-NEXT: shll %cl, %eax
3678 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3679 ; X64-NOBMI-NEXT: shrl %cl, %eax
3680 ; X64-NOBMI-NEXT: retq
3682 ; X64-BMI1NOTBM-LABEL: bzhi32_d0:
3683 ; X64-BMI1NOTBM: # %bb.0:
3684 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
3685 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
3686 ; X64-BMI1NOTBM-NEXT: retq
3688 ; X64-BMI1BMI2-LABEL: bzhi32_d0:
3689 ; X64-BMI1BMI2: # %bb.0:
3690 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
3691 ; X64-BMI1BMI2-NEXT: retq
3692 %numhighbits = sub i32 32, %numlowbits
3693 %highbitscleared = shl i32 %val, %numhighbits
3694 %masked = lshr i32 %highbitscleared, %numhighbits
3698 define i32 @bzhi32_d1_indexzext(i32 %val, i8 %numlowbits) nounwind {
3699 ; X86-NOBMI-LABEL: bzhi32_d1_indexzext:
3700 ; X86-NOBMI: # %bb.0:
3701 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
3702 ; X86-NOBMI-NEXT: xorl %ecx, %ecx
3703 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
3704 ; X86-NOBMI-NEXT: shll %cl, %eax
3705 ; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3706 ; X86-NOBMI-NEXT: shrl %cl, %eax
3707 ; X86-NOBMI-NEXT: retl
3709 ; X86-BMI1NOTBM-LABEL: bzhi32_d1_indexzext:
3710 ; X86-BMI1NOTBM: # %bb.0:
3711 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
3712 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
3713 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
3714 ; X86-BMI1NOTBM-NEXT: retl
3716 ; X86-BMI1BMI2-LABEL: bzhi32_d1_indexzext:
3717 ; X86-BMI1BMI2: # %bb.0:
3718 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
3719 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
3720 ; X86-BMI1BMI2-NEXT: retl
3722 ; X64-NOBMI-LABEL: bzhi32_d1_indexzext:
3723 ; X64-NOBMI: # %bb.0:
3724 ; X64-NOBMI-NEXT: movl %esi, %ecx
3725 ; X64-NOBMI-NEXT: movl %edi, %eax
3726 ; X64-NOBMI-NEXT: negb %cl
3727 ; X64-NOBMI-NEXT: shll %cl, %eax
3728 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3729 ; X64-NOBMI-NEXT: shrl %cl, %eax
3730 ; X64-NOBMI-NEXT: retq
3732 ; X64-BMI1NOTBM-LABEL: bzhi32_d1_indexzext:
3733 ; X64-BMI1NOTBM: # %bb.0:
3734 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
3735 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
3736 ; X64-BMI1NOTBM-NEXT: retq
3738 ; X64-BMI1BMI2-LABEL: bzhi32_d1_indexzext:
3739 ; X64-BMI1BMI2: # %bb.0:
3740 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
3741 ; X64-BMI1BMI2-NEXT: retq
3742 %numhighbits = sub i8 32, %numlowbits
3743 %sh_prom = zext i8 %numhighbits to i32
3744 %highbitscleared = shl i32 %val, %sh_prom
3745 %masked = lshr i32 %highbitscleared, %sh_prom
3749 define i32 @bzhi32_d2_load(i32* %w, i32 %numlowbits) nounwind {
3750 ; X86-NOBMI-LABEL: bzhi32_d2_load:
3751 ; X86-NOBMI: # %bb.0:
3752 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
3753 ; X86-NOBMI-NEXT: movl (%eax), %eax
3754 ; X86-NOBMI-NEXT: xorl %ecx, %ecx
3755 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
3756 ; X86-NOBMI-NEXT: shll %cl, %eax
3757 ; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3758 ; X86-NOBMI-NEXT: shrl %cl, %eax
3759 ; X86-NOBMI-NEXT: retl
3761 ; X86-BMI1NOTBM-LABEL: bzhi32_d2_load:
3762 ; X86-BMI1NOTBM: # %bb.0:
3763 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
3764 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
3765 ; X86-BMI1NOTBM-NEXT: shll $8, %ecx
3766 ; X86-BMI1NOTBM-NEXT: bextrl %ecx, (%eax), %eax
3767 ; X86-BMI1NOTBM-NEXT: retl
3769 ; X86-BMI1BMI2-LABEL: bzhi32_d2_load:
3770 ; X86-BMI1BMI2: # %bb.0:
3771 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
3772 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
3773 ; X86-BMI1BMI2-NEXT: bzhil %ecx, (%eax), %eax
3774 ; X86-BMI1BMI2-NEXT: retl
3776 ; X64-NOBMI-LABEL: bzhi32_d2_load:
3777 ; X64-NOBMI: # %bb.0:
3778 ; X64-NOBMI-NEXT: movl %esi, %ecx
3779 ; X64-NOBMI-NEXT: movl (%rdi), %eax
3780 ; X64-NOBMI-NEXT: negb %cl
3781 ; X64-NOBMI-NEXT: shll %cl, %eax
3782 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3783 ; X64-NOBMI-NEXT: shrl %cl, %eax
3784 ; X64-NOBMI-NEXT: retq
3786 ; X64-BMI1NOTBM-LABEL: bzhi32_d2_load:
3787 ; X64-BMI1NOTBM: # %bb.0:
3788 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
3789 ; X64-BMI1NOTBM-NEXT: bextrl %esi, (%rdi), %eax
3790 ; X64-BMI1NOTBM-NEXT: retq
3792 ; X64-BMI1BMI2-LABEL: bzhi32_d2_load:
3793 ; X64-BMI1BMI2: # %bb.0:
3794 ; X64-BMI1BMI2-NEXT: bzhil %esi, (%rdi), %eax
3795 ; X64-BMI1BMI2-NEXT: retq
3796 %val = load i32, i32* %w
3797 %numhighbits = sub i32 32, %numlowbits
3798 %highbitscleared = shl i32 %val, %numhighbits
3799 %masked = lshr i32 %highbitscleared, %numhighbits
3803 define i32 @bzhi32_d3_load_indexzext(i32* %w, i8 %numlowbits) nounwind {
3804 ; X86-NOBMI-LABEL: bzhi32_d3_load_indexzext:
3805 ; X86-NOBMI: # %bb.0:
3806 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
3807 ; X86-NOBMI-NEXT: movl (%eax), %eax
3808 ; X86-NOBMI-NEXT: xorl %ecx, %ecx
3809 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
3810 ; X86-NOBMI-NEXT: shll %cl, %eax
3811 ; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3812 ; X86-NOBMI-NEXT: shrl %cl, %eax
3813 ; X86-NOBMI-NEXT: retl
3815 ; X86-BMI1NOTBM-LABEL: bzhi32_d3_load_indexzext:
3816 ; X86-BMI1NOTBM: # %bb.0:
3817 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
3818 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %cl
3819 ; X86-BMI1NOTBM-NEXT: shll $8, %ecx
3820 ; X86-BMI1NOTBM-NEXT: bextrl %ecx, (%eax), %eax
3821 ; X86-BMI1NOTBM-NEXT: retl
3823 ; X86-BMI1BMI2-LABEL: bzhi32_d3_load_indexzext:
3824 ; X86-BMI1BMI2: # %bb.0:
3825 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
3826 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %cl
3827 ; X86-BMI1BMI2-NEXT: bzhil %ecx, (%eax), %eax
3828 ; X86-BMI1BMI2-NEXT: retl
3830 ; X64-NOBMI-LABEL: bzhi32_d3_load_indexzext:
3831 ; X64-NOBMI: # %bb.0:
3832 ; X64-NOBMI-NEXT: movl %esi, %ecx
3833 ; X64-NOBMI-NEXT: movl (%rdi), %eax
3834 ; X64-NOBMI-NEXT: negb %cl
3835 ; X64-NOBMI-NEXT: shll %cl, %eax
3836 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
3837 ; X64-NOBMI-NEXT: shrl %cl, %eax
3838 ; X64-NOBMI-NEXT: retq
3840 ; X64-BMI1NOTBM-LABEL: bzhi32_d3_load_indexzext:
3841 ; X64-BMI1NOTBM: # %bb.0:
3842 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
3843 ; X64-BMI1NOTBM-NEXT: bextrl %esi, (%rdi), %eax
3844 ; X64-BMI1NOTBM-NEXT: retq
3846 ; X64-BMI1BMI2-LABEL: bzhi32_d3_load_indexzext:
3847 ; X64-BMI1BMI2: # %bb.0:
3848 ; X64-BMI1BMI2-NEXT: bzhil %esi, (%rdi), %eax
3849 ; X64-BMI1BMI2-NEXT: retq
3850 %val = load i32, i32* %w
3851 %numhighbits = sub i8 32, %numlowbits
3852 %sh_prom = zext i8 %numhighbits to i32
3853 %highbitscleared = shl i32 %val, %sh_prom
3854 %masked = lshr i32 %highbitscleared, %sh_prom
3860 define i64 @bzhi64_d0(i64 %val, i64 %numlowbits) nounwind {
3861 ; X86-NOBMI-LABEL: bzhi64_d0:
3862 ; X86-NOBMI: # %bb.0:
3863 ; X86-NOBMI-NEXT: pushl %ebx
3864 ; X86-NOBMI-NEXT: pushl %edi
3865 ; X86-NOBMI-NEXT: pushl %esi
3866 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx
3867 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
3868 ; X86-NOBMI-NEXT: movb $64, %cl
3869 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
3870 ; X86-NOBMI-NEXT: movl %edx, %esi
3871 ; X86-NOBMI-NEXT: shll %cl, %esi
3872 ; X86-NOBMI-NEXT: shldl %cl, %edx, %eax
3873 ; X86-NOBMI-NEXT: testb $32, %cl
3874 ; X86-NOBMI-NEXT: movl %esi, %edi
3875 ; X86-NOBMI-NEXT: jne .LBB47_2
3876 ; X86-NOBMI-NEXT: # %bb.1:
3877 ; X86-NOBMI-NEXT: movl %eax, %edi
3878 ; X86-NOBMI-NEXT: .LBB47_2:
3879 ; X86-NOBMI-NEXT: movl %edi, %eax
3880 ; X86-NOBMI-NEXT: shrl %cl, %eax
3881 ; X86-NOBMI-NEXT: xorl %ebx, %ebx
3882 ; X86-NOBMI-NEXT: testb $32, %cl
3883 ; X86-NOBMI-NEXT: movl $0, %edx
3884 ; X86-NOBMI-NEXT: jne .LBB47_4
3885 ; X86-NOBMI-NEXT: # %bb.3:
3886 ; X86-NOBMI-NEXT: movl %esi, %ebx
3887 ; X86-NOBMI-NEXT: movl %eax, %edx
3888 ; X86-NOBMI-NEXT: .LBB47_4:
3889 ; X86-NOBMI-NEXT: shrdl %cl, %edi, %ebx
3890 ; X86-NOBMI-NEXT: testb $32, %cl
3891 ; X86-NOBMI-NEXT: jne .LBB47_6
3892 ; X86-NOBMI-NEXT: # %bb.5:
3893 ; X86-NOBMI-NEXT: movl %ebx, %eax
3894 ; X86-NOBMI-NEXT: .LBB47_6:
3895 ; X86-NOBMI-NEXT: popl %esi
3896 ; X86-NOBMI-NEXT: popl %edi
3897 ; X86-NOBMI-NEXT: popl %ebx
3898 ; X86-NOBMI-NEXT: retl
3900 ; X86-BMI1NOTBM-LABEL: bzhi64_d0:
3901 ; X86-BMI1NOTBM: # %bb.0:
3902 ; X86-BMI1NOTBM-NEXT: pushl %ebx
3903 ; X86-BMI1NOTBM-NEXT: pushl %edi
3904 ; X86-BMI1NOTBM-NEXT: pushl %esi
3905 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edx
3906 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
3907 ; X86-BMI1NOTBM-NEXT: movb $64, %cl
3908 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
3909 ; X86-BMI1NOTBM-NEXT: movl %edx, %esi
3910 ; X86-BMI1NOTBM-NEXT: shll %cl, %esi
3911 ; X86-BMI1NOTBM-NEXT: shldl %cl, %edx, %eax
3912 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
3913 ; X86-BMI1NOTBM-NEXT: movl %esi, %edi
3914 ; X86-BMI1NOTBM-NEXT: jne .LBB47_2
3915 ; X86-BMI1NOTBM-NEXT: # %bb.1:
3916 ; X86-BMI1NOTBM-NEXT: movl %eax, %edi
3917 ; X86-BMI1NOTBM-NEXT: .LBB47_2:
3918 ; X86-BMI1NOTBM-NEXT: movl %edi, %eax
3919 ; X86-BMI1NOTBM-NEXT: shrl %cl, %eax
3920 ; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx
3921 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
3922 ; X86-BMI1NOTBM-NEXT: movl $0, %edx
3923 ; X86-BMI1NOTBM-NEXT: jne .LBB47_4
3924 ; X86-BMI1NOTBM-NEXT: # %bb.3:
3925 ; X86-BMI1NOTBM-NEXT: movl %esi, %ebx
3926 ; X86-BMI1NOTBM-NEXT: movl %eax, %edx
3927 ; X86-BMI1NOTBM-NEXT: .LBB47_4:
3928 ; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %ebx
3929 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
3930 ; X86-BMI1NOTBM-NEXT: jne .LBB47_6
3931 ; X86-BMI1NOTBM-NEXT: # %bb.5:
3932 ; X86-BMI1NOTBM-NEXT: movl %ebx, %eax
3933 ; X86-BMI1NOTBM-NEXT: .LBB47_6:
3934 ; X86-BMI1NOTBM-NEXT: popl %esi
3935 ; X86-BMI1NOTBM-NEXT: popl %edi
3936 ; X86-BMI1NOTBM-NEXT: popl %ebx
3937 ; X86-BMI1NOTBM-NEXT: retl
3939 ; X86-BMI1BMI2-LABEL: bzhi64_d0:
3940 ; X86-BMI1BMI2: # %bb.0:
3941 ; X86-BMI1BMI2-NEXT: pushl %edi
3942 ; X86-BMI1BMI2-NEXT: pushl %esi
3943 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
3944 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi
3945 ; X86-BMI1BMI2-NEXT: movb $64, %cl
3946 ; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl
3947 ; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %esi
3948 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %edi
3949 ; X86-BMI1BMI2-NEXT: xorl %edx, %edx
3950 ; X86-BMI1BMI2-NEXT: testb $32, %cl
3951 ; X86-BMI1BMI2-NEXT: je .LBB47_2
3952 ; X86-BMI1BMI2-NEXT: # %bb.1:
3953 ; X86-BMI1BMI2-NEXT: movl %edi, %esi
3954 ; X86-BMI1BMI2-NEXT: movl $0, %edi
3955 ; X86-BMI1BMI2-NEXT: .LBB47_2:
3956 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %eax
3957 ; X86-BMI1BMI2-NEXT: jne .LBB47_4
3958 ; X86-BMI1BMI2-NEXT: # %bb.3:
3959 ; X86-BMI1BMI2-NEXT: movl %eax, %edx
3960 ; X86-BMI1BMI2-NEXT: .LBB47_4:
3961 ; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edi
3962 ; X86-BMI1BMI2-NEXT: testb $32, %cl
3963 ; X86-BMI1BMI2-NEXT: jne .LBB47_6
3964 ; X86-BMI1BMI2-NEXT: # %bb.5:
3965 ; X86-BMI1BMI2-NEXT: movl %edi, %eax
3966 ; X86-BMI1BMI2-NEXT: .LBB47_6:
3967 ; X86-BMI1BMI2-NEXT: popl %esi
3968 ; X86-BMI1BMI2-NEXT: popl %edi
3969 ; X86-BMI1BMI2-NEXT: retl
3971 ; X64-NOBMI-LABEL: bzhi64_d0:
3972 ; X64-NOBMI: # %bb.0:
3973 ; X64-NOBMI-NEXT: movq %rsi, %rcx
3974 ; X64-NOBMI-NEXT: movq %rdi, %rax
3975 ; X64-NOBMI-NEXT: negb %cl
3976 ; X64-NOBMI-NEXT: shlq %cl, %rax
3977 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
3978 ; X64-NOBMI-NEXT: shrq %cl, %rax
3979 ; X64-NOBMI-NEXT: retq
3981 ; X64-BMI1NOTBM-LABEL: bzhi64_d0:
3982 ; X64-BMI1NOTBM: # %bb.0:
3983 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
3984 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, %rdi, %rax
3985 ; X64-BMI1NOTBM-NEXT: retq
3987 ; X64-BMI1BMI2-LABEL: bzhi64_d0:
3988 ; X64-BMI1BMI2: # %bb.0:
3989 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, %rdi, %rax
3990 ; X64-BMI1BMI2-NEXT: retq
3991 %numhighbits = sub i64 64, %numlowbits
3992 %highbitscleared = shl i64 %val, %numhighbits
3993 %masked = lshr i64 %highbitscleared, %numhighbits
3997 define i64 @bzhi64_d1_indexzext(i64 %val, i8 %numlowbits) nounwind {
3998 ; X86-NOBMI-LABEL: bzhi64_d1_indexzext:
3999 ; X86-NOBMI: # %bb.0:
4000 ; X86-NOBMI-NEXT: pushl %ebx
4001 ; X86-NOBMI-NEXT: pushl %edi
4002 ; X86-NOBMI-NEXT: pushl %esi
4003 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx
4004 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
4005 ; X86-NOBMI-NEXT: movb $64, %cl
4006 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
4007 ; X86-NOBMI-NEXT: movl %edx, %esi
4008 ; X86-NOBMI-NEXT: shll %cl, %esi
4009 ; X86-NOBMI-NEXT: shldl %cl, %edx, %eax
4010 ; X86-NOBMI-NEXT: testb $32, %cl
4011 ; X86-NOBMI-NEXT: movl %esi, %edi
4012 ; X86-NOBMI-NEXT: jne .LBB48_2
4013 ; X86-NOBMI-NEXT: # %bb.1:
4014 ; X86-NOBMI-NEXT: movl %eax, %edi
4015 ; X86-NOBMI-NEXT: .LBB48_2:
4016 ; X86-NOBMI-NEXT: movl %edi, %eax
4017 ; X86-NOBMI-NEXT: shrl %cl, %eax
4018 ; X86-NOBMI-NEXT: xorl %ebx, %ebx
4019 ; X86-NOBMI-NEXT: testb $32, %cl
4020 ; X86-NOBMI-NEXT: movl $0, %edx
4021 ; X86-NOBMI-NEXT: jne .LBB48_4
4022 ; X86-NOBMI-NEXT: # %bb.3:
4023 ; X86-NOBMI-NEXT: movl %esi, %ebx
4024 ; X86-NOBMI-NEXT: movl %eax, %edx
4025 ; X86-NOBMI-NEXT: .LBB48_4:
4026 ; X86-NOBMI-NEXT: shrdl %cl, %edi, %ebx
4027 ; X86-NOBMI-NEXT: testb $32, %cl
4028 ; X86-NOBMI-NEXT: jne .LBB48_6
4029 ; X86-NOBMI-NEXT: # %bb.5:
4030 ; X86-NOBMI-NEXT: movl %ebx, %eax
4031 ; X86-NOBMI-NEXT: .LBB48_6:
4032 ; X86-NOBMI-NEXT: popl %esi
4033 ; X86-NOBMI-NEXT: popl %edi
4034 ; X86-NOBMI-NEXT: popl %ebx
4035 ; X86-NOBMI-NEXT: retl
4037 ; X86-BMI1NOTBM-LABEL: bzhi64_d1_indexzext:
4038 ; X86-BMI1NOTBM: # %bb.0:
4039 ; X86-BMI1NOTBM-NEXT: pushl %ebx
4040 ; X86-BMI1NOTBM-NEXT: pushl %edi
4041 ; X86-BMI1NOTBM-NEXT: pushl %esi
4042 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %edx
4043 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
4044 ; X86-BMI1NOTBM-NEXT: movb $64, %cl
4045 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
4046 ; X86-BMI1NOTBM-NEXT: movl %edx, %esi
4047 ; X86-BMI1NOTBM-NEXT: shll %cl, %esi
4048 ; X86-BMI1NOTBM-NEXT: shldl %cl, %edx, %eax
4049 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
4050 ; X86-BMI1NOTBM-NEXT: movl %esi, %edi
4051 ; X86-BMI1NOTBM-NEXT: jne .LBB48_2
4052 ; X86-BMI1NOTBM-NEXT: # %bb.1:
4053 ; X86-BMI1NOTBM-NEXT: movl %eax, %edi
4054 ; X86-BMI1NOTBM-NEXT: .LBB48_2:
4055 ; X86-BMI1NOTBM-NEXT: movl %edi, %eax
4056 ; X86-BMI1NOTBM-NEXT: shrl %cl, %eax
4057 ; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx
4058 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
4059 ; X86-BMI1NOTBM-NEXT: movl $0, %edx
4060 ; X86-BMI1NOTBM-NEXT: jne .LBB48_4
4061 ; X86-BMI1NOTBM-NEXT: # %bb.3:
4062 ; X86-BMI1NOTBM-NEXT: movl %esi, %ebx
4063 ; X86-BMI1NOTBM-NEXT: movl %eax, %edx
4064 ; X86-BMI1NOTBM-NEXT: .LBB48_4:
4065 ; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %ebx
4066 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
4067 ; X86-BMI1NOTBM-NEXT: jne .LBB48_6
4068 ; X86-BMI1NOTBM-NEXT: # %bb.5:
4069 ; X86-BMI1NOTBM-NEXT: movl %ebx, %eax
4070 ; X86-BMI1NOTBM-NEXT: .LBB48_6:
4071 ; X86-BMI1NOTBM-NEXT: popl %esi
4072 ; X86-BMI1NOTBM-NEXT: popl %edi
4073 ; X86-BMI1NOTBM-NEXT: popl %ebx
4074 ; X86-BMI1NOTBM-NEXT: retl
4076 ; X86-BMI1BMI2-LABEL: bzhi64_d1_indexzext:
4077 ; X86-BMI1BMI2: # %bb.0:
4078 ; X86-BMI1BMI2-NEXT: pushl %edi
4079 ; X86-BMI1BMI2-NEXT: pushl %esi
4080 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
4081 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %esi
4082 ; X86-BMI1BMI2-NEXT: movb $64, %cl
4083 ; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl
4084 ; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %esi
4085 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %edi
4086 ; X86-BMI1BMI2-NEXT: xorl %edx, %edx
4087 ; X86-BMI1BMI2-NEXT: testb $32, %cl
4088 ; X86-BMI1BMI2-NEXT: je .LBB48_2
4089 ; X86-BMI1BMI2-NEXT: # %bb.1:
4090 ; X86-BMI1BMI2-NEXT: movl %edi, %esi
4091 ; X86-BMI1BMI2-NEXT: movl $0, %edi
4092 ; X86-BMI1BMI2-NEXT: .LBB48_2:
4093 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %eax
4094 ; X86-BMI1BMI2-NEXT: jne .LBB48_4
4095 ; X86-BMI1BMI2-NEXT: # %bb.3:
4096 ; X86-BMI1BMI2-NEXT: movl %eax, %edx
4097 ; X86-BMI1BMI2-NEXT: .LBB48_4:
4098 ; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edi
4099 ; X86-BMI1BMI2-NEXT: testb $32, %cl
4100 ; X86-BMI1BMI2-NEXT: jne .LBB48_6
4101 ; X86-BMI1BMI2-NEXT: # %bb.5:
4102 ; X86-BMI1BMI2-NEXT: movl %edi, %eax
4103 ; X86-BMI1BMI2-NEXT: .LBB48_6:
4104 ; X86-BMI1BMI2-NEXT: popl %esi
4105 ; X86-BMI1BMI2-NEXT: popl %edi
4106 ; X86-BMI1BMI2-NEXT: retl
4108 ; X64-NOBMI-LABEL: bzhi64_d1_indexzext:
4109 ; X64-NOBMI: # %bb.0:
4110 ; X64-NOBMI-NEXT: movl %esi, %ecx
4111 ; X64-NOBMI-NEXT: movq %rdi, %rax
4112 ; X64-NOBMI-NEXT: negb %cl
4113 ; X64-NOBMI-NEXT: shlq %cl, %rax
4114 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
4115 ; X64-NOBMI-NEXT: shrq %cl, %rax
4116 ; X64-NOBMI-NEXT: retq
4118 ; X64-BMI1NOTBM-LABEL: bzhi64_d1_indexzext:
4119 ; X64-BMI1NOTBM: # %bb.0:
4120 ; X64-BMI1NOTBM-NEXT: # kill: def $esi killed $esi def $rsi
4121 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
4122 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, %rdi, %rax
4123 ; X64-BMI1NOTBM-NEXT: retq
4125 ; X64-BMI1BMI2-LABEL: bzhi64_d1_indexzext:
4126 ; X64-BMI1BMI2: # %bb.0:
4127 ; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi
4128 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, %rdi, %rax
4129 ; X64-BMI1BMI2-NEXT: retq
4130 %numhighbits = sub i8 64, %numlowbits
4131 %sh_prom = zext i8 %numhighbits to i64
4132 %highbitscleared = shl i64 %val, %sh_prom
4133 %masked = lshr i64 %highbitscleared, %sh_prom
4137 define i64 @bzhi64_d2_load(i64* %w, i64 %numlowbits) nounwind {
4138 ; X86-NOBMI-LABEL: bzhi64_d2_load:
4139 ; X86-NOBMI: # %bb.0:
4140 ; X86-NOBMI-NEXT: pushl %ebx
4141 ; X86-NOBMI-NEXT: pushl %edi
4142 ; X86-NOBMI-NEXT: pushl %esi
4143 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
4144 ; X86-NOBMI-NEXT: movl (%eax), %edx
4145 ; X86-NOBMI-NEXT: movl 4(%eax), %eax
4146 ; X86-NOBMI-NEXT: movb $64, %cl
4147 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
4148 ; X86-NOBMI-NEXT: movl %edx, %esi
4149 ; X86-NOBMI-NEXT: shll %cl, %esi
4150 ; X86-NOBMI-NEXT: shldl %cl, %edx, %eax
4151 ; X86-NOBMI-NEXT: testb $32, %cl
4152 ; X86-NOBMI-NEXT: movl %esi, %edi
4153 ; X86-NOBMI-NEXT: jne .LBB49_2
4154 ; X86-NOBMI-NEXT: # %bb.1:
4155 ; X86-NOBMI-NEXT: movl %eax, %edi
4156 ; X86-NOBMI-NEXT: .LBB49_2:
4157 ; X86-NOBMI-NEXT: movl %edi, %eax
4158 ; X86-NOBMI-NEXT: shrl %cl, %eax
4159 ; X86-NOBMI-NEXT: xorl %ebx, %ebx
4160 ; X86-NOBMI-NEXT: testb $32, %cl
4161 ; X86-NOBMI-NEXT: movl $0, %edx
4162 ; X86-NOBMI-NEXT: jne .LBB49_4
4163 ; X86-NOBMI-NEXT: # %bb.3:
4164 ; X86-NOBMI-NEXT: movl %esi, %ebx
4165 ; X86-NOBMI-NEXT: movl %eax, %edx
4166 ; X86-NOBMI-NEXT: .LBB49_4:
4167 ; X86-NOBMI-NEXT: shrdl %cl, %edi, %ebx
4168 ; X86-NOBMI-NEXT: testb $32, %cl
4169 ; X86-NOBMI-NEXT: jne .LBB49_6
4170 ; X86-NOBMI-NEXT: # %bb.5:
4171 ; X86-NOBMI-NEXT: movl %ebx, %eax
4172 ; X86-NOBMI-NEXT: .LBB49_6:
4173 ; X86-NOBMI-NEXT: popl %esi
4174 ; X86-NOBMI-NEXT: popl %edi
4175 ; X86-NOBMI-NEXT: popl %ebx
4176 ; X86-NOBMI-NEXT: retl
4178 ; X86-BMI1NOTBM-LABEL: bzhi64_d2_load:
4179 ; X86-BMI1NOTBM: # %bb.0:
4180 ; X86-BMI1NOTBM-NEXT: pushl %ebx
4181 ; X86-BMI1NOTBM-NEXT: pushl %edi
4182 ; X86-BMI1NOTBM-NEXT: pushl %esi
4183 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
4184 ; X86-BMI1NOTBM-NEXT: movl (%eax), %edx
4185 ; X86-BMI1NOTBM-NEXT: movl 4(%eax), %eax
4186 ; X86-BMI1NOTBM-NEXT: movb $64, %cl
4187 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
4188 ; X86-BMI1NOTBM-NEXT: movl %edx, %esi
4189 ; X86-BMI1NOTBM-NEXT: shll %cl, %esi
4190 ; X86-BMI1NOTBM-NEXT: shldl %cl, %edx, %eax
4191 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
4192 ; X86-BMI1NOTBM-NEXT: movl %esi, %edi
4193 ; X86-BMI1NOTBM-NEXT: jne .LBB49_2
4194 ; X86-BMI1NOTBM-NEXT: # %bb.1:
4195 ; X86-BMI1NOTBM-NEXT: movl %eax, %edi
4196 ; X86-BMI1NOTBM-NEXT: .LBB49_2:
4197 ; X86-BMI1NOTBM-NEXT: movl %edi, %eax
4198 ; X86-BMI1NOTBM-NEXT: shrl %cl, %eax
4199 ; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx
4200 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
4201 ; X86-BMI1NOTBM-NEXT: movl $0, %edx
4202 ; X86-BMI1NOTBM-NEXT: jne .LBB49_4
4203 ; X86-BMI1NOTBM-NEXT: # %bb.3:
4204 ; X86-BMI1NOTBM-NEXT: movl %esi, %ebx
4205 ; X86-BMI1NOTBM-NEXT: movl %eax, %edx
4206 ; X86-BMI1NOTBM-NEXT: .LBB49_4:
4207 ; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %ebx
4208 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
4209 ; X86-BMI1NOTBM-NEXT: jne .LBB49_6
4210 ; X86-BMI1NOTBM-NEXT: # %bb.5:
4211 ; X86-BMI1NOTBM-NEXT: movl %ebx, %eax
4212 ; X86-BMI1NOTBM-NEXT: .LBB49_6:
4213 ; X86-BMI1NOTBM-NEXT: popl %esi
4214 ; X86-BMI1NOTBM-NEXT: popl %edi
4215 ; X86-BMI1NOTBM-NEXT: popl %ebx
4216 ; X86-BMI1NOTBM-NEXT: retl
4218 ; X86-BMI1BMI2-LABEL: bzhi64_d2_load:
4219 ; X86-BMI1BMI2: # %bb.0:
4220 ; X86-BMI1BMI2-NEXT: pushl %edi
4221 ; X86-BMI1BMI2-NEXT: pushl %esi
4222 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
4223 ; X86-BMI1BMI2-NEXT: movl (%eax), %edx
4224 ; X86-BMI1BMI2-NEXT: movl 4(%eax), %esi
4225 ; X86-BMI1BMI2-NEXT: movb $64, %cl
4226 ; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl
4227 ; X86-BMI1BMI2-NEXT: shldl %cl, %edx, %esi
4228 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %edx, %edi
4229 ; X86-BMI1BMI2-NEXT: xorl %edx, %edx
4230 ; X86-BMI1BMI2-NEXT: testb $32, %cl
4231 ; X86-BMI1BMI2-NEXT: je .LBB49_2
4232 ; X86-BMI1BMI2-NEXT: # %bb.1:
4233 ; X86-BMI1BMI2-NEXT: movl %edi, %esi
4234 ; X86-BMI1BMI2-NEXT: movl $0, %edi
4235 ; X86-BMI1BMI2-NEXT: .LBB49_2:
4236 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %eax
4237 ; X86-BMI1BMI2-NEXT: jne .LBB49_4
4238 ; X86-BMI1BMI2-NEXT: # %bb.3:
4239 ; X86-BMI1BMI2-NEXT: movl %eax, %edx
4240 ; X86-BMI1BMI2-NEXT: .LBB49_4:
4241 ; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edi
4242 ; X86-BMI1BMI2-NEXT: testb $32, %cl
4243 ; X86-BMI1BMI2-NEXT: jne .LBB49_6
4244 ; X86-BMI1BMI2-NEXT: # %bb.5:
4245 ; X86-BMI1BMI2-NEXT: movl %edi, %eax
4246 ; X86-BMI1BMI2-NEXT: .LBB49_6:
4247 ; X86-BMI1BMI2-NEXT: popl %esi
4248 ; X86-BMI1BMI2-NEXT: popl %edi
4249 ; X86-BMI1BMI2-NEXT: retl
4251 ; X64-NOBMI-LABEL: bzhi64_d2_load:
4252 ; X64-NOBMI: # %bb.0:
4253 ; X64-NOBMI-NEXT: movq %rsi, %rcx
4254 ; X64-NOBMI-NEXT: movq (%rdi), %rax
4255 ; X64-NOBMI-NEXT: negb %cl
4256 ; X64-NOBMI-NEXT: shlq %cl, %rax
4257 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
4258 ; X64-NOBMI-NEXT: shrq %cl, %rax
4259 ; X64-NOBMI-NEXT: retq
4261 ; X64-BMI1NOTBM-LABEL: bzhi64_d2_load:
4262 ; X64-BMI1NOTBM: # %bb.0:
4263 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
4264 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, (%rdi), %rax
4265 ; X64-BMI1NOTBM-NEXT: retq
4267 ; X64-BMI1BMI2-LABEL: bzhi64_d2_load:
4268 ; X64-BMI1BMI2: # %bb.0:
4269 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, (%rdi), %rax
4270 ; X64-BMI1BMI2-NEXT: retq
4271 %val = load i64, i64* %w
4272 %numhighbits = sub i64 64, %numlowbits
4273 %highbitscleared = shl i64 %val, %numhighbits
4274 %masked = lshr i64 %highbitscleared, %numhighbits
4278 define i64 @bzhi64_d3_load_indexzext(i64* %w, i8 %numlowbits) nounwind {
4279 ; X86-NOBMI-LABEL: bzhi64_d3_load_indexzext:
4280 ; X86-NOBMI: # %bb.0:
4281 ; X86-NOBMI-NEXT: pushl %ebx
4282 ; X86-NOBMI-NEXT: pushl %edi
4283 ; X86-NOBMI-NEXT: pushl %esi
4284 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
4285 ; X86-NOBMI-NEXT: movl (%eax), %edx
4286 ; X86-NOBMI-NEXT: movl 4(%eax), %eax
4287 ; X86-NOBMI-NEXT: movb $64, %cl
4288 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
4289 ; X86-NOBMI-NEXT: movl %edx, %esi
4290 ; X86-NOBMI-NEXT: shll %cl, %esi
4291 ; X86-NOBMI-NEXT: shldl %cl, %edx, %eax
4292 ; X86-NOBMI-NEXT: testb $32, %cl
4293 ; X86-NOBMI-NEXT: movl %esi, %edi
4294 ; X86-NOBMI-NEXT: jne .LBB50_2
4295 ; X86-NOBMI-NEXT: # %bb.1:
4296 ; X86-NOBMI-NEXT: movl %eax, %edi
4297 ; X86-NOBMI-NEXT: .LBB50_2:
4298 ; X86-NOBMI-NEXT: movl %edi, %eax
4299 ; X86-NOBMI-NEXT: shrl %cl, %eax
4300 ; X86-NOBMI-NEXT: xorl %ebx, %ebx
4301 ; X86-NOBMI-NEXT: testb $32, %cl
4302 ; X86-NOBMI-NEXT: movl $0, %edx
4303 ; X86-NOBMI-NEXT: jne .LBB50_4
4304 ; X86-NOBMI-NEXT: # %bb.3:
4305 ; X86-NOBMI-NEXT: movl %esi, %ebx
4306 ; X86-NOBMI-NEXT: movl %eax, %edx
4307 ; X86-NOBMI-NEXT: .LBB50_4:
4308 ; X86-NOBMI-NEXT: shrdl %cl, %edi, %ebx
4309 ; X86-NOBMI-NEXT: testb $32, %cl
4310 ; X86-NOBMI-NEXT: jne .LBB50_6
4311 ; X86-NOBMI-NEXT: # %bb.5:
4312 ; X86-NOBMI-NEXT: movl %ebx, %eax
4313 ; X86-NOBMI-NEXT: .LBB50_6:
4314 ; X86-NOBMI-NEXT: popl %esi
4315 ; X86-NOBMI-NEXT: popl %edi
4316 ; X86-NOBMI-NEXT: popl %ebx
4317 ; X86-NOBMI-NEXT: retl
4319 ; X86-BMI1NOTBM-LABEL: bzhi64_d3_load_indexzext:
4320 ; X86-BMI1NOTBM: # %bb.0:
4321 ; X86-BMI1NOTBM-NEXT: pushl %ebx
4322 ; X86-BMI1NOTBM-NEXT: pushl %edi
4323 ; X86-BMI1NOTBM-NEXT: pushl %esi
4324 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
4325 ; X86-BMI1NOTBM-NEXT: movl (%eax), %edx
4326 ; X86-BMI1NOTBM-NEXT: movl 4(%eax), %eax
4327 ; X86-BMI1NOTBM-NEXT: movb $64, %cl
4328 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
4329 ; X86-BMI1NOTBM-NEXT: movl %edx, %esi
4330 ; X86-BMI1NOTBM-NEXT: shll %cl, %esi
4331 ; X86-BMI1NOTBM-NEXT: shldl %cl, %edx, %eax
4332 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
4333 ; X86-BMI1NOTBM-NEXT: movl %esi, %edi
4334 ; X86-BMI1NOTBM-NEXT: jne .LBB50_2
4335 ; X86-BMI1NOTBM-NEXT: # %bb.1:
4336 ; X86-BMI1NOTBM-NEXT: movl %eax, %edi
4337 ; X86-BMI1NOTBM-NEXT: .LBB50_2:
4338 ; X86-BMI1NOTBM-NEXT: movl %edi, %eax
4339 ; X86-BMI1NOTBM-NEXT: shrl %cl, %eax
4340 ; X86-BMI1NOTBM-NEXT: xorl %ebx, %ebx
4341 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
4342 ; X86-BMI1NOTBM-NEXT: movl $0, %edx
4343 ; X86-BMI1NOTBM-NEXT: jne .LBB50_4
4344 ; X86-BMI1NOTBM-NEXT: # %bb.3:
4345 ; X86-BMI1NOTBM-NEXT: movl %esi, %ebx
4346 ; X86-BMI1NOTBM-NEXT: movl %eax, %edx
4347 ; X86-BMI1NOTBM-NEXT: .LBB50_4:
4348 ; X86-BMI1NOTBM-NEXT: shrdl %cl, %edi, %ebx
4349 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
4350 ; X86-BMI1NOTBM-NEXT: jne .LBB50_6
4351 ; X86-BMI1NOTBM-NEXT: # %bb.5:
4352 ; X86-BMI1NOTBM-NEXT: movl %ebx, %eax
4353 ; X86-BMI1NOTBM-NEXT: .LBB50_6:
4354 ; X86-BMI1NOTBM-NEXT: popl %esi
4355 ; X86-BMI1NOTBM-NEXT: popl %edi
4356 ; X86-BMI1NOTBM-NEXT: popl %ebx
4357 ; X86-BMI1NOTBM-NEXT: retl
4359 ; X86-BMI1BMI2-LABEL: bzhi64_d3_load_indexzext:
4360 ; X86-BMI1BMI2: # %bb.0:
4361 ; X86-BMI1BMI2-NEXT: pushl %edi
4362 ; X86-BMI1BMI2-NEXT: pushl %esi
4363 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
4364 ; X86-BMI1BMI2-NEXT: movl (%eax), %edx
4365 ; X86-BMI1BMI2-NEXT: movl 4(%eax), %esi
4366 ; X86-BMI1BMI2-NEXT: movb $64, %cl
4367 ; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl
4368 ; X86-BMI1BMI2-NEXT: shldl %cl, %edx, %esi
4369 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %edx, %edi
4370 ; X86-BMI1BMI2-NEXT: xorl %edx, %edx
4371 ; X86-BMI1BMI2-NEXT: testb $32, %cl
4372 ; X86-BMI1BMI2-NEXT: je .LBB50_2
4373 ; X86-BMI1BMI2-NEXT: # %bb.1:
4374 ; X86-BMI1BMI2-NEXT: movl %edi, %esi
4375 ; X86-BMI1BMI2-NEXT: movl $0, %edi
4376 ; X86-BMI1BMI2-NEXT: .LBB50_2:
4377 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %esi, %eax
4378 ; X86-BMI1BMI2-NEXT: jne .LBB50_4
4379 ; X86-BMI1BMI2-NEXT: # %bb.3:
4380 ; X86-BMI1BMI2-NEXT: movl %eax, %edx
4381 ; X86-BMI1BMI2-NEXT: .LBB50_4:
4382 ; X86-BMI1BMI2-NEXT: shrdl %cl, %esi, %edi
4383 ; X86-BMI1BMI2-NEXT: testb $32, %cl
4384 ; X86-BMI1BMI2-NEXT: jne .LBB50_6
4385 ; X86-BMI1BMI2-NEXT: # %bb.5:
4386 ; X86-BMI1BMI2-NEXT: movl %edi, %eax
4387 ; X86-BMI1BMI2-NEXT: .LBB50_6:
4388 ; X86-BMI1BMI2-NEXT: popl %esi
4389 ; X86-BMI1BMI2-NEXT: popl %edi
4390 ; X86-BMI1BMI2-NEXT: retl
4392 ; X64-NOBMI-LABEL: bzhi64_d3_load_indexzext:
4393 ; X64-NOBMI: # %bb.0:
4394 ; X64-NOBMI-NEXT: movl %esi, %ecx
4395 ; X64-NOBMI-NEXT: movq (%rdi), %rax
4396 ; X64-NOBMI-NEXT: negb %cl
4397 ; X64-NOBMI-NEXT: shlq %cl, %rax
4398 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
4399 ; X64-NOBMI-NEXT: shrq %cl, %rax
4400 ; X64-NOBMI-NEXT: retq
4402 ; X64-BMI1NOTBM-LABEL: bzhi64_d3_load_indexzext:
4403 ; X64-BMI1NOTBM: # %bb.0:
4404 ; X64-BMI1NOTBM-NEXT: # kill: def $esi killed $esi def $rsi
4405 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
4406 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, (%rdi), %rax
4407 ; X64-BMI1NOTBM-NEXT: retq
4409 ; X64-BMI1BMI2-LABEL: bzhi64_d3_load_indexzext:
4410 ; X64-BMI1BMI2: # %bb.0:
4411 ; X64-BMI1BMI2-NEXT: # kill: def $esi killed $esi def $rsi
4412 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, (%rdi), %rax
4413 ; X64-BMI1BMI2-NEXT: retq
4414 %val = load i64, i64* %w
4415 %numhighbits = sub i8 64, %numlowbits
4416 %sh_prom = zext i8 %numhighbits to i64
4417 %highbitscleared = shl i64 %val, %sh_prom
4418 %masked = lshr i64 %highbitscleared, %sh_prom
4422 ; 64-bit, but with 32-bit output
4424 ; Everything done in 64-bit, truncation happens last.
4425 define i32 @bzhi64_32_d0(i64 %val, i64 %numlowbits) nounwind {
4426 ; X86-NOBMI-LABEL: bzhi64_32_d0:
4427 ; X86-NOBMI: # %bb.0:
4428 ; X86-NOBMI-NEXT: pushl %esi
4429 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi
4430 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
4431 ; X86-NOBMI-NEXT: movb $64, %cl
4432 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
4433 ; X86-NOBMI-NEXT: movl %esi, %edx
4434 ; X86-NOBMI-NEXT: shll %cl, %edx
4435 ; X86-NOBMI-NEXT: shldl %cl, %esi, %eax
4436 ; X86-NOBMI-NEXT: testb $32, %cl
4437 ; X86-NOBMI-NEXT: je .LBB51_2
4438 ; X86-NOBMI-NEXT: # %bb.1:
4439 ; X86-NOBMI-NEXT: movl %edx, %eax
4440 ; X86-NOBMI-NEXT: xorl %edx, %edx
4441 ; X86-NOBMI-NEXT: .LBB51_2:
4442 ; X86-NOBMI-NEXT: shrdl %cl, %eax, %edx
4443 ; X86-NOBMI-NEXT: shrl %cl, %eax
4444 ; X86-NOBMI-NEXT: testb $32, %cl
4445 ; X86-NOBMI-NEXT: jne .LBB51_4
4446 ; X86-NOBMI-NEXT: # %bb.3:
4447 ; X86-NOBMI-NEXT: movl %edx, %eax
4448 ; X86-NOBMI-NEXT: .LBB51_4:
4449 ; X86-NOBMI-NEXT: popl %esi
4450 ; X86-NOBMI-NEXT: retl
4452 ; X86-BMI1NOTBM-LABEL: bzhi64_32_d0:
4453 ; X86-BMI1NOTBM: # %bb.0:
4454 ; X86-BMI1NOTBM-NEXT: pushl %esi
4455 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %esi
4456 ; X86-BMI1NOTBM-NEXT: movl {{[0-9]+}}(%esp), %eax
4457 ; X86-BMI1NOTBM-NEXT: movb $64, %cl
4458 ; X86-BMI1NOTBM-NEXT: subb {{[0-9]+}}(%esp), %cl
4459 ; X86-BMI1NOTBM-NEXT: movl %esi, %edx
4460 ; X86-BMI1NOTBM-NEXT: shll %cl, %edx
4461 ; X86-BMI1NOTBM-NEXT: shldl %cl, %esi, %eax
4462 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
4463 ; X86-BMI1NOTBM-NEXT: je .LBB51_2
4464 ; X86-BMI1NOTBM-NEXT: # %bb.1:
4465 ; X86-BMI1NOTBM-NEXT: movl %edx, %eax
4466 ; X86-BMI1NOTBM-NEXT: xorl %edx, %edx
4467 ; X86-BMI1NOTBM-NEXT: .LBB51_2:
4468 ; X86-BMI1NOTBM-NEXT: shrdl %cl, %eax, %edx
4469 ; X86-BMI1NOTBM-NEXT: shrl %cl, %eax
4470 ; X86-BMI1NOTBM-NEXT: testb $32, %cl
4471 ; X86-BMI1NOTBM-NEXT: jne .LBB51_4
4472 ; X86-BMI1NOTBM-NEXT: # %bb.3:
4473 ; X86-BMI1NOTBM-NEXT: movl %edx, %eax
4474 ; X86-BMI1NOTBM-NEXT: .LBB51_4:
4475 ; X86-BMI1NOTBM-NEXT: popl %esi
4476 ; X86-BMI1NOTBM-NEXT: retl
4478 ; X86-BMI1BMI2-LABEL: bzhi64_32_d0:
4479 ; X86-BMI1BMI2: # %bb.0:
4480 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %eax
4481 ; X86-BMI1BMI2-NEXT: movl {{[0-9]+}}(%esp), %edx
4482 ; X86-BMI1BMI2-NEXT: movb $64, %cl
4483 ; X86-BMI1BMI2-NEXT: subb {{[0-9]+}}(%esp), %cl
4484 ; X86-BMI1BMI2-NEXT: shldl %cl, %eax, %edx
4485 ; X86-BMI1BMI2-NEXT: shlxl %ecx, %eax, %eax
4486 ; X86-BMI1BMI2-NEXT: testb $32, %cl
4487 ; X86-BMI1BMI2-NEXT: je .LBB51_2
4488 ; X86-BMI1BMI2-NEXT: # %bb.1:
4489 ; X86-BMI1BMI2-NEXT: movl %eax, %edx
4490 ; X86-BMI1BMI2-NEXT: xorl %eax, %eax
4491 ; X86-BMI1BMI2-NEXT: .LBB51_2:
4492 ; X86-BMI1BMI2-NEXT: shrdl %cl, %edx, %eax
4493 ; X86-BMI1BMI2-NEXT: testb $32, %cl
4494 ; X86-BMI1BMI2-NEXT: je .LBB51_4
4495 ; X86-BMI1BMI2-NEXT: # %bb.3:
4496 ; X86-BMI1BMI2-NEXT: shrxl %ecx, %edx, %eax
4497 ; X86-BMI1BMI2-NEXT: .LBB51_4:
4498 ; X86-BMI1BMI2-NEXT: retl
4500 ; X64-NOBMI-LABEL: bzhi64_32_d0:
4501 ; X64-NOBMI: # %bb.0:
4502 ; X64-NOBMI-NEXT: movq %rsi, %rcx
4503 ; X64-NOBMI-NEXT: movq %rdi, %rax
4504 ; X64-NOBMI-NEXT: negb %cl
4505 ; X64-NOBMI-NEXT: shlq %cl, %rax
4506 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $rcx
4507 ; X64-NOBMI-NEXT: shrq %cl, %rax
4508 ; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax
4509 ; X64-NOBMI-NEXT: retq
4511 ; X64-BMI1NOTBM-LABEL: bzhi64_32_d0:
4512 ; X64-BMI1NOTBM: # %bb.0:
4513 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
4514 ; X64-BMI1NOTBM-NEXT: bextrq %rsi, %rdi, %rax
4515 ; X64-BMI1NOTBM-NEXT: # kill: def $eax killed $eax killed $rax
4516 ; X64-BMI1NOTBM-NEXT: retq
4518 ; X64-BMI1BMI2-LABEL: bzhi64_32_d0:
4519 ; X64-BMI1BMI2: # %bb.0:
4520 ; X64-BMI1BMI2-NEXT: bzhiq %rsi, %rdi, %rax
4521 ; X64-BMI1BMI2-NEXT: # kill: def $eax killed $eax killed $rax
4522 ; X64-BMI1BMI2-NEXT: retq
4523 %numhighbits = sub i64 64, %numlowbits
4524 %highbitscleared = shl i64 %val, %numhighbits
4525 %masked = lshr i64 %highbitscleared, %numhighbits
4526 %res = trunc i64 %masked to i32
4530 ; Shifting happens in 64-bit, then truncation. Masking is 32-bit.
4531 define i32 @bzhi64_32_d1(i64 %val, i32 %numlowbits) nounwind {
4532 ; X86-NOBMI-LABEL: bzhi64_32_d1:
4533 ; X86-NOBMI: # %bb.0:
4534 ; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
4535 ; X86-NOBMI-NEXT: xorl %ecx, %ecx
4536 ; X86-NOBMI-NEXT: subb {{[0-9]+}}(%esp), %cl
4537 ; X86-NOBMI-NEXT: shll %cl, %eax
4538 ; X86-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
4539 ; X86-NOBMI-NEXT: shrl %cl, %eax
4540 ; X86-NOBMI-NEXT: retl
4542 ; X86-BMI1NOTBM-LABEL: bzhi64_32_d1:
4543 ; X86-BMI1NOTBM: # %bb.0:
4544 ; X86-BMI1NOTBM-NEXT: movb {{[0-9]+}}(%esp), %al
4545 ; X86-BMI1NOTBM-NEXT: shll $8, %eax
4546 ; X86-BMI1NOTBM-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
4547 ; X86-BMI1NOTBM-NEXT: retl
4549 ; X86-BMI1BMI2-LABEL: bzhi64_32_d1:
4550 ; X86-BMI1BMI2: # %bb.0:
4551 ; X86-BMI1BMI2-NEXT: movb {{[0-9]+}}(%esp), %al
4552 ; X86-BMI1BMI2-NEXT: bzhil %eax, {{[0-9]+}}(%esp), %eax
4553 ; X86-BMI1BMI2-NEXT: retl
4555 ; X64-NOBMI-LABEL: bzhi64_32_d1:
4556 ; X64-NOBMI: # %bb.0:
4557 ; X64-NOBMI-NEXT: movl %esi, %ecx
4558 ; X64-NOBMI-NEXT: movq %rdi, %rax
4559 ; X64-NOBMI-NEXT: negb %cl
4560 ; X64-NOBMI-NEXT: shll %cl, %eax
4561 ; X64-NOBMI-NEXT: # kill: def $cl killed $cl killed $ecx
4562 ; X64-NOBMI-NEXT: shrl %cl, %eax
4563 ; X64-NOBMI-NEXT: # kill: def $eax killed $eax killed $rax
4564 ; X64-NOBMI-NEXT: retq
4566 ; X64-BMI1NOTBM-LABEL: bzhi64_32_d1:
4567 ; X64-BMI1NOTBM: # %bb.0:
4568 ; X64-BMI1NOTBM-NEXT: shll $8, %esi
4569 ; X64-BMI1NOTBM-NEXT: bextrl %esi, %edi, %eax
4570 ; X64-BMI1NOTBM-NEXT: retq
4572 ; X64-BMI1BMI2-LABEL: bzhi64_32_d1:
4573 ; X64-BMI1BMI2: # %bb.0:
4574 ; X64-BMI1BMI2-NEXT: bzhil %esi, %edi, %eax
4575 ; X64-BMI1BMI2-NEXT: retq
4576 %truncval = trunc i64 %val to i32
4577 %numhighbits = sub i32 32, %numlowbits
4578 %highbitscleared = shl i32 %truncval, %numhighbits
4579 %masked = lshr i32 %highbitscleared, %numhighbits
4583 ; ---------------------------------------------------------------------------- ;
4585 ; ---------------------------------------------------------------------------- ;
4589 define i32 @bzhi32_constant_mask32(i32 %val) nounwind {
4590 ; X86-LABEL: bzhi32_constant_mask32:
4592 ; X86-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
4593 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
4596 ; X64-LABEL: bzhi32_constant_mask32:
4598 ; X64-NEXT: movl %edi, %eax
4599 ; X64-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
4601 %masked = and i32 %val, 2147483647
4605 define i32 @bzhi32_constant_mask32_load(i32* %val) nounwind {
4606 ; X86-LABEL: bzhi32_constant_mask32_load:
4608 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
4609 ; X86-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
4610 ; X86-NEXT: andl (%ecx), %eax
4613 ; X64-LABEL: bzhi32_constant_mask32_load:
4615 ; X64-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
4616 ; X64-NEXT: andl (%rdi), %eax
4618 %val1 = load i32, i32* %val
4619 %masked = and i32 %val1, 2147483647
4623 define i32 @bzhi32_constant_mask16(i32 %val) nounwind {
4624 ; X86-LABEL: bzhi32_constant_mask16:
4626 ; X86-NEXT: movl $32767, %eax # imm = 0x7FFF
4627 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
4630 ; X64-LABEL: bzhi32_constant_mask16:
4632 ; X64-NEXT: movl %edi, %eax
4633 ; X64-NEXT: andl $32767, %eax # imm = 0x7FFF
4635 %masked = and i32 %val, 32767
4639 define i32 @bzhi32_constant_mask16_load(i32* %val) nounwind {
4640 ; X86-LABEL: bzhi32_constant_mask16_load:
4642 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
4643 ; X86-NEXT: movl $32767, %eax # imm = 0x7FFF
4644 ; X86-NEXT: andl (%ecx), %eax
4647 ; X64-LABEL: bzhi32_constant_mask16_load:
4649 ; X64-NEXT: movl $32767, %eax # imm = 0x7FFF
4650 ; X64-NEXT: andl (%rdi), %eax
4652 %val1 = load i32, i32* %val
4653 %masked = and i32 %val1, 32767
4657 define i32 @bzhi32_constant_mask8(i32 %val) nounwind {
4658 ; X86-LABEL: bzhi32_constant_mask8:
4660 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
4661 ; X86-NEXT: andl $127, %eax
4664 ; X64-LABEL: bzhi32_constant_mask8:
4666 ; X64-NEXT: movl %edi, %eax
4667 ; X64-NEXT: andl $127, %eax
4669 %masked = and i32 %val, 127
4673 define i32 @bzhi32_constant_mask8_load(i32* %val) nounwind {
4674 ; X86-LABEL: bzhi32_constant_mask8_load:
4676 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
4677 ; X86-NEXT: movl (%eax), %eax
4678 ; X86-NEXT: andl $127, %eax
4681 ; X64-LABEL: bzhi32_constant_mask8_load:
4683 ; X64-NEXT: movl (%rdi), %eax
4684 ; X64-NEXT: andl $127, %eax
4686 %val1 = load i32, i32* %val
4687 %masked = and i32 %val1, 127
4693 define i64 @bzhi64_constant_mask64(i64 %val) nounwind {
4694 ; X86-LABEL: bzhi64_constant_mask64:
4696 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
4697 ; X86-NEXT: movl $1073741823, %edx # imm = 0x3FFFFFFF
4698 ; X86-NEXT: andl {{[0-9]+}}(%esp), %edx
4701 ; X64-NOBMI-LABEL: bzhi64_constant_mask64:
4702 ; X64-NOBMI: # %bb.0:
4703 ; X64-NOBMI-NEXT: movabsq $4611686018427387903, %rax # imm = 0x3FFFFFFFFFFFFFFF
4704 ; X64-NOBMI-NEXT: andq %rdi, %rax
4705 ; X64-NOBMI-NEXT: retq
4707 ; X64-BMI1NOTBM-LABEL: bzhi64_constant_mask64:
4708 ; X64-BMI1NOTBM: # %bb.0:
4709 ; X64-BMI1NOTBM-NEXT: movl $15872, %eax # imm = 0x3E00
4710 ; X64-BMI1NOTBM-NEXT: bextrq %rax, %rdi, %rax
4711 ; X64-BMI1NOTBM-NEXT: retq
4713 ; X64-BMI1TBM-LABEL: bzhi64_constant_mask64:
4714 ; X64-BMI1TBM: # %bb.0:
4715 ; X64-BMI1TBM-NEXT: bextrq $15872, %rdi, %rax # imm = 0x3E00
4716 ; X64-BMI1TBM-NEXT: retq
4718 ; X64-BMI1NOTBMBMI2-LABEL: bzhi64_constant_mask64:
4719 ; X64-BMI1NOTBMBMI2: # %bb.0:
4720 ; X64-BMI1NOTBMBMI2-NEXT: movb $62, %al
4721 ; X64-BMI1NOTBMBMI2-NEXT: bzhiq %rax, %rdi, %rax
4722 ; X64-BMI1NOTBMBMI2-NEXT: retq
4723 %masked = and i64 %val, 4611686018427387903
4727 define i64 @bzhi64_constant_mask64_load(i64* %val) nounwind {
4728 ; X86-LABEL: bzhi64_constant_mask64_load:
4730 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
4731 ; X86-NEXT: movl (%ecx), %eax
4732 ; X86-NEXT: movl $1073741823, %edx # imm = 0x3FFFFFFF
4733 ; X86-NEXT: andl 4(%ecx), %edx
4736 ; X64-NOBMI-LABEL: bzhi64_constant_mask64_load:
4737 ; X64-NOBMI: # %bb.0:
4738 ; X64-NOBMI-NEXT: movabsq $4611686018427387903, %rax # imm = 0x3FFFFFFFFFFFFFFF
4739 ; X64-NOBMI-NEXT: andq (%rdi), %rax
4740 ; X64-NOBMI-NEXT: retq
4742 ; X64-BMI1NOTBM-LABEL: bzhi64_constant_mask64_load:
4743 ; X64-BMI1NOTBM: # %bb.0:
4744 ; X64-BMI1NOTBM-NEXT: movl $15872, %eax # imm = 0x3E00
4745 ; X64-BMI1NOTBM-NEXT: bextrq %rax, (%rdi), %rax
4746 ; X64-BMI1NOTBM-NEXT: retq
4748 ; X64-BMI1TBM-LABEL: bzhi64_constant_mask64_load:
4749 ; X64-BMI1TBM: # %bb.0:
4750 ; X64-BMI1TBM-NEXT: bextrq $15872, (%rdi), %rax # imm = 0x3E00
4751 ; X64-BMI1TBM-NEXT: retq
4753 ; X64-BMI1NOTBMBMI2-LABEL: bzhi64_constant_mask64_load:
4754 ; X64-BMI1NOTBMBMI2: # %bb.0:
4755 ; X64-BMI1NOTBMBMI2-NEXT: movb $62, %al
4756 ; X64-BMI1NOTBMBMI2-NEXT: bzhiq %rax, (%rdi), %rax
4757 ; X64-BMI1NOTBMBMI2-NEXT: retq
4758 %val1 = load i64, i64* %val
4759 %masked = and i64 %val1, 4611686018427387903
4763 define i64 @bzhi64_constant_mask32(i64 %val) nounwind {
4764 ; X86-LABEL: bzhi64_constant_mask32:
4766 ; X86-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
4767 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
4768 ; X86-NEXT: xorl %edx, %edx
4771 ; X64-LABEL: bzhi64_constant_mask32:
4773 ; X64-NEXT: movq %rdi, %rax
4774 ; X64-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
4776 %masked = and i64 %val, 2147483647
4780 define i64 @bzhi64_constant_mask32_load(i64* %val) nounwind {
4781 ; X86-LABEL: bzhi64_constant_mask32_load:
4783 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
4784 ; X86-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
4785 ; X86-NEXT: andl (%ecx), %eax
4786 ; X86-NEXT: xorl %edx, %edx
4789 ; X64-LABEL: bzhi64_constant_mask32_load:
4791 ; X64-NEXT: movq (%rdi), %rax
4792 ; X64-NEXT: andl $2147483647, %eax # imm = 0x7FFFFFFF
4794 %val1 = load i64, i64* %val
4795 %masked = and i64 %val1, 2147483647
4799 define i64 @bzhi64_constant_mask16(i64 %val) nounwind {
4800 ; X86-LABEL: bzhi64_constant_mask16:
4802 ; X86-NEXT: movl $32767, %eax # imm = 0x7FFF
4803 ; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
4804 ; X86-NEXT: xorl %edx, %edx
4807 ; X64-LABEL: bzhi64_constant_mask16:
4809 ; X64-NEXT: movq %rdi, %rax
4810 ; X64-NEXT: andl $32767, %eax # imm = 0x7FFF
4812 %masked = and i64 %val, 32767
4816 define i64 @bzhi64_constant_mask16_load(i64* %val) nounwind {
4817 ; X86-LABEL: bzhi64_constant_mask16_load:
4819 ; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
4820 ; X86-NEXT: movl $32767, %eax # imm = 0x7FFF
4821 ; X86-NEXT: andl (%ecx), %eax
4822 ; X86-NEXT: xorl %edx, %edx
4825 ; X64-LABEL: bzhi64_constant_mask16_load:
4827 ; X64-NEXT: movq (%rdi), %rax
4828 ; X64-NEXT: andl $32767, %eax # imm = 0x7FFF
4830 %val1 = load i64, i64* %val
4831 %masked = and i64 %val1, 32767
4835 define i64 @bzhi64_constant_mask8(i64 %val) nounwind {
4836 ; X86-LABEL: bzhi64_constant_mask8:
4838 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
4839 ; X86-NEXT: andl $127, %eax
4840 ; X86-NEXT: xorl %edx, %edx
4843 ; X64-LABEL: bzhi64_constant_mask8:
4845 ; X64-NEXT: movq %rdi, %rax
4846 ; X64-NEXT: andl $127, %eax
4848 %masked = and i64 %val, 127
4852 define i64 @bzhi64_constant_mask8_load(i64* %val) nounwind {
4853 ; X86-LABEL: bzhi64_constant_mask8_load:
4855 ; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
4856 ; X86-NEXT: movl (%eax), %eax
4857 ; X86-NEXT: andl $127, %eax
4858 ; X86-NEXT: xorl %edx, %edx
4861 ; X64-LABEL: bzhi64_constant_mask8_load:
4863 ; X64-NEXT: movq (%rdi), %rax
4864 ; X64-NEXT: andl $127, %eax
4866 %val1 = load i64, i64* %val
4867 %masked = and i64 %val1, 127