1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=ppc32-- | FileCheck %s --check-prefixes=CHECK,CHECK32,CHECK32_32
3 ; RUN: llc < %s -mtriple=ppc32-- -mcpu=ppc64 | FileCheck %s --check-prefixes=CHECK,CHECK32,CHECK32_64
4 ; RUN: llc < %s -mtriple=powerpc64le-- | FileCheck %s --check-prefixes=CHECK,CHECK64
6 declare i8 @llvm.fshl.i8(i8, i8, i8)
7 declare i16 @llvm.fshl.i16(i16, i16, i16)
8 declare i32 @llvm.fshl.i32(i32, i32, i32)
9 declare i64 @llvm.fshl.i64(i64, i64, i64)
10 declare <4 x i32> @llvm.fshl.v4i32(<4 x i32>, <4 x i32>, <4 x i32>)
12 declare i8 @llvm.fshr.i8(i8, i8, i8)
13 declare i16 @llvm.fshr.i16(i16, i16, i16)
14 declare i32 @llvm.fshr.i32(i32, i32, i32)
15 declare i64 @llvm.fshr.i64(i64, i64, i64)
16 declare <4 x i32> @llvm.fshr.v4i32(<4 x i32>, <4 x i32>, <4 x i32>)
18 ; When first 2 operands match, it's a rotate.
20 define i8 @rotl_i8_const_shift(i8 %x) {
21 ; CHECK-LABEL: rotl_i8_const_shift:
23 ; CHECK-NEXT: rotlwi 4, 3, 27
24 ; CHECK-NEXT: rlwimi 4, 3, 3, 0, 28
27 %f = call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 3)
31 define i64 @rotl_i64_const_shift(i64 %x) {
32 ; CHECK32-LABEL: rotl_i64_const_shift:
34 ; CHECK32-NEXT: rotlwi 5, 4, 3
35 ; CHECK32-NEXT: rotlwi 6, 3, 3
36 ; CHECK32-NEXT: rlwimi 5, 3, 3, 0, 28
37 ; CHECK32-NEXT: rlwimi 6, 4, 3, 0, 28
38 ; CHECK32-NEXT: mr 3, 5
39 ; CHECK32-NEXT: mr 4, 6
42 ; CHECK64-LABEL: rotl_i64_const_shift:
44 ; CHECK64-NEXT: rotldi 3, 3, 3
46 %f = call i64 @llvm.fshl.i64(i64 %x, i64 %x, i64 3)
50 ; When first 2 operands match, it's a rotate (by variable amount).
52 define i16 @rotl_i16(i16 %x, i16 %z) {
53 ; CHECK32-LABEL: rotl_i16:
55 ; CHECK32-NEXT: clrlwi 6, 4, 28
56 ; CHECK32-NEXT: neg 4, 4
57 ; CHECK32-NEXT: clrlwi 5, 3, 16
58 ; CHECK32-NEXT: clrlwi 4, 4, 28
59 ; CHECK32-NEXT: slw 3, 3, 6
60 ; CHECK32-NEXT: srw 4, 5, 4
61 ; CHECK32-NEXT: or 3, 3, 4
64 ; CHECK64-LABEL: rotl_i16:
66 ; CHECK64-NEXT: neg 5, 4
67 ; CHECK64-NEXT: clrlwi 6, 3, 16
68 ; CHECK64-NEXT: clrlwi 4, 4, 28
69 ; CHECK64-NEXT: clrlwi 5, 5, 28
70 ; CHECK64-NEXT: slw 3, 3, 4
71 ; CHECK64-NEXT: srw 4, 6, 5
72 ; CHECK64-NEXT: or 3, 3, 4
74 %f = call i16 @llvm.fshl.i16(i16 %x, i16 %x, i16 %z)
78 define i32 @rotl_i32(i32 %x, i32 %z) {
79 ; CHECK-LABEL: rotl_i32:
81 ; CHECK-NEXT: rotlw 3, 3, 4
83 %f = call i32 @llvm.fshl.i32(i32 %x, i32 %x, i32 %z)
87 define i64 @rotl_i64(i64 %x, i64 %z) {
88 ; CHECK32_32-LABEL: rotl_i64:
89 ; CHECK32_32: # %bb.0:
90 ; CHECK32_32-NEXT: andi. 5, 6, 32
91 ; CHECK32_32-NEXT: clrlwi 5, 6, 27
92 ; CHECK32_32-NEXT: subfic 6, 5, 32
93 ; CHECK32_32-NEXT: bc 12, 2, .LBB4_2
94 ; CHECK32_32-NEXT: # %bb.1:
95 ; CHECK32_32-NEXT: ori 7, 3, 0
96 ; CHECK32_32-NEXT: ori 3, 4, 0
97 ; CHECK32_32-NEXT: b .LBB4_3
98 ; CHECK32_32-NEXT: .LBB4_2:
99 ; CHECK32_32-NEXT: addi 7, 4, 0
100 ; CHECK32_32-NEXT: .LBB4_3:
101 ; CHECK32_32-NEXT: srw 4, 7, 6
102 ; CHECK32_32-NEXT: slw 8, 3, 5
103 ; CHECK32_32-NEXT: srw 6, 3, 6
104 ; CHECK32_32-NEXT: slw 5, 7, 5
105 ; CHECK32_32-NEXT: or 3, 8, 4
106 ; CHECK32_32-NEXT: or 4, 5, 6
107 ; CHECK32_32-NEXT: blr
109 ; CHECK32_64-LABEL: rotl_i64:
110 ; CHECK32_64: # %bb.0:
111 ; CHECK32_64-NEXT: andi. 5, 6, 32
112 ; CHECK32_64-NEXT: clrlwi 5, 6, 27
113 ; CHECK32_64-NEXT: bc 12, 2, .LBB4_2
114 ; CHECK32_64-NEXT: # %bb.1:
115 ; CHECK32_64-NEXT: ori 7, 3, 0
116 ; CHECK32_64-NEXT: ori 3, 4, 0
117 ; CHECK32_64-NEXT: b .LBB4_3
118 ; CHECK32_64-NEXT: .LBB4_2:
119 ; CHECK32_64-NEXT: addi 7, 4, 0
120 ; CHECK32_64-NEXT: .LBB4_3:
121 ; CHECK32_64-NEXT: subfic 6, 5, 32
122 ; CHECK32_64-NEXT: srw 4, 7, 6
123 ; CHECK32_64-NEXT: slw 8, 3, 5
124 ; CHECK32_64-NEXT: srw 6, 3, 6
125 ; CHECK32_64-NEXT: slw 5, 7, 5
126 ; CHECK32_64-NEXT: or 3, 8, 4
127 ; CHECK32_64-NEXT: or 4, 5, 6
128 ; CHECK32_64-NEXT: blr
130 ; CHECK64-LABEL: rotl_i64:
132 ; CHECK64-NEXT: rotld 3, 3, 4
134 %f = call i64 @llvm.fshl.i64(i64 %x, i64 %x, i64 %z)
140 define <4 x i32> @rotl_v4i32(<4 x i32> %x, <4 x i32> %z) {
141 ; CHECK32_32-LABEL: rotl_v4i32:
142 ; CHECK32_32: # %bb.0:
143 ; CHECK32_32-NEXT: rotlw 3, 3, 7
144 ; CHECK32_32-NEXT: rotlw 4, 4, 8
145 ; CHECK32_32-NEXT: rotlw 5, 5, 9
146 ; CHECK32_32-NEXT: rotlw 6, 6, 10
147 ; CHECK32_32-NEXT: blr
149 ; CHECK32_64-LABEL: rotl_v4i32:
150 ; CHECK32_64: # %bb.0:
151 ; CHECK32_64-NEXT: vrlw 2, 2, 3
152 ; CHECK32_64-NEXT: blr
154 ; CHECK64-LABEL: rotl_v4i32:
156 ; CHECK64-NEXT: vrlw 2, 2, 3
158 %f = call <4 x i32> @llvm.fshl.v4i32(<4 x i32> %x, <4 x i32> %x, <4 x i32> %z)
162 ; Vector rotate by constant splat amount.
164 define <4 x i32> @rotl_v4i32_const_shift(<4 x i32> %x) {
165 ; CHECK32_32-LABEL: rotl_v4i32_const_shift:
166 ; CHECK32_32: # %bb.0:
167 ; CHECK32_32-NEXT: rotlwi 3, 3, 3
168 ; CHECK32_32-NEXT: rotlwi 4, 4, 3
169 ; CHECK32_32-NEXT: rotlwi 5, 5, 3
170 ; CHECK32_32-NEXT: rotlwi 6, 6, 3
171 ; CHECK32_32-NEXT: blr
173 ; CHECK32_64-LABEL: rotl_v4i32_const_shift:
174 ; CHECK32_64: # %bb.0:
175 ; CHECK32_64-NEXT: vspltisw 3, 3
176 ; CHECK32_64-NEXT: vrlw 2, 2, 3
177 ; CHECK32_64-NEXT: blr
179 ; CHECK64-LABEL: rotl_v4i32_const_shift:
181 ; CHECK64-NEXT: vspltisw 3, 3
182 ; CHECK64-NEXT: vrlw 2, 2, 3
184 %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>)
188 ; Repeat everything for funnel shift right.
190 define i8 @rotr_i8_const_shift(i8 %x) {
191 ; CHECK-LABEL: rotr_i8_const_shift:
193 ; CHECK-NEXT: rotlwi 4, 3, 29
194 ; CHECK-NEXT: rlwimi 4, 3, 5, 0, 26
195 ; CHECK-NEXT: mr 3, 4
197 %f = call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 3)
201 define i32 @rotr_i32_const_shift(i32 %x) {
202 ; CHECK-LABEL: rotr_i32_const_shift:
204 ; CHECK-NEXT: rotlwi 3, 3, 29
206 %f = call i32 @llvm.fshr.i32(i32 %x, i32 %x, i32 3)
210 ; When first 2 operands match, it's a rotate (by variable amount).
212 define i16 @rotr_i16(i16 %x, i16 %z) {
213 ; CHECK32-LABEL: rotr_i16:
215 ; CHECK32-NEXT: clrlwi 6, 4, 28
216 ; CHECK32-NEXT: neg 4, 4
217 ; CHECK32-NEXT: clrlwi 5, 3, 16
218 ; CHECK32-NEXT: clrlwi 4, 4, 28
219 ; CHECK32-NEXT: srw 5, 5, 6
220 ; CHECK32-NEXT: slw 3, 3, 4
221 ; CHECK32-NEXT: or 3, 5, 3
224 ; CHECK64-LABEL: rotr_i16:
226 ; CHECK64-NEXT: neg 5, 4
227 ; CHECK64-NEXT: clrlwi 6, 3, 16
228 ; CHECK64-NEXT: clrlwi 4, 4, 28
229 ; CHECK64-NEXT: clrlwi 5, 5, 28
230 ; CHECK64-NEXT: srw 4, 6, 4
231 ; CHECK64-NEXT: slw 3, 3, 5
232 ; CHECK64-NEXT: or 3, 4, 3
234 %f = call i16 @llvm.fshr.i16(i16 %x, i16 %x, i16 %z)
238 define i32 @rotr_i32(i32 %x, i32 %z) {
239 ; CHECK-LABEL: rotr_i32:
241 ; CHECK-NEXT: neg 4, 4
242 ; CHECK-NEXT: rotlw 3, 3, 4
244 %f = call i32 @llvm.fshr.i32(i32 %x, i32 %x, i32 %z)
248 define i64 @rotr_i64(i64 %x, i64 %z) {
249 ; CHECK32_32-LABEL: rotr_i64:
250 ; CHECK32_32: # %bb.0:
251 ; CHECK32_32-NEXT: andi. 5, 6, 32
252 ; CHECK32_32-NEXT: clrlwi 5, 6, 27
253 ; CHECK32_32-NEXT: subfic 6, 5, 32
254 ; CHECK32_32-NEXT: bc 12, 2, .LBB11_2
255 ; CHECK32_32-NEXT: # %bb.1:
256 ; CHECK32_32-NEXT: ori 7, 4, 0
257 ; CHECK32_32-NEXT: b .LBB11_3
258 ; CHECK32_32-NEXT: .LBB11_2:
259 ; CHECK32_32-NEXT: addi 7, 3, 0
260 ; CHECK32_32-NEXT: addi 3, 4, 0
261 ; CHECK32_32-NEXT: .LBB11_3:
262 ; CHECK32_32-NEXT: srw 4, 7, 5
263 ; CHECK32_32-NEXT: slw 8, 3, 6
264 ; CHECK32_32-NEXT: srw 5, 3, 5
265 ; CHECK32_32-NEXT: slw 6, 7, 6
266 ; CHECK32_32-NEXT: or 3, 8, 4
267 ; CHECK32_32-NEXT: or 4, 6, 5
268 ; CHECK32_32-NEXT: blr
270 ; CHECK32_64-LABEL: rotr_i64:
271 ; CHECK32_64: # %bb.0:
272 ; CHECK32_64-NEXT: andi. 5, 6, 32
273 ; CHECK32_64-NEXT: clrlwi 5, 6, 27
274 ; CHECK32_64-NEXT: bc 12, 2, .LBB11_2
275 ; CHECK32_64-NEXT: # %bb.1:
276 ; CHECK32_64-NEXT: ori 7, 4, 0
277 ; CHECK32_64-NEXT: b .LBB11_3
278 ; CHECK32_64-NEXT: .LBB11_2:
279 ; CHECK32_64-NEXT: addi 7, 3, 0
280 ; CHECK32_64-NEXT: addi 3, 4, 0
281 ; CHECK32_64-NEXT: .LBB11_3:
282 ; CHECK32_64-NEXT: subfic 6, 5, 32
283 ; CHECK32_64-NEXT: srw 4, 7, 5
284 ; CHECK32_64-NEXT: slw 8, 3, 6
285 ; CHECK32_64-NEXT: srw 5, 3, 5
286 ; CHECK32_64-NEXT: slw 6, 7, 6
287 ; CHECK32_64-NEXT: or 3, 8, 4
288 ; CHECK32_64-NEXT: or 4, 6, 5
289 ; CHECK32_64-NEXT: blr
291 ; CHECK64-LABEL: rotr_i64:
293 ; CHECK64-NEXT: neg 4, 4
294 ; CHECK64-NEXT: rotld 3, 3, 4
296 %f = call i64 @llvm.fshr.i64(i64 %x, i64 %x, i64 %z)
302 define <4 x i32> @rotr_v4i32(<4 x i32> %x, <4 x i32> %z) {
303 ; CHECK32_32-LABEL: rotr_v4i32:
304 ; CHECK32_32: # %bb.0:
305 ; CHECK32_32-NEXT: neg 7, 7
306 ; CHECK32_32-NEXT: neg 8, 8
307 ; CHECK32_32-NEXT: neg 9, 9
308 ; CHECK32_32-NEXT: neg 10, 10
309 ; CHECK32_32-NEXT: rotlw 3, 3, 7
310 ; CHECK32_32-NEXT: rotlw 4, 4, 8
311 ; CHECK32_32-NEXT: rotlw 5, 5, 9
312 ; CHECK32_32-NEXT: rotlw 6, 6, 10
313 ; CHECK32_32-NEXT: blr
315 ; CHECK32_64-LABEL: rotr_v4i32:
316 ; CHECK32_64: # %bb.0:
317 ; CHECK32_64-NEXT: vxor 4, 4, 4
318 ; CHECK32_64-NEXT: vsubuwm 3, 4, 3
319 ; CHECK32_64-NEXT: vrlw 2, 2, 3
320 ; CHECK32_64-NEXT: blr
322 ; CHECK64-LABEL: rotr_v4i32:
324 ; CHECK64-NEXT: xxlxor 36, 36, 36
325 ; CHECK64-NEXT: vsubuwm 3, 4, 3
326 ; CHECK64-NEXT: vrlw 2, 2, 3
328 %f = call <4 x i32> @llvm.fshr.v4i32(<4 x i32> %x, <4 x i32> %x, <4 x i32> %z)
332 ; Vector rotate by constant splat amount.
334 define <4 x i32> @rotr_v4i32_const_shift(<4 x i32> %x) {
335 ; CHECK32_32-LABEL: rotr_v4i32_const_shift:
336 ; CHECK32_32: # %bb.0:
337 ; CHECK32_32-NEXT: rotlwi 3, 3, 29
338 ; CHECK32_32-NEXT: rotlwi 4, 4, 29
339 ; CHECK32_32-NEXT: rotlwi 5, 5, 29
340 ; CHECK32_32-NEXT: rotlwi 6, 6, 29
341 ; CHECK32_32-NEXT: blr
343 ; CHECK32_64-LABEL: rotr_v4i32_const_shift:
344 ; CHECK32_64: # %bb.0:
345 ; CHECK32_64-NEXT: vspltisw 3, -16
346 ; CHECK32_64-NEXT: vspltisw 4, 13
347 ; CHECK32_64-NEXT: vsubuwm 3, 4, 3
348 ; CHECK32_64-NEXT: vrlw 2, 2, 3
349 ; CHECK32_64-NEXT: blr
351 ; CHECK64-LABEL: rotr_v4i32_const_shift:
353 ; CHECK64-NEXT: vspltisw 3, -16
354 ; CHECK64-NEXT: vspltisw 4, 13
355 ; CHECK64-NEXT: vsubuwm 3, 4, 3
356 ; CHECK64-NEXT: vrlw 2, 2, 3
358 %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>)
362 define i32 @rotl_i32_shift_by_bitwidth(i32 %x) {
363 ; CHECK-LABEL: rotl_i32_shift_by_bitwidth:
366 %f = call i32 @llvm.fshl.i32(i32 %x, i32 %x, i32 32)
370 define i32 @rotr_i32_shift_by_bitwidth(i32 %x) {
371 ; CHECK-LABEL: rotr_i32_shift_by_bitwidth:
374 %f = call i32 @llvm.fshr.i32(i32 %x, i32 %x, i32 32)
378 define <4 x i32> @rotl_v4i32_shift_by_bitwidth(<4 x i32> %x) {
379 ; CHECK-LABEL: rotl_v4i32_shift_by_bitwidth:
382 %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>)
386 define <4 x i32> @rotr_v4i32_shift_by_bitwidth(<4 x i32> %x) {
387 ; CHECK-LABEL: rotr_v4i32_shift_by_bitwidth:
390 %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>)