blob: 8ecf15432d5c96ddc2f84a7b52c163cc0c62bff1 [file] [log] [blame]
Dan Gohmanb7c0b242009-09-11 18:36:27 +00001; RUN: llc < %s -march=cellspu > %t1.s
Kalle Raiskila31cbac12011-03-04 13:19:18 +00002; RUN: grep {shlh } %t1.s | count 10
Duncan Sands74789ea2009-01-21 09:41:42 +00003; RUN: grep {shlhi } %t1.s | count 3
Kalle Raiskila31cbac12011-03-04 13:19:18 +00004; RUN: grep {shl } %t1.s | count 11
Duncan Sands74789ea2009-01-21 09:41:42 +00005; RUN: grep {shli } %t1.s | count 3
Evan Cheng3927f432009-03-25 20:20:11 +00006; RUN: grep {xshw } %t1.s | count 5
Chris Lattnerd3027732011-02-13 09:02:52 +00007; RUN: grep {and } %t1.s | count 14
Duncan Sands74789ea2009-01-21 09:41:42 +00008; RUN: grep {andi } %t1.s | count 2
9; RUN: grep {rotmi } %t1.s | count 2
10; RUN: grep {rotqmbyi } %t1.s | count 1
11; RUN: grep {rotqmbii } %t1.s | count 2
12; RUN: grep {rotqmby } %t1.s | count 1
Kalle Raiskila9363f732010-11-29 14:44:28 +000013; RUN: grep {rotqmbi } %t1.s | count 2
Duncan Sands74789ea2009-01-21 09:41:42 +000014; RUN: grep {rotqbyi } %t1.s | count 1
15; RUN: grep {rotqbii } %t1.s | count 2
16; RUN: grep {rotqbybi } %t1.s | count 1
Kalle Raiskila31cbac12011-03-04 13:19:18 +000017; RUN: grep {sfi } %t1.s | count 6
Kalle Raiskila9363f732010-11-29 14:44:28 +000018; RUN: cat %t1.s | FileCheck %s
Scott Michel02d711b2008-12-30 23:28:25 +000019
Scott Michel9de5d0d2008-01-11 02:53:15 +000020target datalayout = "E-p:32:32:128-f64:64:128-f32:32:128-i64:32:128-i32:32:128-i16:16:128-i8:8:128-i1:8:128-a0:0:128-v128:128:128-s0:128:128"
21target triple = "spu"
Scott Michel0a92af42007-12-19 20:50:49 +000022
Scott Michel0a92af42007-12-19 20:50:49 +000023; Shift left i16 via register, note that the second operand to shl is promoted
24; to a 32-bit type:
25
26define i16 @shlh_i16_1(i16 %arg1, i16 %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +000027 %A = shl i16 %arg1, %arg2
28 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000029}
30
31define i16 @shlh_i16_2(i16 %arg1, i16 %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +000032 %A = shl i16 %arg2, %arg1
33 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000034}
35
Chris Lattner26b00002011-06-17 03:14:27 +000036define signext i16 @shlh_i16_3(i16 signext %arg1, i16 signext %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +000037 %A = shl i16 %arg1, %arg2
38 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000039}
40
Chris Lattner26b00002011-06-17 03:14:27 +000041define signext i16 @shlh_i16_4(i16 signext %arg1, i16 signext %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +000042 %A = shl i16 %arg2, %arg1
43 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000044}
45
Chris Lattner26b00002011-06-17 03:14:27 +000046define zeroext i16 @shlh_i16_5(i16 zeroext %arg1, i16 zeroext %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +000047 %A = shl i16 %arg1, %arg2
48 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000049}
50
Chris Lattner26b00002011-06-17 03:14:27 +000051define zeroext i16 @shlh_i16_6(i16 zeroext %arg1, i16 zeroext %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +000052 %A = shl i16 %arg2, %arg1
53 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000054}
55
56; Shift left i16 with immediate:
57define i16 @shlhi_i16_1(i16 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +000058 %A = shl i16 %arg1, 12
59 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000060}
61
62; Should not generate anything other than the return, arg1 << 0 = arg1
63define i16 @shlhi_i16_2(i16 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +000064 %A = shl i16 %arg1, 0
65 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000066}
67
68define i16 @shlhi_i16_3(i16 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +000069 %A = shl i16 16383, %arg1
70 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000071}
72
73; Should generate 0, 0 << arg1 = 0
74define i16 @shlhi_i16_4(i16 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +000075 %A = shl i16 0, %arg1
76 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000077}
78
Chris Lattner26b00002011-06-17 03:14:27 +000079define signext i16 @shlhi_i16_5(i16 signext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +000080 %A = shl i16 %arg1, 12
81 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000082}
83
84; Should not generate anything other than the return, arg1 << 0 = arg1
Chris Lattner26b00002011-06-17 03:14:27 +000085define signext i16 @shlhi_i16_6(i16 signext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +000086 %A = shl i16 %arg1, 0
87 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000088}
89
Chris Lattner26b00002011-06-17 03:14:27 +000090define signext i16 @shlhi_i16_7(i16 signext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +000091 %A = shl i16 16383, %arg1
92 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000093}
94
95; Should generate 0, 0 << arg1 = 0
Chris Lattner26b00002011-06-17 03:14:27 +000096define signext i16 @shlhi_i16_8(i16 signext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +000097 %A = shl i16 0, %arg1
98 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000099}
100
Chris Lattner26b00002011-06-17 03:14:27 +0000101define zeroext i16 @shlhi_i16_9(i16 zeroext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000102 %A = shl i16 %arg1, 12
103 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000104}
105
106; Should not generate anything other than the return, arg1 << 0 = arg1
Chris Lattner26b00002011-06-17 03:14:27 +0000107define zeroext i16 @shlhi_i16_10(i16 zeroext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000108 %A = shl i16 %arg1, 0
109 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000110}
111
Chris Lattner26b00002011-06-17 03:14:27 +0000112define zeroext i16 @shlhi_i16_11(i16 zeroext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000113 %A = shl i16 16383, %arg1
114 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000115}
116
117; Should generate 0, 0 << arg1 = 0
Chris Lattner26b00002011-06-17 03:14:27 +0000118define zeroext i16 @shlhi_i16_12(i16 zeroext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000119 %A = shl i16 0, %arg1
120 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000121}
122
123; Shift left i32 via register, note that the second operand to shl is promoted
124; to a 32-bit type:
125
126define i32 @shl_i32_1(i32 %arg1, i32 %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +0000127 %A = shl i32 %arg1, %arg2
128 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000129}
130
131define i32 @shl_i32_2(i32 %arg1, i32 %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +0000132 %A = shl i32 %arg2, %arg1
133 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000134}
135
Chris Lattner26b00002011-06-17 03:14:27 +0000136define signext i32 @shl_i32_3(i32 signext %arg1, i32 signext %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +0000137 %A = shl i32 %arg1, %arg2
138 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000139}
140
Chris Lattner26b00002011-06-17 03:14:27 +0000141define signext i32 @shl_i32_4(i32 signext %arg1, i32 signext %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +0000142 %A = shl i32 %arg2, %arg1
143 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000144}
145
Chris Lattner26b00002011-06-17 03:14:27 +0000146define zeroext i32 @shl_i32_5(i32 zeroext %arg1, i32 zeroext %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +0000147 %A = shl i32 %arg1, %arg2
148 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000149}
150
Chris Lattner26b00002011-06-17 03:14:27 +0000151define zeroext i32 @shl_i32_6(i32 zeroext %arg1, i32 zeroext %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +0000152 %A = shl i32 %arg2, %arg1
153 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000154}
155
156; Shift left i32 with immediate:
157define i32 @shli_i32_1(i32 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000158 %A = shl i32 %arg1, 12
159 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000160}
161
162; Should not generate anything other than the return, arg1 << 0 = arg1
163define i32 @shli_i32_2(i32 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000164 %A = shl i32 %arg1, 0
165 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000166}
167
168define i32 @shli_i32_3(i32 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000169 %A = shl i32 16383, %arg1
170 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000171}
172
173; Should generate 0, 0 << arg1 = 0
174define i32 @shli_i32_4(i32 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000175 %A = shl i32 0, %arg1
176 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000177}
178
Chris Lattner26b00002011-06-17 03:14:27 +0000179define signext i32 @shli_i32_5(i32 signext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000180 %A = shl i32 %arg1, 12
181 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000182}
183
184; Should not generate anything other than the return, arg1 << 0 = arg1
Chris Lattner26b00002011-06-17 03:14:27 +0000185define signext i32 @shli_i32_6(i32 signext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000186 %A = shl i32 %arg1, 0
187 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000188}
189
Chris Lattner26b00002011-06-17 03:14:27 +0000190define signext i32 @shli_i32_7(i32 signext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000191 %A = shl i32 16383, %arg1
192 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000193}
194
195; Should generate 0, 0 << arg1 = 0
Chris Lattner26b00002011-06-17 03:14:27 +0000196define signext i32 @shli_i32_8(i32 signext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000197 %A = shl i32 0, %arg1
198 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000199}
200
Chris Lattner26b00002011-06-17 03:14:27 +0000201define zeroext i32 @shli_i32_9(i32 zeroext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000202 %A = shl i32 %arg1, 12
203 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000204}
205
206; Should not generate anything other than the return, arg1 << 0 = arg1
Chris Lattner26b00002011-06-17 03:14:27 +0000207define zeroext i32 @shli_i32_10(i32 zeroext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000208 %A = shl i32 %arg1, 0
209 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000210}
211
Chris Lattner26b00002011-06-17 03:14:27 +0000212define zeroext i32 @shli_i32_11(i32 zeroext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000213 %A = shl i32 16383, %arg1
214 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000215}
216
217; Should generate 0, 0 << arg1 = 0
Chris Lattner26b00002011-06-17 03:14:27 +0000218define zeroext i32 @shli_i32_12(i32 zeroext %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000219 %A = shl i32 0, %arg1
220 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000221}
Scott Michel02d711b2008-12-30 23:28:25 +0000222
223;; i64 shift left
224
225define i64 @shl_i64_1(i64 %arg1) {
226 %A = shl i64 %arg1, 9
227 ret i64 %A
228}
229
230define i64 @shl_i64_2(i64 %arg1) {
231 %A = shl i64 %arg1, 3
232 ret i64 %A
233}
234
235define i64 @shl_i64_3(i64 %arg1, i32 %shift) {
236 %1 = zext i32 %shift to i64
237 %2 = shl i64 %arg1, %1
238 ret i64 %2
239}
240
241;; i64 shift right logical (shift 0s from the right)
242
243define i64 @lshr_i64_1(i64 %arg1) {
244 %1 = lshr i64 %arg1, 9
245 ret i64 %1
246}
247
248define i64 @lshr_i64_2(i64 %arg1) {
249 %1 = lshr i64 %arg1, 3
250 ret i64 %1
251}
252
253define i64 @lshr_i64_3(i64 %arg1, i32 %shift) {
254 %1 = zext i32 %shift to i64
255 %2 = lshr i64 %arg1, %1
256 ret i64 %2
257}
258
259;; i64 shift right arithmetic (shift 1s from the right)
260
261define i64 @ashr_i64_1(i64 %arg) {
262 %1 = ashr i64 %arg, 9
263 ret i64 %1
264}
265
266define i64 @ashr_i64_2(i64 %arg) {
267 %1 = ashr i64 %arg, 3
268 ret i64 %1
269}
270
271define i64 @ashr_i64_3(i64 %arg1, i32 %shift) {
272 %1 = zext i32 %shift to i64
273 %2 = ashr i64 %arg1, %1
274 ret i64 %2
275}
Scott Michelc9c8b2a2009-01-26 03:31:40 +0000276
277define i32 @hi32_i64(i64 %arg) {
278 %1 = lshr i64 %arg, 32
279 %2 = trunc i64 %1 to i32
280 ret i32 %2
281}
Kalle Raiskila9363f732010-11-29 14:44:28 +0000282
283; some random tests
284define i128 @test_lshr_i128( i128 %val ) {
285 ;CHECK: test_lshr_i128
286 ;CHECK: sfi
287 ;CHECK: rotqmbi
288 ;CHECK: rotqmbybi
289 ;CHECK: bi $lr
290 %rv = lshr i128 %val, 64
291 ret i128 %rv
292}
Kalle Raiskila31cbac12011-03-04 13:19:18 +0000293
294;Vector shifts
295define <2 x i32> @shl_v2i32(<2 x i32> %val, <2 x i32> %sh) {
296;CHECK: shl
297;CHECK: bi $lr
298 %rv = shl <2 x i32> %val, %sh
299 ret <2 x i32> %rv
300}
301
302define <4 x i32> @shl_v4i32(<4 x i32> %val, <4 x i32> %sh) {
303;CHECK: shl
304;CHECK: bi $lr
305 %rv = shl <4 x i32> %val, %sh
306 ret <4 x i32> %rv
307}
308
309define <8 x i16> @shl_v8i16(<8 x i16> %val, <8 x i16> %sh) {
310;CHECK: shlh
311;CHECK: bi $lr
312 %rv = shl <8 x i16> %val, %sh
313 ret <8 x i16> %rv
314}
315
316define <4 x i32> @lshr_v4i32(<4 x i32> %val, <4 x i32> %sh) {
317;CHECK: rotm
318;CHECK: bi $lr
319 %rv = lshr <4 x i32> %val, %sh
320 ret <4 x i32> %rv
321}
322
323define <8 x i16> @lshr_v8i16(<8 x i16> %val, <8 x i16> %sh) {
324;CHECK: sfhi
325;CHECK: rothm
326;CHECK: bi $lr
327 %rv = lshr <8 x i16> %val, %sh
328 ret <8 x i16> %rv
329}
330
331define <4 x i32> @ashr_v4i32(<4 x i32> %val, <4 x i32> %sh) {
332;CHECK: rotma
333;CHECK: bi $lr
334 %rv = ashr <4 x i32> %val, %sh
335 ret <4 x i32> %rv
336}
337
338define <8 x i16> @ashr_v8i16(<8 x i16> %val, <8 x i16> %sh) {
339;CHECK: sfhi
340;CHECK: rotmah
341;CHECK: bi $lr
342 %rv = ashr <8 x i16> %val, %sh
343 ret <8 x i16> %rv
344}
Nadav Rotemc32a8c92011-10-16 10:02:06 +0000345
346define <2 x i64> @special_const() {
347 ret <2 x i64> <i64 4294967295, i64 4294967295>
348}