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