1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=i686-- -mattr=sse2 | FileCheck %s --check-prefixes=CHECK,X86-SSE2
3 ; RUN: llc < %s -mtriple=x86_64-- -mattr=avx2 | FileCheck %s --check-prefixes=CHECK,X64-AVX2
5 declare i8 @llvm.fshl.i8(i8, i8, i8)
6 declare i16 @llvm.fshl.i16(i16, i16, i16)
7 declare i32 @llvm.fshl.i32(i32, i32, i32)
8 declare i64 @llvm.fshl.i64(i64, i64, i64)
9 declare <4 x i32> @llvm.fshl.v4i32(<4 x i32>, <4 x i32>, <4 x i32>)
11 declare i8 @llvm.fshr.i8(i8, i8, i8)
12 declare i16 @llvm.fshr.i16(i16, i16, i16)
13 declare i32 @llvm.fshr.i32(i32, i32, i32)
14 declare i64 @llvm.fshr.i64(i64, i64, i64)
15 declare <4 x i32> @llvm.fshr.v4i32(<4 x i32>, <4 x i32>, <4 x i32>)
17 ; When first 2 operands match, it's a rotate.
19 define i8 @rotl_i8_const_shift(i8 %x) nounwind {
20 ; X86-SSE2-LABEL: rotl_i8_const_shift:
22 ; X86-SSE2-NEXT: movzbl {{[0-9]+}}(%esp), %eax
23 ; X86-SSE2-NEXT: rolb $3, %al
26 ; X64-AVX2-LABEL: rotl_i8_const_shift:
28 ; X64-AVX2-NEXT: movl %edi, %eax
29 ; X64-AVX2-NEXT: rolb $3, %al
30 ; X64-AVX2-NEXT: # kill: def $al killed $al killed $eax
32 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 3)
36 define i8 @rotl_i8_const_shift1(i8 %x) nounwind {
37 ; X86-SSE2-LABEL: rotl_i8_const_shift1:
39 ; X86-SSE2-NEXT: movzbl {{[0-9]+}}(%esp), %eax
40 ; X86-SSE2-NEXT: rolb %al
43 ; X64-AVX2-LABEL: rotl_i8_const_shift1:
45 ; X64-AVX2-NEXT: movl %edi, %eax
46 ; X64-AVX2-NEXT: rolb %al
47 ; X64-AVX2-NEXT: # kill: def $al killed $al killed $eax
49 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 1)
53 define i8 @rotl_i8_const_shift7(i8 %x) nounwind {
54 ; X86-SSE2-LABEL: rotl_i8_const_shift7:
56 ; X86-SSE2-NEXT: movzbl {{[0-9]+}}(%esp), %eax
57 ; X86-SSE2-NEXT: rorb %al
60 ; X64-AVX2-LABEL: rotl_i8_const_shift7:
62 ; X64-AVX2-NEXT: movl %edi, %eax
63 ; X64-AVX2-NEXT: rorb %al
64 ; X64-AVX2-NEXT: # kill: def $al killed $al killed $eax
66 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 7)
70 define i64 @rotl_i64_const_shift(i64 %x) nounwind {
71 ; X86-SSE2-LABEL: rotl_i64_const_shift:
73 ; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %ecx
74 ; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %edx
75 ; X86-SSE2-NEXT: movl %ecx, %eax
76 ; X86-SSE2-NEXT: shldl $3, %edx, %eax
77 ; X86-SSE2-NEXT: shldl $3, %ecx, %edx
80 ; X64-AVX2-LABEL: rotl_i64_const_shift:
82 ; X64-AVX2-NEXT: movq %rdi, %rax
83 ; X64-AVX2-NEXT: rolq $3, %rax
85 %f = call i64 @llvm.fshl.i64(i64 %x, i64 %x, i64 3)
89 define i16 @rotl_i16(i16 %x, i16 %z) nounwind {
90 ; X86-SSE2-LABEL: rotl_i16:
92 ; X86-SSE2-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
93 ; X86-SSE2-NEXT: movzwl {{[0-9]+}}(%esp), %eax
94 ; X86-SSE2-NEXT: rolw %cl, %ax
97 ; X64-AVX2-LABEL: rotl_i16:
99 ; X64-AVX2-NEXT: movl %esi, %ecx
100 ; X64-AVX2-NEXT: movl %edi, %eax
101 ; X64-AVX2-NEXT: # kill: def $cl killed $cl killed $ecx
102 ; X64-AVX2-NEXT: rolw %cl, %ax
103 ; X64-AVX2-NEXT: # kill: def $ax killed $ax killed $eax
104 ; X64-AVX2-NEXT: retq
105 %f = call i16 @llvm.fshl.i16(i16 %x, i16 %x, i16 %z)
109 define i32 @rotl_i32(i32 %x, i32 %z) nounwind {
110 ; X86-SSE2-LABEL: rotl_i32:
112 ; X86-SSE2-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
113 ; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
114 ; X86-SSE2-NEXT: roll %cl, %eax
115 ; X86-SSE2-NEXT: retl
117 ; X64-AVX2-LABEL: rotl_i32:
119 ; X64-AVX2-NEXT: movl %esi, %ecx
120 ; X64-AVX2-NEXT: movl %edi, %eax
121 ; X64-AVX2-NEXT: # kill: def $cl killed $cl killed $ecx
122 ; X64-AVX2-NEXT: roll %cl, %eax
123 ; X64-AVX2-NEXT: retq
124 %f = call i32 @llvm.fshl.i32(i32 %x, i32 %x, i32 %z)
130 define <4 x i32> @rotl_v4i32(<4 x i32> %x, <4 x i32> %z) nounwind {
131 ; X86-SSE2-LABEL: rotl_v4i32:
133 ; X86-SSE2-NEXT: pslld $23, %xmm1
134 ; X86-SSE2-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}, %xmm1
135 ; X86-SSE2-NEXT: paddd {{\.?LCPI[0-9]+_[0-9]+}}, %xmm1
136 ; X86-SSE2-NEXT: cvttps2dq %xmm1, %xmm1
137 ; X86-SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm0[1,1,3,3]
138 ; X86-SSE2-NEXT: pmuludq %xmm1, %xmm0
139 ; X86-SSE2-NEXT: pshufd {{.*#+}} xmm3 = xmm0[1,3,2,3]
140 ; X86-SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm1[1,1,3,3]
141 ; X86-SSE2-NEXT: pmuludq %xmm2, %xmm1
142 ; X86-SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm1[1,3,2,3]
143 ; X86-SSE2-NEXT: punpckldq {{.*#+}} xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
144 ; X86-SSE2-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,2,2,3]
145 ; X86-SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm1[0,2,2,3]
146 ; X86-SSE2-NEXT: punpckldq {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
147 ; X86-SSE2-NEXT: por %xmm3, %xmm0
148 ; X86-SSE2-NEXT: retl
150 ; X64-AVX2-LABEL: rotl_v4i32:
152 ; X64-AVX2-NEXT: vpbroadcastd {{.*#+}} xmm2 = [31,31,31,31]
153 ; X64-AVX2-NEXT: vpand %xmm2, %xmm1, %xmm1
154 ; X64-AVX2-NEXT: vpsllvd %xmm1, %xmm0, %xmm2
155 ; X64-AVX2-NEXT: vpbroadcastd {{.*#+}} xmm3 = [32,32,32,32]
156 ; X64-AVX2-NEXT: vpsubd %xmm1, %xmm3, %xmm1
157 ; X64-AVX2-NEXT: vpsrlvd %xmm1, %xmm0, %xmm0
158 ; X64-AVX2-NEXT: vpor %xmm0, %xmm2, %xmm0
159 ; X64-AVX2-NEXT: retq
160 %f = call <4 x i32> @llvm.fshl.v4i32(<4 x i32> %x, <4 x i32> %x, <4 x i32> %z)
164 ; Vector rotate by constant splat amount.
166 define <4 x i32> @rotl_v4i32_const_shift(<4 x i32> %x) nounwind {
167 ; X86-SSE2-LABEL: rotl_v4i32_const_shift:
169 ; X86-SSE2-NEXT: movdqa %xmm0, %xmm1
170 ; X86-SSE2-NEXT: psrld $29, %xmm1
171 ; X86-SSE2-NEXT: pslld $3, %xmm0
172 ; X86-SSE2-NEXT: por %xmm1, %xmm0
173 ; X86-SSE2-NEXT: retl
175 ; X64-AVX2-LABEL: rotl_v4i32_const_shift:
177 ; X64-AVX2-NEXT: vpsrld $29, %xmm0, %xmm1
178 ; X64-AVX2-NEXT: vpslld $3, %xmm0, %xmm0
179 ; X64-AVX2-NEXT: vpor %xmm1, %xmm0, %xmm0
180 ; X64-AVX2-NEXT: retq
181 %f = call <4 x i32> @llvm.fshl.v4i32(<4 x i32> %x, <4 x i32> %x, <4 x i32> <i32 3, i32 3, i32 3, i32 3>)
185 ; Repeat everything for funnel shift right.
187 define i8 @rotr_i8_const_shift(i8 %x) nounwind {
188 ; X86-SSE2-LABEL: rotr_i8_const_shift:
190 ; X86-SSE2-NEXT: movzbl {{[0-9]+}}(%esp), %eax
191 ; X86-SSE2-NEXT: rorb $3, %al
192 ; X86-SSE2-NEXT: retl
194 ; X64-AVX2-LABEL: rotr_i8_const_shift:
196 ; X64-AVX2-NEXT: movl %edi, %eax
197 ; X64-AVX2-NEXT: rorb $3, %al
198 ; X64-AVX2-NEXT: # kill: def $al killed $al killed $eax
199 ; X64-AVX2-NEXT: retq
200 %f = call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 3)
204 define i8 @rotr_i8_const_shift1(i8 %x) nounwind {
205 ; X86-SSE2-LABEL: rotr_i8_const_shift1:
207 ; X86-SSE2-NEXT: movzbl {{[0-9]+}}(%esp), %eax
208 ; X86-SSE2-NEXT: rorb %al
209 ; X86-SSE2-NEXT: retl
211 ; X64-AVX2-LABEL: rotr_i8_const_shift1:
213 ; X64-AVX2-NEXT: movl %edi, %eax
214 ; X64-AVX2-NEXT: rorb %al
215 ; X64-AVX2-NEXT: # kill: def $al killed $al killed $eax
216 ; X64-AVX2-NEXT: retq
217 %f = call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 1)
221 define i8 @rotr_i8_const_shift7(i8 %x) nounwind {
222 ; X86-SSE2-LABEL: rotr_i8_const_shift7:
224 ; X86-SSE2-NEXT: movzbl {{[0-9]+}}(%esp), %eax
225 ; X86-SSE2-NEXT: rolb %al
226 ; X86-SSE2-NEXT: retl
228 ; X64-AVX2-LABEL: rotr_i8_const_shift7:
230 ; X64-AVX2-NEXT: movl %edi, %eax
231 ; X64-AVX2-NEXT: rolb %al
232 ; X64-AVX2-NEXT: # kill: def $al killed $al killed $eax
233 ; X64-AVX2-NEXT: retq
234 %f = call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 7)
238 define i32 @rotr_i32_const_shift(i32 %x) nounwind {
239 ; X86-SSE2-LABEL: rotr_i32_const_shift:
241 ; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
242 ; X86-SSE2-NEXT: rorl $3, %eax
243 ; X86-SSE2-NEXT: retl
245 ; X64-AVX2-LABEL: rotr_i32_const_shift:
247 ; X64-AVX2-NEXT: movl %edi, %eax
248 ; X64-AVX2-NEXT: rorl $3, %eax
249 ; X64-AVX2-NEXT: retq
250 %f = call i32 @llvm.fshr.i32(i32 %x, i32 %x, i32 3)
254 ; When first 2 operands match, it's a rotate (by variable amount).
256 define i16 @rotr_i16(i16 %x, i16 %z) nounwind {
257 ; X86-SSE2-LABEL: rotr_i16:
259 ; X86-SSE2-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
260 ; X86-SSE2-NEXT: movzwl {{[0-9]+}}(%esp), %eax
261 ; X86-SSE2-NEXT: rorw %cl, %ax
262 ; X86-SSE2-NEXT: retl
264 ; X64-AVX2-LABEL: rotr_i16:
266 ; X64-AVX2-NEXT: movl %esi, %ecx
267 ; X64-AVX2-NEXT: movl %edi, %eax
268 ; X64-AVX2-NEXT: # kill: def $cl killed $cl killed $ecx
269 ; X64-AVX2-NEXT: rorw %cl, %ax
270 ; X64-AVX2-NEXT: # kill: def $ax killed $ax killed $eax
271 ; X64-AVX2-NEXT: retq
272 %f = call i16 @llvm.fshr.i16(i16 %x, i16 %x, i16 %z)
276 define i64 @rotr_i64(i64 %x, i64 %z) nounwind {
277 ; X86-SSE2-LABEL: rotr_i64:
279 ; X86-SSE2-NEXT: pushl %esi
280 ; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
281 ; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %esi
282 ; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %ecx
283 ; X86-SSE2-NEXT: testb $32, %cl
284 ; X86-SSE2-NEXT: movl %eax, %edx
285 ; X86-SSE2-NEXT: cmovel %esi, %edx
286 ; X86-SSE2-NEXT: cmovel %eax, %esi
287 ; X86-SSE2-NEXT: movl %esi, %eax
288 ; X86-SSE2-NEXT: shrdl %cl, %edx, %eax
289 ; X86-SSE2-NEXT: # kill: def $cl killed $cl killed $ecx
290 ; X86-SSE2-NEXT: shrdl %cl, %esi, %edx
291 ; X86-SSE2-NEXT: popl %esi
292 ; X86-SSE2-NEXT: retl
294 ; X64-AVX2-LABEL: rotr_i64:
296 ; X64-AVX2-NEXT: movq %rsi, %rcx
297 ; X64-AVX2-NEXT: movq %rdi, %rax
298 ; X64-AVX2-NEXT: # kill: def $cl killed $cl killed $rcx
299 ; X64-AVX2-NEXT: rorq %cl, %rax
300 ; X64-AVX2-NEXT: retq
301 %f = call i64 @llvm.fshr.i64(i64 %x, i64 %x, i64 %z)
307 define <4 x i32> @rotr_v4i32(<4 x i32> %x, <4 x i32> %z) nounwind {
308 ; X86-SSE2-LABEL: rotr_v4i32:
310 ; X86-SSE2-NEXT: pxor %xmm2, %xmm2
311 ; X86-SSE2-NEXT: psubd %xmm1, %xmm2
312 ; X86-SSE2-NEXT: pslld $23, %xmm2
313 ; X86-SSE2-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}, %xmm2
314 ; X86-SSE2-NEXT: paddd {{\.?LCPI[0-9]+_[0-9]+}}, %xmm2
315 ; X86-SSE2-NEXT: cvttps2dq %xmm2, %xmm1
316 ; X86-SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm0[1,1,3,3]
317 ; X86-SSE2-NEXT: pmuludq %xmm1, %xmm0
318 ; X86-SSE2-NEXT: pshufd {{.*#+}} xmm3 = xmm0[1,3,2,3]
319 ; X86-SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm1[1,1,3,3]
320 ; X86-SSE2-NEXT: pmuludq %xmm2, %xmm1
321 ; X86-SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm1[1,3,2,3]
322 ; X86-SSE2-NEXT: punpckldq {{.*#+}} xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
323 ; X86-SSE2-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,2,2,3]
324 ; X86-SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm1[0,2,2,3]
325 ; X86-SSE2-NEXT: punpckldq {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
326 ; X86-SSE2-NEXT: por %xmm3, %xmm0
327 ; X86-SSE2-NEXT: retl
329 ; X64-AVX2-LABEL: rotr_v4i32:
331 ; X64-AVX2-NEXT: vpbroadcastd {{.*#+}} xmm2 = [31,31,31,31]
332 ; X64-AVX2-NEXT: vpand %xmm2, %xmm1, %xmm1
333 ; X64-AVX2-NEXT: vpsrlvd %xmm1, %xmm0, %xmm2
334 ; X64-AVX2-NEXT: vpbroadcastd {{.*#+}} xmm3 = [32,32,32,32]
335 ; X64-AVX2-NEXT: vpsubd %xmm1, %xmm3, %xmm1
336 ; X64-AVX2-NEXT: vpsllvd %xmm1, %xmm0, %xmm0
337 ; X64-AVX2-NEXT: vpor %xmm0, %xmm2, %xmm0
338 ; X64-AVX2-NEXT: retq
339 %f = call <4 x i32> @llvm.fshr.v4i32(<4 x i32> %x, <4 x i32> %x, <4 x i32> %z)
343 ; Vector rotate by constant splat amount.
345 define <4 x i32> @rotr_v4i32_const_shift(<4 x i32> %x) nounwind {
346 ; X86-SSE2-LABEL: rotr_v4i32_const_shift:
348 ; X86-SSE2-NEXT: movdqa %xmm0, %xmm1
349 ; X86-SSE2-NEXT: psrld $3, %xmm1
350 ; X86-SSE2-NEXT: pslld $29, %xmm0
351 ; X86-SSE2-NEXT: por %xmm1, %xmm0
352 ; X86-SSE2-NEXT: retl
354 ; X64-AVX2-LABEL: rotr_v4i32_const_shift:
356 ; X64-AVX2-NEXT: vpsrld $3, %xmm0, %xmm1
357 ; X64-AVX2-NEXT: vpslld $29, %xmm0, %xmm0
358 ; X64-AVX2-NEXT: vpor %xmm1, %xmm0, %xmm0
359 ; X64-AVX2-NEXT: retq
360 %f = call <4 x i32> @llvm.fshr.v4i32(<4 x i32> %x, <4 x i32> %x, <4 x i32> <i32 3, i32 3, i32 3, i32 3>)
364 define i32 @rotl_i32_shift_by_bitwidth(i32 %x) nounwind {
365 ; X86-SSE2-LABEL: rotl_i32_shift_by_bitwidth:
367 ; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
368 ; X86-SSE2-NEXT: retl
370 ; X64-AVX2-LABEL: rotl_i32_shift_by_bitwidth:
372 ; X64-AVX2-NEXT: movl %edi, %eax
373 ; X64-AVX2-NEXT: retq
374 %f = call i32 @llvm.fshl.i32(i32 %x, i32 %x, i32 32)
378 define i32 @rotr_i32_shift_by_bitwidth(i32 %x) nounwind {
379 ; X86-SSE2-LABEL: rotr_i32_shift_by_bitwidth:
381 ; X86-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
382 ; X86-SSE2-NEXT: retl
384 ; X64-AVX2-LABEL: rotr_i32_shift_by_bitwidth:
386 ; X64-AVX2-NEXT: movl %edi, %eax
387 ; X64-AVX2-NEXT: retq
388 %f = call i32 @llvm.fshr.i32(i32 %x, i32 %x, i32 32)
392 define <4 x i32> @rotl_v4i32_shift_by_bitwidth(<4 x i32> %x) nounwind {
393 ; CHECK-LABEL: rotl_v4i32_shift_by_bitwidth:
395 ; CHECK-NEXT: ret{{[l|q]}}
396 %f = call <4 x i32> @llvm.fshl.v4i32(<4 x i32> %x, <4 x i32> %x, <4 x i32> <i32 32, i32 32, i32 32, i32 32>)
400 define <4 x i32> @rotr_v4i32_shift_by_bitwidth(<4 x i32> %x) nounwind {
401 ; CHECK-LABEL: rotr_v4i32_shift_by_bitwidth:
403 ; CHECK-NEXT: ret{{[l|q]}}
404 %f = call <4 x i32> @llvm.fshr.v4i32(<4 x i32> %x, <4 x i32> %x, <4 x i32> <i32 32, i32 32, i32 32, i32 32>)
408 ; Non power-of-2 types can't use the negated shift amount to avoid a select.
410 declare i7 @llvm.fshl.i7(i7, i7, i7)
411 declare i7 @llvm.fshr.i7(i7, i7, i7)
413 ; extract(concat(0b1110000, 0b1110000) << 9) = 0b1000011
414 ; Try an oversized shift to test modulo functionality.
416 define i7 @fshl_i7() {
417 ; CHECK-LABEL: fshl_i7:
419 ; CHECK-NEXT: movb $67, %al
420 ; CHECK-NEXT: ret{{[l|q]}}
421 %f = call i7 @llvm.fshl.i7(i7 112, i7 112, i7 9)
425 ; extract(concat(0b1110001, 0b1110001) >> 16) = 0b0111100
426 ; Try an oversized shift to test modulo functionality.
428 define i7 @fshr_i7() {
429 ; CHECK-LABEL: fshr_i7:
431 ; CHECK-NEXT: movb $60, %al
432 ; CHECK-NEXT: ret{{[l|q]}}
433 %f = call i7 @llvm.fshr.i7(i7 113, i7 113, i7 16)