1 ; RUN: llc -march=arc < %s | FileCheck %s
4 ; CHECK: ld %r0, [%r0,16000]
6 define i32 @load32(i32* %bp) nounwind {
8 %gep = getelementptr i32, i32* %bp, i32 4000
9 %v = load i32, i32* %gep, align 4
14 ; CHECK: ldh %r0, [%r0,8000]
16 define i16 @load16(i16* %bp) nounwind {
18 %gep = getelementptr i16, i16* %bp, i32 4000
19 %v = load i16, i16* %gep, align 2
24 ; CHECK: ldb %r0, [%r0,4000]
26 define i8 @load8(i8* %bp) nounwind {
28 %gep = getelementptr i8, i8* %bp, i32 4000
29 %v = load i8, i8* %gep, align 1
33 ; CHECK-LABEL: sextload16
34 ; CHECK: ldh.x %r0, [%r0,8000]
36 define i32 @sextload16(i16* %bp) nounwind {
38 %gep = getelementptr i16, i16* %bp, i32 4000
39 %vl = load i16, i16* %gep, align 2
40 %v = sext i16 %vl to i32
44 ; CHECK-LABEL: sextload8
45 ; CHECK: ldb.x %r0, [%r0,4000]
47 define i32 @sextload8(i8* %bp) nounwind {
49 %gep = getelementptr i8, i8* %bp, i32 4000
50 %vl = load i8, i8* %gep, align 1
51 %v = sext i8 %vl to i32
55 ; CHECK-LABEL: s_sextload16
56 ; CHECK: ldh.x %r0, [%r0,32]
58 define i32 @s_sextload16(i16* %bp) nounwind {
60 %gep = getelementptr i16, i16* %bp, i32 16
61 %vl = load i16, i16* %gep, align 2
62 %v = sext i16 %vl to i32
66 ; CHECK-LABEL: s_sextload8
67 ; CHECK: ldb.x %r0, [%r0,16]
69 define i32 @s_sextload8(i8* %bp) nounwind {
71 %gep = getelementptr i8, i8* %bp, i32 16
72 %vl = load i8, i8* %gep, align 1
73 %v = sext i8 %vl to i32
77 ; CHECK-LABEL: store32
78 ; CHECK: add %r[[REG:[0-9]+]], %r1, 16000
79 ; CHECK: st %r0, [%r[[REG]],0]
81 ; Long range stores (offset does not fit in s9) must be add followed by st.
82 define void @store32(i32 %val, i32* %bp) nounwind {
84 %gep = getelementptr i32, i32* %bp, i32 4000
85 store i32 %val, i32* %gep, align 4
89 ; CHECK-LABEL: store16
90 ; CHECK: add %r[[REG:[0-9]+]], %r1, 8000
91 ; CHECK: sth %r0, [%r[[REG]],0]
93 define void @store16(i16 zeroext %val, i16* %bp) nounwind {
95 %gep = getelementptr i16, i16* %bp, i32 4000
96 store i16 %val, i16* %gep, align 2
100 ; CHECK-LABEL: store8
101 ; CHECK: add %r[[REG:[0-9]+]], %r1, 4000
102 ; CHECK: stb %r0, [%r[[REG]],0]
104 define void @store8(i8 zeroext %val, i8* %bp) nounwind {
106 %gep = getelementptr i8, i8* %bp, i32 4000
107 store i8 %val, i8* %gep, align 1
111 ; Short range stores can be done with [reg, s9].
112 ; CHECK-LABEL: s_store32
114 ; CHECK: st %r0, [%r1,64]
115 define void @s_store32(i32 %val, i32* %bp) nounwind {
117 %gep = getelementptr i32, i32* %bp, i32 16
118 store i32 %val, i32* %gep, align 4
122 ; CHECK-LABEL: s_store16
124 ; CHECK: sth %r0, [%r1,32]
125 define void @s_store16(i16 zeroext %val, i16* %bp) nounwind {
127 %gep = getelementptr i16, i16* %bp, i32 16
128 store i16 %val, i16* %gep, align 2
132 ; CHECK-LABEL: s_store8
134 ; CHECK: stb %r0, [%r1,16]
135 define void @s_store8(i8 zeroext %val, i8* %bp) nounwind {
137 %gep = getelementptr i8, i8* %bp, i32 16
138 store i8 %val, i8* %gep, align 1
143 @aaaa = internal global [128 x i32] zeroinitializer
144 @bbbb = internal global [128 x i16] zeroinitializer
145 @cccc = internal global [128 x i8] zeroinitializer
147 ; CHECK-LABEL: g_store32
149 ; CHECK: st %r0, [@aaaa+64]
150 define void @g_store32(i32 %val) nounwind {
152 store i32 %val, i32* getelementptr inbounds ([128 x i32], [128 x i32]* @aaaa, i32 0, i32 16), align 4
156 ; CHECK-LABEL: g_load32
158 ; CHECK: ld %r0, [@aaaa+64]
159 define i32 @g_load32() nounwind {
160 %gep = getelementptr inbounds [128 x i32], [128 x i32]* @aaaa, i32 0, i32 16
161 %v = load i32, i32* %gep, align 4
165 ; CHECK-LABEL: g_store16
167 ; CHECK: sth %r0, [@bbbb+32]
168 define void @g_store16(i16 %val) nounwind {
170 store i16 %val, i16* getelementptr inbounds ([128 x i16], [128 x i16]* @bbbb, i16 0, i16 16), align 2
174 ; CHECK-LABEL: g_load16
176 ; CHECK: ldh %r0, [@bbbb+32]
177 define i16 @g_load16() nounwind {
178 %gep = getelementptr inbounds [128 x i16], [128 x i16]* @bbbb, i16 0, i16 16
179 %v = load i16, i16* %gep, align 2
183 ; CHECK-LABEL: g_store8
185 ; CHECK: stb %r0, [@cccc+16]
186 define void @g_store8(i8 %val) nounwind {
188 store i8 %val, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @cccc, i8 0, i8 16), align 1
192 ; CHECK-LABEL: g_load8
194 ; CHECK: ldb %r0, [@cccc+16]
195 define i8 @g_load8() nounwind {
196 %gep = getelementptr inbounds [128 x i8], [128 x i8]* @cccc, i8 0, i8 16
197 %v = load i8, i8* %gep, align 1
201 ; CHECK-LABEL: align2_load32
202 ; CHECK-DAG: ldh %r[[REG0:[0-9]+]], [%r0,0]
203 ; CHECK-DAG: ldh %r[[REG1:[0-9]+]], [%r0,2]
204 ; CHECK-DAG: asl %r[[REG2:[0-9]+]], %r[[REG1]], 16
205 define i32 @align2_load32(i8* %p) nounwind {
207 %bp = bitcast i8* %p to i32*
208 %v = load i32, i32* %bp, align 2
212 ; CHECK-LABEL: align1_load32
213 ; CHECK-DAG: ldb %r[[REG0:[0-9]+]], [%r0,0]
214 ; CHECK-DAG: ldb %r[[REG1:[0-9]+]], [%r0,1]
215 ; CHECK-DAG: ldb %r[[REG2:[0-9]+]], [%r0,2]
216 ; CHECK-DAG: ldb %r[[REG3:[0-9]+]], [%r0,3]
217 ; CHECK-DAG: asl %r[[AREG1:[0-9]+]], %r[[REG1]], 8
218 ; CHECK-DAG: asl %r[[AREG3:[0-9]+]], %r[[REG3]], 8
219 define i32 @align1_load32(i8* %p) nounwind {
221 %bp = bitcast i8* %p to i32*
222 %v = load i32, i32* %bp, align 1
226 ; CHECK-LABEL: align1_load16
227 ; CHECK-DAG: ldb %r[[REG0:[0-9]+]], [%r0,0]
228 ; CHECK-DAG: ldb %r[[REG1:[0-9]+]], [%r0,1]
229 ; CHECK-DAG: asl %r[[REG2:[0-9]+]], %r[[REG1]], 8
230 define i16 @align1_load16(i8* %p) nounwind {
232 %bp = bitcast i8* %p to i16*
233 %v = load i16, i16* %bp, align 1
237 ; CHECK-LABEL: align2_store32
238 ; CHECK-DAG: lsr %r[[REG:[0-9]+]], %r1, 16
239 ; CHECK-DAG: sth %r1, [%r0,0]
240 ; CHECK-DAG: sth %r[[REG:[0-9]+]], [%r0,2]
241 define void @align2_store32(i8* %p, i32 %v) nounwind {
243 %bp = bitcast i8* %p to i32*
244 store i32 %v, i32* %bp, align 2
248 ; CHECK-LABEL: align1_store16
249 ; CHECK-DAG: lsr %r[[REG:[0-9]+]], %r1, 8
250 ; CHECK-DAG: stb %r1, [%r0,0]
251 ; CHECK-DAG: stb %r[[REG:[0-9]+]], [%r0,1]
252 define void @align1_store16(i8* %p, i16 %v) nounwind {
254 %bp = bitcast i8* %p to i16*
255 store i16 %v, i16* %bp, align 1
259 ; CHECK-LABEL: align1_store32
260 ; CHECK-DAG: lsr %r[[REG0:[0-9]+]], %r1, 8
261 ; CHECK-DAG: lsr %r[[REG1:[0-9]+]], %r1, 16
262 ; CHECK-DAG: lsr %r[[REG2:[0-9]+]], %r1, 24
263 ; CHECK-DAG: stb %r1, [%r0,0]
264 ; CHECK-DAG: stb %r[[REG0]], [%r0,1]
265 ; CHECK-DAG: stb %r[[REG1]], [%r0,2]
266 ; CHECK-DAG: stb %r[[REG2]], [%r0,3]
267 define void @align1_store32(i8* %p, i32 %v) nounwind {
269 %bp = bitcast i8* %p to i32*
270 store i32 %v, i32* %bp, align 1