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=ANY,X32-SSE2
3 ; RUN: llc < %s -mtriple=x86_64-- -mattr=avx2 | FileCheck %s --check-prefixes=ANY,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 ; X32-SSE2-LABEL: rotl_i8_const_shift:
22 ; X32-SSE2-NEXT: movb {{[0-9]+}}(%esp), %al
23 ; X32-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 i64 @rotl_i64_const_shift(i64 %x) nounwind {
37 ; X32-SSE2-LABEL: rotl_i64_const_shift:
39 ; X32-SSE2-NEXT: movl {{[0-9]+}}(%esp), %ecx
40 ; X32-SSE2-NEXT: movl {{[0-9]+}}(%esp), %edx
41 ; X32-SSE2-NEXT: movl %ecx, %eax
42 ; X32-SSE2-NEXT: shldl $3, %edx, %eax
43 ; X32-SSE2-NEXT: shldl $3, %ecx, %edx
46 ; X64-AVX2-LABEL: rotl_i64_const_shift:
48 ; X64-AVX2-NEXT: movq %rdi, %rax
49 ; X64-AVX2-NEXT: rolq $3, %rax
51 %f = call i64 @llvm.fshl.i64(i64 %x, i64 %x, i64 3)
55 define i16 @rotl_i16(i16 %x, i16 %z) nounwind {
56 ; X32-SSE2-LABEL: rotl_i16:
58 ; X32-SSE2-NEXT: movb {{[0-9]+}}(%esp), %cl
59 ; X32-SSE2-NEXT: movzwl {{[0-9]+}}(%esp), %eax
60 ; X32-SSE2-NEXT: rolw %cl, %ax
63 ; X64-AVX2-LABEL: rotl_i16:
65 ; X64-AVX2-NEXT: movl %esi, %ecx
66 ; X64-AVX2-NEXT: movl %edi, %eax
67 ; X64-AVX2-NEXT: # kill: def $cl killed $cl killed $ecx
68 ; X64-AVX2-NEXT: rolw %cl, %ax
69 ; X64-AVX2-NEXT: # kill: def $ax killed $ax killed $eax
71 %f = call i16 @llvm.fshl.i16(i16 %x, i16 %x, i16 %z)
75 define i32 @rotl_i32(i32 %x, i32 %z) nounwind {
76 ; X32-SSE2-LABEL: rotl_i32:
78 ; X32-SSE2-NEXT: movb {{[0-9]+}}(%esp), %cl
79 ; X32-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
80 ; X32-SSE2-NEXT: roll %cl, %eax
83 ; X64-AVX2-LABEL: rotl_i32:
85 ; X64-AVX2-NEXT: movl %esi, %ecx
86 ; X64-AVX2-NEXT: movl %edi, %eax
87 ; X64-AVX2-NEXT: # kill: def $cl killed $cl killed $ecx
88 ; X64-AVX2-NEXT: roll %cl, %eax
90 %f = call i32 @llvm.fshl.i32(i32 %x, i32 %x, i32 %z)
96 define <4 x i32> @rotl_v4i32(<4 x i32> %x, <4 x i32> %z) nounwind {
97 ; X32-SSE2-LABEL: rotl_v4i32:
99 ; X32-SSE2-NEXT: pand {{\.LCPI.*}}, %xmm1
100 ; X32-SSE2-NEXT: pslld $23, %xmm1
101 ; X32-SSE2-NEXT: paddd {{\.LCPI.*}}, %xmm1
102 ; X32-SSE2-NEXT: cvttps2dq %xmm1, %xmm1
103 ; X32-SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm0[1,1,3,3]
104 ; X32-SSE2-NEXT: pmuludq %xmm1, %xmm0
105 ; X32-SSE2-NEXT: pshufd {{.*#+}} xmm3 = xmm0[1,3,2,3]
106 ; X32-SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm1[1,1,3,3]
107 ; X32-SSE2-NEXT: pmuludq %xmm2, %xmm1
108 ; X32-SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm1[1,3,2,3]
109 ; X32-SSE2-NEXT: punpckldq {{.*#+}} xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
110 ; X32-SSE2-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,2,2,3]
111 ; X32-SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm1[0,2,2,3]
112 ; X32-SSE2-NEXT: punpckldq {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
113 ; X32-SSE2-NEXT: por %xmm3, %xmm0
114 ; X32-SSE2-NEXT: retl
116 ; X64-AVX2-LABEL: rotl_v4i32:
118 ; X64-AVX2-NEXT: vpbroadcastd {{.*#+}} xmm2 = [31,31,31,31]
119 ; X64-AVX2-NEXT: vpand %xmm2, %xmm1, %xmm1
120 ; X64-AVX2-NEXT: vpsllvd %xmm1, %xmm0, %xmm2
121 ; X64-AVX2-NEXT: vpbroadcastd {{.*#+}} xmm3 = [32,32,32,32]
122 ; X64-AVX2-NEXT: vpsubd %xmm1, %xmm3, %xmm1
123 ; X64-AVX2-NEXT: vpsrlvd %xmm1, %xmm0, %xmm0
124 ; X64-AVX2-NEXT: vpor %xmm0, %xmm2, %xmm0
125 ; X64-AVX2-NEXT: retq
126 %f = call <4 x i32> @llvm.fshl.v4i32(<4 x i32> %x, <4 x i32> %x, <4 x i32> %z)
130 ; Vector rotate by constant splat amount.
132 define <4 x i32> @rotl_v4i32_const_shift(<4 x i32> %x) nounwind {
133 ; X32-SSE2-LABEL: rotl_v4i32_const_shift:
135 ; X32-SSE2-NEXT: movdqa %xmm0, %xmm1
136 ; X32-SSE2-NEXT: psrld $29, %xmm1
137 ; X32-SSE2-NEXT: pslld $3, %xmm0
138 ; X32-SSE2-NEXT: por %xmm1, %xmm0
139 ; X32-SSE2-NEXT: retl
141 ; X64-AVX2-LABEL: rotl_v4i32_const_shift:
143 ; X64-AVX2-NEXT: vpsrld $29, %xmm0, %xmm1
144 ; X64-AVX2-NEXT: vpslld $3, %xmm0, %xmm0
145 ; X64-AVX2-NEXT: vpor %xmm1, %xmm0, %xmm0
146 ; X64-AVX2-NEXT: retq
147 %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>)
151 ; Repeat everything for funnel shift right.
153 define i8 @rotr_i8_const_shift(i8 %x) nounwind {
154 ; X32-SSE2-LABEL: rotr_i8_const_shift:
156 ; X32-SSE2-NEXT: movb {{[0-9]+}}(%esp), %al
157 ; X32-SSE2-NEXT: rorb $3, %al
158 ; X32-SSE2-NEXT: retl
160 ; X64-AVX2-LABEL: rotr_i8_const_shift:
162 ; X64-AVX2-NEXT: movl %edi, %eax
163 ; X64-AVX2-NEXT: rorb $3, %al
164 ; X64-AVX2-NEXT: # kill: def $al killed $al killed $eax
165 ; X64-AVX2-NEXT: retq
166 %f = call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 3)
170 define i32 @rotr_i32_const_shift(i32 %x) nounwind {
171 ; X32-SSE2-LABEL: rotr_i32_const_shift:
173 ; X32-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
174 ; X32-SSE2-NEXT: rorl $3, %eax
175 ; X32-SSE2-NEXT: retl
177 ; X64-AVX2-LABEL: rotr_i32_const_shift:
179 ; X64-AVX2-NEXT: movl %edi, %eax
180 ; X64-AVX2-NEXT: rorl $3, %eax
181 ; X64-AVX2-NEXT: retq
182 %f = call i32 @llvm.fshr.i32(i32 %x, i32 %x, i32 3)
186 ; When first 2 operands match, it's a rotate (by variable amount).
188 define i16 @rotr_i16(i16 %x, i16 %z) nounwind {
189 ; X32-SSE2-LABEL: rotr_i16:
191 ; X32-SSE2-NEXT: movb {{[0-9]+}}(%esp), %cl
192 ; X32-SSE2-NEXT: movzwl {{[0-9]+}}(%esp), %eax
193 ; X32-SSE2-NEXT: rorw %cl, %ax
194 ; X32-SSE2-NEXT: retl
196 ; X64-AVX2-LABEL: rotr_i16:
198 ; X64-AVX2-NEXT: movl %esi, %ecx
199 ; X64-AVX2-NEXT: movl %edi, %eax
200 ; X64-AVX2-NEXT: # kill: def $cl killed $cl killed $ecx
201 ; X64-AVX2-NEXT: rorw %cl, %ax
202 ; X64-AVX2-NEXT: # kill: def $ax killed $ax killed $eax
203 ; X64-AVX2-NEXT: retq
204 %f = call i16 @llvm.fshr.i16(i16 %x, i16 %x, i16 %z)
208 define i64 @rotr_i64(i64 %x, i64 %z) nounwind {
209 ; X32-SSE2-LABEL: rotr_i64:
211 ; X32-SSE2-NEXT: pushl %ebp
212 ; X32-SSE2-NEXT: pushl %ebx
213 ; X32-SSE2-NEXT: pushl %edi
214 ; X32-SSE2-NEXT: pushl %esi
215 ; X32-SSE2-NEXT: movb {{[0-9]+}}(%esp), %cl
216 ; X32-SSE2-NEXT: movl {{[0-9]+}}(%esp), %esi
217 ; X32-SSE2-NEXT: movl {{[0-9]+}}(%esp), %edx
218 ; X32-SSE2-NEXT: movl %edx, %edi
219 ; X32-SSE2-NEXT: shrl %cl, %edi
220 ; X32-SSE2-NEXT: movl %esi, %ebx
221 ; X32-SSE2-NEXT: shrdl %cl, %edx, %ebx
222 ; X32-SSE2-NEXT: xorl %ebp, %ebp
223 ; X32-SSE2-NEXT: testb $32, %cl
224 ; X32-SSE2-NEXT: cmovnel %edi, %ebx
225 ; X32-SSE2-NEXT: cmovnel %ebp, %edi
226 ; X32-SSE2-NEXT: negb %cl
227 ; X32-SSE2-NEXT: movl %esi, %eax
228 ; X32-SSE2-NEXT: shll %cl, %eax
229 ; X32-SSE2-NEXT: shldl %cl, %esi, %edx
230 ; X32-SSE2-NEXT: testb $32, %cl
231 ; X32-SSE2-NEXT: cmovnel %eax, %edx
232 ; X32-SSE2-NEXT: cmovnel %ebp, %eax
233 ; X32-SSE2-NEXT: orl %ebx, %eax
234 ; X32-SSE2-NEXT: orl %edi, %edx
235 ; X32-SSE2-NEXT: popl %esi
236 ; X32-SSE2-NEXT: popl %edi
237 ; X32-SSE2-NEXT: popl %ebx
238 ; X32-SSE2-NEXT: popl %ebp
239 ; X32-SSE2-NEXT: retl
241 ; X64-AVX2-LABEL: rotr_i64:
243 ; X64-AVX2-NEXT: movq %rsi, %rcx
244 ; X64-AVX2-NEXT: movq %rdi, %rax
245 ; X64-AVX2-NEXT: # kill: def $cl killed $cl killed $rcx
246 ; X64-AVX2-NEXT: rorq %cl, %rax
247 ; X64-AVX2-NEXT: retq
248 %f = call i64 @llvm.fshr.i64(i64 %x, i64 %x, i64 %z)
254 define <4 x i32> @rotr_v4i32(<4 x i32> %x, <4 x i32> %z) nounwind {
255 ; X32-SSE2-LABEL: rotr_v4i32:
257 ; X32-SSE2-NEXT: pxor %xmm2, %xmm2
258 ; X32-SSE2-NEXT: psubd %xmm1, %xmm2
259 ; X32-SSE2-NEXT: pand {{\.LCPI.*}}, %xmm2
260 ; X32-SSE2-NEXT: pslld $23, %xmm2
261 ; X32-SSE2-NEXT: paddd {{\.LCPI.*}}, %xmm2
262 ; X32-SSE2-NEXT: cvttps2dq %xmm2, %xmm1
263 ; X32-SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm0[1,1,3,3]
264 ; X32-SSE2-NEXT: pmuludq %xmm1, %xmm0
265 ; X32-SSE2-NEXT: pshufd {{.*#+}} xmm3 = xmm0[1,3,2,3]
266 ; X32-SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm1[1,1,3,3]
267 ; X32-SSE2-NEXT: pmuludq %xmm2, %xmm1
268 ; X32-SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm1[1,3,2,3]
269 ; X32-SSE2-NEXT: punpckldq {{.*#+}} xmm3 = xmm3[0],xmm2[0],xmm3[1],xmm2[1]
270 ; X32-SSE2-NEXT: pshufd {{.*#+}} xmm0 = xmm0[0,2,2,3]
271 ; X32-SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm1[0,2,2,3]
272 ; X32-SSE2-NEXT: punpckldq {{.*#+}} xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
273 ; X32-SSE2-NEXT: por %xmm3, %xmm0
274 ; X32-SSE2-NEXT: retl
276 ; X64-AVX2-LABEL: rotr_v4i32:
278 ; X64-AVX2-NEXT: vpxor %xmm2, %xmm2, %xmm2
279 ; X64-AVX2-NEXT: vpsubd %xmm1, %xmm2, %xmm1
280 ; X64-AVX2-NEXT: vpbroadcastd {{.*#+}} xmm2 = [31,31,31,31]
281 ; X64-AVX2-NEXT: vpand %xmm2, %xmm1, %xmm1
282 ; X64-AVX2-NEXT: vpsllvd %xmm1, %xmm0, %xmm2
283 ; X64-AVX2-NEXT: vpbroadcastd {{.*#+}} xmm3 = [32,32,32,32]
284 ; X64-AVX2-NEXT: vpsubd %xmm1, %xmm3, %xmm1
285 ; X64-AVX2-NEXT: vpsrlvd %xmm1, %xmm0, %xmm0
286 ; X64-AVX2-NEXT: vpor %xmm0, %xmm2, %xmm0
287 ; X64-AVX2-NEXT: retq
288 %f = call <4 x i32> @llvm.fshr.v4i32(<4 x i32> %x, <4 x i32> %x, <4 x i32> %z)
292 ; Vector rotate by constant splat amount.
294 define <4 x i32> @rotr_v4i32_const_shift(<4 x i32> %x) nounwind {
295 ; X32-SSE2-LABEL: rotr_v4i32_const_shift:
297 ; X32-SSE2-NEXT: movdqa %xmm0, %xmm1
298 ; X32-SSE2-NEXT: psrld $3, %xmm1
299 ; X32-SSE2-NEXT: pslld $29, %xmm0
300 ; X32-SSE2-NEXT: por %xmm1, %xmm0
301 ; X32-SSE2-NEXT: retl
303 ; X64-AVX2-LABEL: rotr_v4i32_const_shift:
305 ; X64-AVX2-NEXT: vpsrld $3, %xmm0, %xmm1
306 ; X64-AVX2-NEXT: vpslld $29, %xmm0, %xmm0
307 ; X64-AVX2-NEXT: vpor %xmm1, %xmm0, %xmm0
308 ; X64-AVX2-NEXT: retq
309 %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>)
313 define i32 @rotl_i32_shift_by_bitwidth(i32 %x) nounwind {
314 ; X32-SSE2-LABEL: rotl_i32_shift_by_bitwidth:
316 ; X32-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
317 ; X32-SSE2-NEXT: retl
319 ; X64-AVX2-LABEL: rotl_i32_shift_by_bitwidth:
321 ; X64-AVX2-NEXT: movl %edi, %eax
322 ; X64-AVX2-NEXT: retq
323 %f = call i32 @llvm.fshl.i32(i32 %x, i32 %x, i32 32)
327 define i32 @rotr_i32_shift_by_bitwidth(i32 %x) nounwind {
328 ; X32-SSE2-LABEL: rotr_i32_shift_by_bitwidth:
330 ; X32-SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
331 ; X32-SSE2-NEXT: retl
333 ; X64-AVX2-LABEL: rotr_i32_shift_by_bitwidth:
335 ; X64-AVX2-NEXT: movl %edi, %eax
336 ; X64-AVX2-NEXT: retq
337 %f = call i32 @llvm.fshr.i32(i32 %x, i32 %x, i32 32)
341 define <4 x i32> @rotl_v4i32_shift_by_bitwidth(<4 x i32> %x) nounwind {
342 ; ANY-LABEL: rotl_v4i32_shift_by_bitwidth:
344 ; ANY-NEXT: ret{{[l|q]}}
345 %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>)
349 define <4 x i32> @rotr_v4i32_shift_by_bitwidth(<4 x i32> %x) nounwind {
350 ; ANY-LABEL: rotr_v4i32_shift_by_bitwidth:
352 ; ANY-NEXT: ret{{[l|q]}}
353 %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>)
357 ; Non power-of-2 types can't use the negated shift amount to avoid a select.
359 declare i7 @llvm.fshl.i7(i7, i7, i7)
360 declare i7 @llvm.fshr.i7(i7, i7, i7)
362 ; extract(concat(0b1110000, 0b1110000) << 9) = 0b1000011
363 ; Try an oversized shift to test modulo functionality.
365 define i7 @fshl_i7() {
366 ; ANY-LABEL: fshl_i7:
368 ; ANY-NEXT: movb $67, %al
369 ; ANY-NEXT: ret{{[l|q]}}
370 %f = call i7 @llvm.fshl.i7(i7 112, i7 112, i7 9)
374 ; extract(concat(0b1110001, 0b1110001) >> 16) = 0b0111100
375 ; Try an oversized shift to test modulo functionality.
377 define i7 @fshr_i7() {
378 ; ANY-LABEL: fshr_i7:
380 ; ANY-NEXT: movb $60, %al
381 ; ANY-NEXT: ret{{[l|q]}}
382 %f = call i7 @llvm.fshr.i7(i7 113, i7 113, i7 16)