blob: 9dffb98a2345aaf3caea5d0907f20129d31d8a76 [file] [log] [blame]
Dan Gohmanb7c0b242009-09-11 18:36:27 +00001; RUN: llc < %s -march=cellspu > %t1.s
Duncan Sands74789ea2009-01-21 09:41:42 +00002; RUN: grep {shlh } %t1.s | count 9
3; RUN: grep {shlhi } %t1.s | count 3
4; RUN: grep {shl } %t1.s | count 9
5; RUN: grep {shli } %t1.s | count 3
Evan Cheng3927f432009-03-25 20:20:11 +00006; RUN: grep {xshw } %t1.s | count 5
7; RUN: grep {and } %t1.s | count 5
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 Raiskila9363f732010-11-29 14:44:28 +000017; RUN: grep {sfi } %t1.s | count 4
18; 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
23; Vector shifts are not currently supported in gcc or llvm assembly. These are
24; not tested.
25
26; Shift left i16 via register, note that the second operand to shl is promoted
27; to a 32-bit type:
28
29define i16 @shlh_i16_1(i16 %arg1, i16 %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +000030 %A = shl i16 %arg1, %arg2
31 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000032}
33
34define i16 @shlh_i16_2(i16 %arg1, i16 %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +000035 %A = shl i16 %arg2, %arg1
36 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000037}
38
39define i16 @shlh_i16_3(i16 signext %arg1, i16 signext %arg2) signext {
Scott Michel53dec472008-03-05 23:00:19 +000040 %A = shl i16 %arg1, %arg2
41 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000042}
43
44define i16 @shlh_i16_4(i16 signext %arg1, i16 signext %arg2) signext {
Scott Michel53dec472008-03-05 23:00:19 +000045 %A = shl i16 %arg2, %arg1
46 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000047}
48
49define i16 @shlh_i16_5(i16 zeroext %arg1, i16 zeroext %arg2) zeroext {
Scott Michel53dec472008-03-05 23:00:19 +000050 %A = shl i16 %arg1, %arg2
51 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000052}
53
54define i16 @shlh_i16_6(i16 zeroext %arg1, i16 zeroext %arg2) zeroext {
Scott Michel53dec472008-03-05 23:00:19 +000055 %A = shl i16 %arg2, %arg1
56 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000057}
58
59; Shift left i16 with immediate:
60define i16 @shlhi_i16_1(i16 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +000061 %A = shl i16 %arg1, 12
62 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000063}
64
65; Should not generate anything other than the return, arg1 << 0 = arg1
66define i16 @shlhi_i16_2(i16 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +000067 %A = shl i16 %arg1, 0
68 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000069}
70
71define i16 @shlhi_i16_3(i16 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +000072 %A = shl i16 16383, %arg1
73 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000074}
75
76; Should generate 0, 0 << arg1 = 0
77define i16 @shlhi_i16_4(i16 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +000078 %A = shl i16 0, %arg1
79 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000080}
81
82define i16 @shlhi_i16_5(i16 signext %arg1) signext {
Scott Michel53dec472008-03-05 23:00:19 +000083 %A = shl i16 %arg1, 12
84 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000085}
86
87; Should not generate anything other than the return, arg1 << 0 = arg1
88define i16 @shlhi_i16_6(i16 signext %arg1) signext {
Scott Michel53dec472008-03-05 23:00:19 +000089 %A = shl i16 %arg1, 0
90 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000091}
92
93define i16 @shlhi_i16_7(i16 signext %arg1) signext {
Scott Michel53dec472008-03-05 23:00:19 +000094 %A = shl i16 16383, %arg1
95 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +000096}
97
98; Should generate 0, 0 << arg1 = 0
99define i16 @shlhi_i16_8(i16 signext %arg1) signext {
Scott Michel53dec472008-03-05 23:00:19 +0000100 %A = shl i16 0, %arg1
101 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000102}
103
104define i16 @shlhi_i16_9(i16 zeroext %arg1) zeroext {
Scott Michel53dec472008-03-05 23:00:19 +0000105 %A = shl i16 %arg1, 12
106 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000107}
108
109; Should not generate anything other than the return, arg1 << 0 = arg1
110define i16 @shlhi_i16_10(i16 zeroext %arg1) zeroext {
Scott Michel53dec472008-03-05 23:00:19 +0000111 %A = shl i16 %arg1, 0
112 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000113}
114
115define i16 @shlhi_i16_11(i16 zeroext %arg1) zeroext {
Scott Michel53dec472008-03-05 23:00:19 +0000116 %A = shl i16 16383, %arg1
117 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000118}
119
120; Should generate 0, 0 << arg1 = 0
121define i16 @shlhi_i16_12(i16 zeroext %arg1) zeroext {
Scott Michel53dec472008-03-05 23:00:19 +0000122 %A = shl i16 0, %arg1
123 ret i16 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000124}
125
126; Shift left i32 via register, note that the second operand to shl is promoted
127; to a 32-bit type:
128
129define i32 @shl_i32_1(i32 %arg1, i32 %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +0000130 %A = shl i32 %arg1, %arg2
131 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000132}
133
134define i32 @shl_i32_2(i32 %arg1, i32 %arg2) {
Scott Michel53dec472008-03-05 23:00:19 +0000135 %A = shl i32 %arg2, %arg1
136 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000137}
138
139define i32 @shl_i32_3(i32 signext %arg1, i32 signext %arg2) signext {
Scott Michel53dec472008-03-05 23:00:19 +0000140 %A = shl i32 %arg1, %arg2
141 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000142}
143
144define i32 @shl_i32_4(i32 signext %arg1, i32 signext %arg2) signext {
Scott Michel53dec472008-03-05 23:00:19 +0000145 %A = shl i32 %arg2, %arg1
146 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000147}
148
149define i32 @shl_i32_5(i32 zeroext %arg1, i32 zeroext %arg2) zeroext {
Scott Michel53dec472008-03-05 23:00:19 +0000150 %A = shl i32 %arg1, %arg2
151 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000152}
153
154define i32 @shl_i32_6(i32 zeroext %arg1, i32 zeroext %arg2) zeroext {
Scott Michel53dec472008-03-05 23:00:19 +0000155 %A = shl i32 %arg2, %arg1
156 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000157}
158
159; Shift left i32 with immediate:
160define i32 @shli_i32_1(i32 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000161 %A = shl i32 %arg1, 12
162 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000163}
164
165; Should not generate anything other than the return, arg1 << 0 = arg1
166define i32 @shli_i32_2(i32 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000167 %A = shl i32 %arg1, 0
168 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000169}
170
171define i32 @shli_i32_3(i32 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000172 %A = shl i32 16383, %arg1
173 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000174}
175
176; Should generate 0, 0 << arg1 = 0
177define i32 @shli_i32_4(i32 %arg1) {
Scott Michel53dec472008-03-05 23:00:19 +0000178 %A = shl i32 0, %arg1
179 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000180}
181
182define i32 @shli_i32_5(i32 signext %arg1) signext {
Scott Michel53dec472008-03-05 23:00:19 +0000183 %A = shl i32 %arg1, 12
184 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000185}
186
187; Should not generate anything other than the return, arg1 << 0 = arg1
188define i32 @shli_i32_6(i32 signext %arg1) signext {
Scott Michel53dec472008-03-05 23:00:19 +0000189 %A = shl i32 %arg1, 0
190 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000191}
192
193define i32 @shli_i32_7(i32 signext %arg1) signext {
Scott Michel53dec472008-03-05 23:00:19 +0000194 %A = shl i32 16383, %arg1
195 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000196}
197
198; Should generate 0, 0 << arg1 = 0
199define i32 @shli_i32_8(i32 signext %arg1) signext {
Scott Michel53dec472008-03-05 23:00:19 +0000200 %A = shl i32 0, %arg1
201 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000202}
203
204define i32 @shli_i32_9(i32 zeroext %arg1) zeroext {
Scott Michel53dec472008-03-05 23:00:19 +0000205 %A = shl i32 %arg1, 12
206 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000207}
208
209; Should not generate anything other than the return, arg1 << 0 = arg1
210define i32 @shli_i32_10(i32 zeroext %arg1) zeroext {
Scott Michel53dec472008-03-05 23:00:19 +0000211 %A = shl i32 %arg1, 0
212 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000213}
214
215define i32 @shli_i32_11(i32 zeroext %arg1) zeroext {
Scott Michel53dec472008-03-05 23:00:19 +0000216 %A = shl i32 16383, %arg1
217 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000218}
219
220; Should generate 0, 0 << arg1 = 0
221define i32 @shli_i32_12(i32 zeroext %arg1) zeroext {
Scott Michel53dec472008-03-05 23:00:19 +0000222 %A = shl i32 0, %arg1
223 ret i32 %A
Scott Michel0a92af42007-12-19 20:50:49 +0000224}
Scott Michel02d711b2008-12-30 23:28:25 +0000225
226;; i64 shift left
227
228define i64 @shl_i64_1(i64 %arg1) {
229 %A = shl i64 %arg1, 9
230 ret i64 %A
231}
232
233define i64 @shl_i64_2(i64 %arg1) {
234 %A = shl i64 %arg1, 3
235 ret i64 %A
236}
237
238define i64 @shl_i64_3(i64 %arg1, i32 %shift) {
239 %1 = zext i32 %shift to i64
240 %2 = shl i64 %arg1, %1
241 ret i64 %2
242}
243
244;; i64 shift right logical (shift 0s from the right)
245
246define i64 @lshr_i64_1(i64 %arg1) {
247 %1 = lshr i64 %arg1, 9
248 ret i64 %1
249}
250
251define i64 @lshr_i64_2(i64 %arg1) {
252 %1 = lshr i64 %arg1, 3
253 ret i64 %1
254}
255
256define i64 @lshr_i64_3(i64 %arg1, i32 %shift) {
257 %1 = zext i32 %shift to i64
258 %2 = lshr i64 %arg1, %1
259 ret i64 %2
260}
261
262;; i64 shift right arithmetic (shift 1s from the right)
263
264define i64 @ashr_i64_1(i64 %arg) {
265 %1 = ashr i64 %arg, 9
266 ret i64 %1
267}
268
269define i64 @ashr_i64_2(i64 %arg) {
270 %1 = ashr i64 %arg, 3
271 ret i64 %1
272}
273
274define i64 @ashr_i64_3(i64 %arg1, i32 %shift) {
275 %1 = zext i32 %shift to i64
276 %2 = ashr i64 %arg1, %1
277 ret i64 %2
278}
Scott Michelc9c8b2a2009-01-26 03:31:40 +0000279
280define i32 @hi32_i64(i64 %arg) {
281 %1 = lshr i64 %arg, 32
282 %2 = trunc i64 %1 to i32
283 ret i32 %2
284}
Kalle Raiskila9363f732010-11-29 14:44:28 +0000285
286; some random tests
287define i128 @test_lshr_i128( i128 %val ) {
288 ;CHECK: test_lshr_i128
289 ;CHECK: sfi
290 ;CHECK: rotqmbi
291 ;CHECK: rotqmbybi
292 ;CHECK: bi $lr
293 %rv = lshr i128 %val, 64
294 ret i128 %rv
295}