1 ; Test load/store pairs that act as memcpys.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
11 @g5src = external global fp128, align 16
12 @g5dst = external global fp128, align 16
14 ; Test the simple i8 case.
15 define void @f1(i8 *%ptr1) {
17 ; CHECK: mvc 1(1,%r2), 0(%r2)
19 %ptr2 = getelementptr i8, i8 *%ptr1, i64 1
20 %val = load i8, i8 *%ptr1
21 store i8 %val, i8 *%ptr2
25 ; Test i8 cases where the value is zero-extended to 32 bits.
26 define void @f2(i8 *%ptr1) {
28 ; CHECK: mvc 1(1,%r2), 0(%r2)
30 %ptr2 = getelementptr i8, i8 *%ptr1, i64 1
31 %val = load i8, i8 *%ptr1
32 %ext = zext i8 %val to i32
33 %trunc = trunc i32 %ext to i8
34 store i8 %trunc, i8 *%ptr2
38 ; Test i8 cases where the value is zero-extended to 64 bits.
39 define void @f3(i8 *%ptr1) {
41 ; CHECK: mvc 1(1,%r2), 0(%r2)
43 %ptr2 = getelementptr i8, i8 *%ptr1, i64 1
44 %val = load i8, i8 *%ptr1
45 %ext = zext i8 %val to i64
46 %trunc = trunc i64 %ext to i8
47 store i8 %trunc, i8 *%ptr2
51 ; Test i8 cases where the value is sign-extended to 32 bits.
52 define void @f4(i8 *%ptr1) {
54 ; CHECK: mvc 1(1,%r2), 0(%r2)
56 %ptr2 = getelementptr i8, i8 *%ptr1, i64 1
57 %val = load i8, i8 *%ptr1
58 %ext = sext i8 %val to i32
59 %trunc = trunc i32 %ext to i8
60 store i8 %trunc, i8 *%ptr2
64 ; Test i8 cases where the value is sign-extended to 64 bits.
65 define void @f5(i8 *%ptr1) {
67 ; CHECK: mvc 1(1,%r2), 0(%r2)
69 %ptr2 = getelementptr i8, i8 *%ptr1, i64 1
70 %val = load i8, i8 *%ptr1
71 %ext = sext i8 %val to i64
72 %trunc = trunc i64 %ext to i8
73 store i8 %trunc, i8 *%ptr2
77 ; Test the simple i16 case.
78 define void @f6(i16 *%ptr1) {
80 ; CHECK: mvc 2(2,%r2), 0(%r2)
82 %ptr2 = getelementptr i16, i16 *%ptr1, i64 1
83 %val = load i16, i16 *%ptr1
84 store i16 %val, i16 *%ptr2
88 ; Test i16 cases where the value is zero-extended to 32 bits.
89 define void @f7(i16 *%ptr1) {
91 ; CHECK: mvc 2(2,%r2), 0(%r2)
93 %ptr2 = getelementptr i16, i16 *%ptr1, i64 1
94 %val = load i16, i16 *%ptr1
95 %ext = zext i16 %val to i32
96 %trunc = trunc i32 %ext to i16
97 store i16 %trunc, i16 *%ptr2
101 ; Test i16 cases where the value is zero-extended to 64 bits.
102 define void @f8(i16 *%ptr1) {
104 ; CHECK: mvc 2(2,%r2), 0(%r2)
106 %ptr2 = getelementptr i16, i16 *%ptr1, i64 1
107 %val = load i16, i16 *%ptr1
108 %ext = zext i16 %val to i64
109 %trunc = trunc i64 %ext to i16
110 store i16 %trunc, i16 *%ptr2
114 ; Test i16 cases where the value is sign-extended to 32 bits.
115 define void @f9(i16 *%ptr1) {
117 ; CHECK: mvc 2(2,%r2), 0(%r2)
119 %ptr2 = getelementptr i16, i16 *%ptr1, i64 1
120 %val = load i16, i16 *%ptr1
121 %ext = sext i16 %val to i32
122 %trunc = trunc i32 %ext to i16
123 store i16 %trunc, i16 *%ptr2
127 ; Test i16 cases where the value is sign-extended to 64 bits.
128 define void @f10(i16 *%ptr1) {
130 ; CHECK: mvc 2(2,%r2), 0(%r2)
132 %ptr2 = getelementptr i16, i16 *%ptr1, i64 1
133 %val = load i16, i16 *%ptr1
134 %ext = sext i16 %val to i64
135 %trunc = trunc i64 %ext to i16
136 store i16 %trunc, i16 *%ptr2
140 ; Test the simple i32 case.
141 define void @f11(i32 *%ptr1) {
143 ; CHECK: mvc 4(4,%r2), 0(%r2)
145 %ptr2 = getelementptr i32, i32 *%ptr1, i64 1
146 %val = load i32, i32 *%ptr1
147 store i32 %val, i32 *%ptr2
151 ; Test i32 cases where the value is zero-extended to 64 bits.
152 define void @f12(i32 *%ptr1) {
154 ; CHECK: mvc 4(4,%r2), 0(%r2)
156 %ptr2 = getelementptr i32, i32 *%ptr1, i64 1
157 %val = load i32, i32 *%ptr1
158 %ext = zext i32 %val to i64
159 %trunc = trunc i64 %ext to i32
160 store i32 %trunc, i32 *%ptr2
164 ; Test i32 cases where the value is sign-extended to 64 bits.
165 define void @f13(i32 *%ptr1) {
167 ; CHECK: mvc 4(4,%r2), 0(%r2)
169 %ptr2 = getelementptr i32, i32 *%ptr1, i64 1
170 %val = load i32, i32 *%ptr1
171 %ext = sext i32 %val to i64
172 %trunc = trunc i64 %ext to i32
173 store i32 %trunc, i32 *%ptr2
178 define void @f14(i64 *%ptr1) {
180 ; CHECK: mvc 8(8,%r2), 0(%r2)
182 %ptr2 = getelementptr i64, i64 *%ptr1, i64 1
183 %val = load i64, i64 *%ptr1
184 store i64 %val, i64 *%ptr2
189 define void @f15(float *%ptr1) {
191 ; CHECK: mvc 4(4,%r2), 0(%r2)
193 %ptr2 = getelementptr float, float *%ptr1, i64 1
194 %val = load float, float *%ptr1
195 store float %val, float *%ptr2
200 define void @f16(double *%ptr1) {
202 ; CHECK: mvc 8(8,%r2), 0(%r2)
204 %ptr2 = getelementptr double, double *%ptr1, i64 1
205 %val = load double, double *%ptr1
206 store double %val, double *%ptr2
210 ; Test the f128 case.
211 define void @f17(fp128 *%ptr1) {
213 ; CHECK: mvc 16(16,%r2), 0(%r2)
215 %ptr2 = getelementptr fp128, fp128 *%ptr1, i64 1
216 %val = load fp128, fp128 *%ptr1
217 store fp128 %val, fp128 *%ptr2
221 ; Make sure that we don't use MVC if the load is volatile.
222 define void @f18(i64 *%ptr1) {
226 %ptr2 = getelementptr i64, i64 *%ptr1, i64 1
227 %val = load volatile i64, i64 *%ptr1
228 store i64 %val, i64 *%ptr2
232 ; ...likewise the store.
233 define void @f19(i64 *%ptr1) {
237 %ptr2 = getelementptr i64, i64 *%ptr1, i64 1
238 %val = load i64, i64 *%ptr1
239 store volatile i64 %val, i64 *%ptr2
243 ; Test that MVC is not used for aligned loads and stores if there is
244 ; no way of telling whether they alias. We don't want to use MVC in
245 ; cases where the addresses could be equal.
246 define void @f20(i64 *%ptr1, i64 *%ptr2) {
250 %val = load i64, i64 *%ptr1
251 store i64 %val, i64 *%ptr2
255 ; ...and again for unaligned loads and stores.
256 define void @f21(i64 *%ptr1, i64 *%ptr2) {
260 %val = load i64, i64 *%ptr1, align 2
261 store i64 %val, i64 *%ptr2, align 2
265 ; Test a case where there is definite overlap.
266 define void @f22(i64 %base) {
270 %add = add i64 %base, 1
271 %ptr1 = inttoptr i64 %base to i64 *
272 %ptr2 = inttoptr i64 %add to i64 *
273 %val = load i64, i64 *%ptr1, align 1
274 store i64 %val, i64 *%ptr2, align 1
278 ; Test that we can use MVC for global addresses for i8.
279 define void @f23(i8 *%ptr) {
281 ; CHECK-DAG: larl [[SRC:%r[0-5]]], g1src
282 ; CHECK-DAG: larl [[DST:%r[0-5]]], g1dst
283 ; CHECK: mvc 0(1,[[DST]]), 0([[SRC]])
285 %val = load i8, i8 *@g1src
286 store i8 %val, i8 *@g1dst
290 ; Test that we use LHRL and STHRL for i16.
291 define void @f24(i16 *%ptr) {
293 ; CHECK: lhrl [[REG:%r[0-5]]], g2src
294 ; CHECK: sthrl [[REG]], g2dst
296 %val = load i16, i16 *@g2src
297 store i16 %val, i16 *@g2dst
301 ; Test that we use LRL for i32.
302 define void @f25(i32 *%ptr) {
304 ; CHECK: lrl [[REG:%r[0-5]]], g3
305 ; CHECK: st [[REG]], 0(%r2)
307 %val = load i32, i32 *@g3
308 store i32 %val, i32 *%ptr
313 define void @f26(i32 *%ptr) {
315 ; CHECK: l [[REG:%r[0-5]]], 0(%r2)
316 ; CHECK: strl [[REG]], g3
318 %val = load i32, i32 *%ptr
319 store i32 %val, i32 *@g3
323 ; Test that we use LGRL for i64.
324 define void @f27(i64 *%ptr) {
326 ; CHECK: lgrl [[REG:%r[0-5]]], g4
327 ; CHECK: stg [[REG]], 0(%r2)
329 %val = load i64, i64 *@g4
330 store i64 %val, i64 *%ptr
335 define void @f28(i64 *%ptr) {
337 ; CHECK: lg [[REG:%r[0-5]]], 0(%r2)
338 ; CHECK: stgrl [[REG]], g4
340 %val = load i64, i64 *%ptr
341 store i64 %val, i64 *@g4
345 ; Test that we can use MVC for global addresses for fp128.
346 define void @f29(fp128 *%ptr) {
348 ; CHECK-DAG: larl [[SRC:%r[0-5]]], g5src
349 ; CHECK-DAG: larl [[DST:%r[0-5]]], g5dst
350 ; CHECK: mvc 0(16,[[DST]]), 0([[SRC]])
352 %val = load fp128, fp128 *@g5src, align 16
353 store fp128 %val, fp128 *@g5dst, align 16
357 ; Test a case where offset disambiguation is enough.
358 define void @f30(i64 *%ptr1) {
360 ; CHECK: mvc 8(8,%r2), 0(%r2)
362 %ptr2 = getelementptr i64, i64 *%ptr1, i64 1
363 %val = load i64, i64 *%ptr1, align 1
364 store i64 %val, i64 *%ptr2, align 1
368 ; Test f21 in cases where TBAA tells us there is no alias.
369 define void @f31(i64 *%ptr1, i64 *%ptr2) {
371 ; CHECK: mvc 0(8,%r3), 0(%r2)
373 %val = load i64, i64 *%ptr1, align 2, !tbaa !1
374 store i64 %val, i64 *%ptr2, align 2, !tbaa !2
378 ; Test f21 in cases where TBAA is present but doesn't help.
379 define void @f32(i64 *%ptr1, i64 *%ptr2) {
383 %val = load i64, i64 *%ptr1, align 2, !tbaa !1
384 store i64 %val, i64 *%ptr2, align 2, !tbaa !1
389 !1 = !{ !3, !3, i64 0 }
390 !2 = !{ !4, !4, i64 0 }
391 !3 = !{ !"set1", !0 }
392 !4 = !{ !"set2", !0 }