1 ; Test memcpy using MVC.
3 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
4 ; RUN: llc -mtriple=s390x-linux-gnu -filetype=null %s
6 declare void @llvm.memcpy.p0.p0.i32(ptr nocapture, ptr nocapture, i32, i1) nounwind
7 declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind
8 declare void @foo(ptr, ptr)
10 ; Test a no-op move, i32 version.
11 define void @f1(ptr %dest, ptr %src) {
16 call void @llvm.memcpy.p0.p0.i32(ptr %dest, ptr %src, i32 0, i1 false)
20 ; Test a no-op move, i64 version.
21 define void @f2(ptr %dest, ptr %src) {
26 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 0, i1 false)
30 ; Test a 1-byte move, i32 version.
31 define void @f3(ptr %dest, ptr %src) {
33 ; CHECK: mvc 0(1,%r2), 0(%r3)
35 call void @llvm.memcpy.p0.p0.i32(ptr %dest, ptr %src, i32 1, i1 false)
39 ; Test a 1-byte move, i64 version.
40 define void @f4(ptr %dest, ptr %src) {
42 ; CHECK: mvc 0(1,%r2), 0(%r3)
44 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 1, i1 false)
48 ; Test the upper range of a single MVC, i32 version.
49 define void @f5(ptr %dest, ptr %src) {
51 ; CHECK: mvc 0(256,%r2), 0(%r3)
53 call void @llvm.memcpy.p0.p0.i32(ptr %dest, ptr %src, i32 256, i1 false)
57 ; Test the upper range of a single MVC, i64 version.
58 define void @f6(ptr %dest, ptr %src) {
60 ; CHECK: mvc 0(256,%r2), 0(%r3)
62 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 256, i1 false)
66 ; Test the first case that needs two MVCs.
67 define void @f7(ptr %dest, ptr %src) {
69 ; CHECK: mvc 0(256,%r2), 0(%r3)
70 ; CHECK: mvc 256(1,%r2), 256(%r3)
72 call void @llvm.memcpy.p0.p0.i32(ptr %dest, ptr %src, i32 257, i1 false)
76 ; Test the last-but-one case that needs two MVCs.
77 define void @f8(ptr %dest, ptr %src) {
79 ; CHECK: mvc 0(256,%r2), 0(%r3)
80 ; CHECK: mvc 256(255,%r2), 256(%r3)
82 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 511, i1 false)
86 ; Test the last case that needs two MVCs.
87 define void @f9(ptr %dest, ptr %src) {
89 ; CHECK: mvc 0(256,%r2), 0(%r3)
90 ; CHECK: mvc 256(256,%r2), 256(%r3)
92 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 512, i1 false)
96 ; Test an arbitrary value that uses straight-line code.
97 define void @f10(ptr %dest, ptr %src) {
99 ; CHECK: mvc 0(256,%r2), 0(%r3)
100 ; CHECK: mvc 256(256,%r2), 256(%r3)
101 ; CHECK: mvc 512(256,%r2), 512(%r3)
102 ; CHECK: mvc 768(256,%r2), 768(%r3)
103 ; CHECK: mvc 1024(255,%r2), 1024(%r3)
105 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 1279, i1 false)
109 ; ...and again in cases where not all parts are in range of MVC.
110 define void @f11(ptr %srcbase, ptr %destbase) {
112 ; CHECK: mvc 4000(256,%r2), 3500(%r3)
113 ; CHECK: lay [[NEWDEST:%r[1-5]]], 4256(%r2)
114 ; CHECK: mvc 0(256,[[NEWDEST]]), 3756(%r3)
115 ; CHECK: mvc 256(256,[[NEWDEST]]), 4012(%r3)
116 ; CHECK: lay [[NEWSRC:%r[1-5]]], 4268(%r3)
117 ; CHECK: mvc 512(256,[[NEWDEST]]), 0([[NEWSRC]])
118 ; CHECK: mvc 768(255,[[NEWDEST]]), 256([[NEWSRC]])
120 %dest = getelementptr i8, ptr %srcbase, i64 4000
121 %src = getelementptr i8, ptr %destbase, i64 3500
122 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 1279, i1 false)
126 ; ...and again with a destination frame base that goes out of range.
129 ; CHECK: brasl %r14, foo@PLT
130 ; CHECK: mvc 4076(256,%r15), 2100(%r15)
131 ; CHECK: lay [[NEWDEST:%r[1-5]]], 4332(%r15)
132 ; CHECK: mvc 0(256,[[NEWDEST]]), 2356(%r15)
133 ; CHECK: mvc 256(256,[[NEWDEST]]), 2612(%r15)
134 ; CHECK: mvc 512(256,[[NEWDEST]]), 2868(%r15)
135 ; CHECK: mvc 768(255,[[NEWDEST]]), 3124(%r15)
136 ; CHECK: brasl %r14, foo@PLT
138 %arr = alloca [6000 x i8]
139 %dest = getelementptr [6000 x i8], ptr %arr, i64 0, i64 3900
140 %src = getelementptr [6000 x i8], ptr %arr, i64 0, i64 1924
141 call void @foo(ptr %dest, ptr %src)
142 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 1279, i1 false)
143 call void @foo(ptr %dest, ptr %src)
147 ; ...and again with a source frame base that goes out of range.
150 ; CHECK: brasl %r14, foo@PLT
151 ; CHECK: mvc 200(256,%r15), 3826(%r15)
152 ; CHECK: mvc 456(256,%r15), 4082(%r15)
153 ; CHECK: lay [[NEWSRC:%r[1-5]]], 4338(%r15)
154 ; CHECK: mvc 712(256,%r15), 0([[NEWSRC]])
155 ; CHECK: mvc 968(256,%r15), 256([[NEWSRC]])
156 ; CHECK: mvc 1224(255,%r15), 512([[NEWSRC]])
157 ; CHECK: brasl %r14, foo@PLT
159 %arr = alloca [6000 x i8]
160 %dest = getelementptr [6000 x i8], ptr %arr, i64 0, i64 24
161 %src = getelementptr [6000 x i8], ptr %arr, i64 0, i64 3650
162 call void @foo(ptr %dest, ptr %src)
163 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 1279, i1 false)
164 call void @foo(ptr %dest, ptr %src)
168 ; Test the last case that is done using straight-line code.
169 define void @f14(ptr %dest, ptr %src) {
171 ; CHECK: mvc 0(256,%r2), 0(%r3)
172 ; CHECK: mvc 256(256,%r2), 256(%r3)
173 ; CHECK: mvc 512(256,%r2), 512(%r3)
174 ; CHECK: mvc 768(256,%r2), 768(%r3)
175 ; CHECK: mvc 1024(256,%r2), 1024(%r3)
176 ; CHECK: mvc 1280(256,%r2), 1280(%r3)
178 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 1536, i1 false)
182 ; Test the first case that is done using a loop.
183 define void @f15(ptr %dest, ptr %src) {
185 ; CHECK: lghi [[COUNT:%r[0-5]]], 6
186 ; CHECK: [[LABEL:\.L[^:]*]]:
187 ; CHECK: pfd 2, 768(%r2)
188 ; CHECK: mvc 0(256,%r2), 0(%r3)
189 ; CHECK: la %r2, 256(%r2)
190 ; CHECK: la %r3, 256(%r3)
191 ; CHECK: brctg [[COUNT]], [[LABEL]]
192 ; CHECK: mvc 0(1,%r2), 0(%r3)
194 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 1537, i1 false)
198 ; ...and again with frame bases, where the base must be loaded into a
199 ; register before the loop.
202 ; CHECK: brasl %r14, foo@PLT
203 ; CHECK-DAG: lghi [[COUNT:%r[0-5]]], 6
204 ; CHECK-DAG: la [[BASE:%r[0-5]]], 160(%r15)
205 ; CHECK: [[LABEL:\.L[^:]*]]:
206 ; CHECK: pfd 2, 2368([[BASE]])
207 ; CHECK: mvc 1600(256,[[BASE]]), 0([[BASE]])
208 ; CHECK: la [[BASE]], 256([[BASE]])
209 ; CHECK: brctg [[COUNT]], [[LABEL]]
210 ; CHECK: mvc 1600(1,[[BASE]]), 0([[BASE]])
211 ; CHECK: brasl %r14, foo@PLT
213 %arr = alloca [3200 x i8]
214 %dest = getelementptr [3200 x i8], ptr %arr, i64 0, i64 1600
215 call void @foo(ptr %dest, ptr %arr)
216 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %arr, i64 1537, i1 false)
217 call void @foo(ptr %dest, ptr %arr)
221 ; Test a variable length loop.
222 define void @f17(ptr %dest, ptr %src, i64 %Len) {
225 ; CHECK-NEXT: aghi %r4, -1
226 ; CHECK-NEXT: cgibe %r4, -1, 0(%r14)
227 ; CHECK-NEXT: .LBB16_1:
228 ; CHECK-NEXT: srlg %r0, %r4, 8
229 ; CHECK-NEXT: cgije %r0, 0, .LBB16_3
230 ; CHECK-NEXT: .LBB16_2: # =>This Inner Loop Header: Depth=1
231 ; CHECK-NEXT: pfd 2, 768(%r2)
232 ; CHECK-NEXT: mvc 0(256,%r2), 0(%r3)
233 ; CHECK-NEXT: la %r2, 256(%r2)
234 ; CHECK-NEXT: la %r3, 256(%r3)
235 ; CHECK-NEXT: brctg %r0, .LBB16_2
236 ; CHECK-NEXT: .LBB16_3:
237 ; CHECK-NEXT: exrl %r4, .Ltmp0
238 ; CHECK-NEXT: br %r14
239 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %src, i64 %Len, i1 false)
244 ; CHECK-NEXT: mvc 0(1,%r2), 0(%r3)