1 ; RUN: llc -march=arc < %s | FileCheck %s
4 ; CHECK: ld %r0, [%r0,16000]
6 define i32 @load32(ptr %bp) nounwind {
8 %gep = getelementptr i32, ptr %bp, i32 4000
9 %v = load i32, ptr %gep, align 4
14 ; CHECK: ldh %r0, [%r0,8000]
16 define i16 @load16(ptr %bp) nounwind {
18 %gep = getelementptr i16, ptr %bp, i32 4000
19 %v = load i16, ptr %gep, align 2
24 ; CHECK: ldb %r0, [%r0,4000]
26 define i8 @load8(ptr %bp) nounwind {
28 %gep = getelementptr i8, ptr %bp, i32 4000
29 %v = load i8, ptr %gep, align 1
33 ; CHECK-LABEL: sextload16
34 ; CHECK: ldh.x %r0, [%r0,8000]
36 define i32 @sextload16(ptr %bp) nounwind {
38 %gep = getelementptr i16, ptr %bp, i32 4000
39 %vl = load i16, ptr %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(ptr %bp) nounwind {
49 %gep = getelementptr i8, ptr %bp, i32 4000
50 %vl = load i8, ptr %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(ptr %bp) nounwind {
60 %gep = getelementptr i16, ptr %bp, i32 16
61 %vl = load i16, ptr %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(ptr %bp) nounwind {
71 %gep = getelementptr i8, ptr %bp, i32 16
72 %vl = load i8, ptr %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, ptr %bp) nounwind {
84 %gep = getelementptr i32, ptr %bp, i32 4000
85 store i32 %val, ptr %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, ptr %bp) nounwind {
95 %gep = getelementptr i16, ptr %bp, i32 4000
96 store i16 %val, ptr %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, ptr %bp) nounwind {
106 %gep = getelementptr i8, ptr %bp, i32 4000
107 store i8 %val, ptr %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, ptr %bp) nounwind {
117 %gep = getelementptr i32, ptr %bp, i32 16
118 store i32 %val, ptr %gep, align 4
122 ; CHECK-LABEL: s_store16
124 ; CHECK: sth %r0, [%r1,32]
125 define void @s_store16(i16 zeroext %val, ptr %bp) nounwind {
127 %gep = getelementptr i16, ptr %bp, i32 16
128 store i16 %val, ptr %gep, align 2
132 ; CHECK-LABEL: s_store8
134 ; CHECK: stb %r0, [%r1,16]
135 define void @s_store8(i8 zeroext %val, ptr %bp) nounwind {
137 %gep = getelementptr i8, ptr %bp, i32 16
138 store i8 %val, ptr %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, ptr getelementptr inbounds ([128 x i32], ptr @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], ptr @aaaa, i32 0, i32 16
161 %v = load i32, ptr %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, ptr getelementptr inbounds ([128 x i16], ptr @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], ptr @bbbb, i16 0, i16 16
179 %v = load i16, ptr %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, ptr getelementptr inbounds ([128 x i8], ptr @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], ptr @cccc, i8 0, i8 16
197 %v = load i8, ptr %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(ptr %p) nounwind {
207 %bp = bitcast ptr %p to ptr
208 %v = load i32, ptr %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[[AREG2:[0-9]+]], %r[[REG2]], 16
219 ; CHECK-DAG: asl %r[[AREG3:[0-9]+]], %r[[REG3]], 24
220 ; CHECK-DAG: or %r[[AREG01:[0-9]+]], %r[[AREG1]], %r[[REG0]]
221 ; CHECK-DAG: or %r[[AREG23:[0-9]+]], %r[[AREG3]], %r[[AREG2]]
222 ; CHECK-DAG: or %r0, %r[[AREG23]], %r[[AREG01]]
223 define i32 @align1_load32(ptr %p) nounwind {
225 %bp = bitcast ptr %p to ptr
226 %v = load i32, ptr %bp, align 1
230 ; CHECK-LABEL: align1_load16
231 ; CHECK-DAG: ldb %r[[REG0:[0-9]+]], [%r0,0]
232 ; CHECK-DAG: ldb %r[[REG1:[0-9]+]], [%r0,1]
233 ; CHECK-DAG: asl %r[[REG2:[0-9]+]], %r[[REG1]], 8
234 define i16 @align1_load16(ptr %p) nounwind {
236 %bp = bitcast ptr %p to ptr
237 %v = load i16, ptr %bp, align 1
241 ; CHECK-LABEL: align2_store32
242 ; CHECK-DAG: lsr %r[[REG:[0-9]+]], %r1, 16
243 ; CHECK-DAG: sth %r1, [%r0,0]
244 ; CHECK-DAG: sth %r[[REG:[0-9]+]], [%r0,2]
245 define void @align2_store32(ptr %p, i32 %v) nounwind {
247 %bp = bitcast ptr %p to ptr
248 store i32 %v, ptr %bp, align 2
252 ; CHECK-LABEL: align1_store16
253 ; CHECK-DAG: lsr %r[[REG:[0-9]+]], %r1, 8
254 ; CHECK-DAG: stb %r1, [%r0,0]
255 ; CHECK-DAG: stb %r[[REG:[0-9]+]], [%r0,1]
256 define void @align1_store16(ptr %p, i16 %v) nounwind {
258 %bp = bitcast ptr %p to ptr
259 store i16 %v, ptr %bp, align 1
263 ; CHECK-LABEL: align1_store32
264 ; CHECK-DAG: lsr %r[[REG0:[0-9]+]], %r1, 8
265 ; CHECK-DAG: lsr %r[[REG1:[0-9]+]], %r1, 16
266 ; CHECK-DAG: lsr %r[[REG2:[0-9]+]], %r1, 24
267 ; CHECK-DAG: stb %r1, [%r0,0]
268 ; CHECK-DAG: stb %r[[REG0]], [%r0,1]
269 ; CHECK-DAG: stb %r[[REG1]], [%r0,2]
270 ; CHECK-DAG: stb %r[[REG2]], [%r0,3]
271 define void @align1_store32(ptr %p, i32 %v) nounwind {
273 %bp = bitcast ptr %p to ptr
274 store i32 %v, ptr %bp, align 1