1; RUN: llc < %s -mtriple=arm64-eabi | FileCheck %s
2
3define void @bzero_4_heap(i8* nocapture %c) {
4; CHECK-LABEL: bzero_4_heap:
5; CHECK:       str wzr, [x0]
6; CHECK-NEXT:  ret
7  call void @llvm.memset.p0i8.i64(i8* align 4 %c, i8 0, i64 4, i1 false)
8  ret void
9}
10
11define void @bzero_8_heap(i8* nocapture %c) {
12; CHECK-LABEL: bzero_8_heap:
13; CHECK:       str xzr, [x0]
14; CHECK-NEXT:  ret
15  call void @llvm.memset.p0i8.i64(i8* align 8 %c, i8 0, i64 8, i1 false)
16  ret void
17}
18
19define void @bzero_12_heap(i8* nocapture %c) {
20; CHECK-LABEL: bzero_12_heap:
21; CHECK:       str wzr, [x0, #8]
22; CHECK-NEXT:  str xzr, [x0]
23; CHECK-NEXT:  ret
24  call void @llvm.memset.p0i8.i64(i8* align 8 %c, i8 0, i64 12, i1 false)
25  ret void
26}
27
28define void @bzero_16_heap(i8* nocapture %c) {
29; CHECK-LABEL: bzero_16_heap:
30; CHECK:       stp xzr, xzr, [x0]
31; CHECK-NEXT:  ret
32  call void @llvm.memset.p0i8.i64(i8* align 8 %c, i8 0, i64 16, i1 false)
33  ret void
34}
35
36define void @bzero_32_heap(i8* nocapture %c) {
37; CHECK-LABEL: bzero_32_heap:
38; CHECK:       movi v0.2d, #0000000000000000
39; CHECK-NEXT:  stp q0, q0, [x0]
40; CHECK-NEXT:  ret
41  call void @llvm.memset.p0i8.i64(i8* align 8 %c, i8 0, i64 32, i1 false)
42  ret void
43}
44
45define void @bzero_64_heap(i8* nocapture %c) {
46; CHECK-LABEL: bzero_64_heap:
47; CHECK:       movi v0.2d, #0000000000000000
48; CHECK-NEXT:  stp q0, q0, [x0, #32]
49; CHECK-NEXT:  stp q0, q0, [x0]
50; CHECK-NEXT:  ret
51  call void @llvm.memset.p0i8.i64(i8* align 8 %c, i8 0, i64 64, i1 false)
52  ret void
53}
54
55define void @bzero_4_stack() {
56; CHECK-LABEL: bzero_4_stack:
57; CHECK:       str wzr, [sp, #12]
58; CHECK-NEXT:  bl something
59  %buf = alloca [4 x i8], align 1
60  %cast = bitcast [4 x i8]* %buf to i8*
61  call void @llvm.memset.p0i8.i32(i8* %cast, i8 0, i32 4, i1 false)
62  call void @something(i8* %cast)
63  ret void
64}
65
66define void @bzero_8_stack() {
67; CHECK-LABEL: bzero_8_stack:
68; CHECK:       str xzr, [sp, #8]
69; CHECK-NEXT:  bl something
70  %buf = alloca [8 x i8], align 1
71  %cast = bitcast [8 x i8]* %buf to i8*
72  call void @llvm.memset.p0i8.i32(i8* %cast, i8 0, i32 8, i1 false)
73  call void @something(i8* %cast)
74  ret void
75}
76
77define void @bzero_12_stack() {
78; CHECK-LABEL: bzero_12_stack:
79; CHECK:       str wzr, [sp, #8]
80; CHECK-NEXT:  str xzr, [sp]
81; CHECK-NEXT:  bl something
82  %buf = alloca [12 x i8], align 1
83  %cast = bitcast [12 x i8]* %buf to i8*
84  call void @llvm.memset.p0i8.i32(i8* %cast, i8 0, i32 12, i1 false)
85  call void @something(i8* %cast)
86  ret void
87}
88
89define void @bzero_16_stack() {
90; CHECK-LABEL: bzero_16_stack:
91; CHECK:       stp xzr, x30, [sp, #8]
92; CHECK:       mov x0, sp
93; CHECK:       str xzr, [sp]
94; CHECK-NEXT:  bl something
95  %buf = alloca [16 x i8], align 1
96  %cast = bitcast [16 x i8]* %buf to i8*
97  call void @llvm.memset.p0i8.i32(i8* %cast, i8 0, i32 16, i1 false)
98  call void @something(i8* %cast)
99  ret void
100}
101
102define void @bzero_20_stack() {
103; CHECK-LABEL: bzero_20_stack:
104; CHECK:       stp xzr, xzr, [sp, #8]
105; CHECK-NEXT:  str wzr, [sp, #24]
106; CHECK-NEXT:  bl something
107  %buf = alloca [20 x i8], align 1
108  %cast = bitcast [20 x i8]* %buf to i8*
109  call void @llvm.memset.p0i8.i32(i8* %cast, i8 0, i32 20, i1 false)
110  call void @something(i8* %cast)
111  ret void
112}
113
114define void @bzero_26_stack() {
115; CHECK-LABEL: bzero_26_stack:
116; CHECK:       stp xzr, xzr, [sp]
117; CHECK-NEXT:  strh wzr, [sp, #24]
118; CHECK-NEXT:  str xzr, [sp, #16]
119; CHECK-NEXT:  bl something
120  %buf = alloca [26 x i8], align 1
121  %cast = bitcast [26 x i8]* %buf to i8*
122  call void @llvm.memset.p0i8.i32(i8* %cast, i8 0, i32 26, i1 false)
123  call void @something(i8* %cast)
124  ret void
125}
126
127define void @bzero_32_stack() {
128; CHECK-LABEL: bzero_32_stack:
129; CHECK:       movi v0.2d, #0000000000000000
130; CHECK-NEXT:  mov x0, sp
131; CHECK-NEXT:  stp q0, q0, [sp]
132; CHECK-NEXT:  bl something
133  %buf = alloca [32 x i8], align 1
134  %cast = bitcast [32 x i8]* %buf to i8*
135  call void @llvm.memset.p0i8.i32(i8* %cast, i8 0, i32 32, i1 false)
136  call void @something(i8* %cast)
137  ret void
138}
139
140define void @bzero_40_stack() {
141; CHECK-LABEL: bzero_40_stack:
142; CHECK:       movi v0.2d, #0000000000000000
143; CHECK-NEXT:  mov x0, sp
144; CHECK-NEXT:  str xzr, [sp, #32]
145; CHECK-NEXT:  stp q0, q0, [sp]
146; CHECK-NEXT: bl something
147  %buf = alloca [40 x i8], align 1
148  %cast = bitcast [40 x i8]* %buf to i8*
149  call void @llvm.memset.p0i8.i32(i8* %cast, i8 0, i32 40, i1 false)
150  call void @something(i8* %cast)
151  ret void
152}
153
154define void @bzero_64_stack() {
155; CHECK-LABEL: bzero_64_stack:
156; CHECK:       movi v0.2d, #0000000000000000
157; CHECK-NEXT:  mov x0, sp
158; CHECK-NEXT:  stp q0, q0, [sp, #32]
159; CHECK-NEXT:  stp q0, q0, [sp]
160; CHECK-NEXT:  bl something
161  %buf = alloca [64 x i8], align 1
162  %cast = bitcast [64 x i8]* %buf to i8*
163  call void @llvm.memset.p0i8.i32(i8* %cast, i8 0, i32 64, i1 false)
164  call void @something(i8* %cast)
165  ret void
166}
167
168define void @bzero_72_stack() {
169; CHECK-LABEL: bzero_72_stack:
170; CHECK:       movi v0.2d, #0000000000000000
171; CHECK-NEXT:  mov x0, sp
172; CHECK-NEXT:  str xzr, [sp, #64]
173; CHECK-NEXT:  stp q0, q0, [sp, #32]
174; CHECK-NEXT:  stp q0, q0, [sp]
175; CHECK-NEXT:  bl something
176  %buf = alloca [72 x i8], align 1
177  %cast = bitcast [72 x i8]* %buf to i8*
178  call void @llvm.memset.p0i8.i32(i8* %cast, i8 0, i32 72, i1 false)
179  call void @something(i8* %cast)
180  ret void
181}
182
183define void @bzero_128_stack() {
184; CHECK-LABEL: bzero_128_stack:
185; CHECK:       movi v0.2d, #0000000000000000
186; CHECK-NEXT:  mov x0, sp
187; CHECK-NEXT:  stp q0, q0, [sp, #96]
188; CHECK-NEXT:  stp q0, q0, [sp, #64]
189; CHECK-NEXT:  stp q0, q0, [sp, #32]
190; CHECK-NEXT:  stp q0, q0, [sp]
191; CHECK-NEXT:  bl something
192  %buf = alloca [128 x i8], align 1
193  %cast = bitcast [128 x i8]* %buf to i8*
194  call void @llvm.memset.p0i8.i32(i8* %cast, i8 0, i32 128, i1 false)
195  call void @something(i8* %cast)
196  ret void
197}
198
199define void @bzero_256_stack() {
200; CHECK-LABEL: bzero_256_stack:
201; CHECK:       movi v0.2d, #0000000000000000
202; CHECK-NEXT:  mov x0, sp
203; CHECK-NEXT:  stp q0, q0, [sp, #224]
204; CHECK-NEXT:  stp q0, q0, [sp, #192]
205; CHECK-NEXT:  stp q0, q0, [sp, #160]
206; CHECK-NEXT:  stp q0, q0, [sp, #128]
207; CHECK-NEXT:  stp q0, q0, [sp, #96]
208; CHECK-NEXT:  stp q0, q0, [sp, #64]
209; CHECK-NEXT:  stp q0, q0, [sp, #32]
210; CHECK-NEXT:  stp q0, q0, [sp]
211; CHECK-NEXT:  bl something
212  %buf = alloca [256 x i8], align 1
213  %cast = bitcast [256 x i8]* %buf to i8*
214  call void @llvm.memset.p0i8.i32(i8* %cast, i8 0, i32 256, i1 false)
215  call void @something(i8* %cast)
216  ret void
217}
218
219define void @memset_4_stack() {
220; CHECK-LABEL: memset_4_stack:
221; CHECK:       mov w8, #-1431655766
222; CHECK-NEXT:  add x0, sp, #12
223; CHECK-NEXT:  str w8, [sp, #12]
224; CHECK-NEXT:  bl something
225  %buf = alloca [4 x i8], align 1
226  %cast = bitcast [4 x i8]* %buf to i8*
227  call void @llvm.memset.p0i8.i32(i8* %cast, i8 -86, i32 4, i1 false)
228  call void @something(i8* %cast)
229  ret void
230}
231
232define void @memset_8_stack() {
233; CHECK-LABEL: memset_8_stack:
234; CHECK:       mov x8, #-6148914691236517206
235; CHECK-NEXT:  add x0, sp, #8
236; CHECK-NEXT:  str x8, [sp, #8]
237; CHECK-NEXT:  bl something
238  %buf = alloca [8 x i8], align 1
239  %cast = bitcast [8 x i8]* %buf to i8*
240  call void @llvm.memset.p0i8.i32(i8* %cast, i8 -86, i32 8, i1 false)
241  call void @something(i8* %cast)
242  ret void
243}
244
245define void @memset_12_stack() {
246; CHECK-LABEL: memset_12_stack:
247; CHECK:       mov x8, #-6148914691236517206
248; CHECK-NEXT:  mov x0, sp
249; CHECK-NEXT:  str x8, [sp]
250; CHECK-NEXT:  str w8, [sp, #8]
251; CHECK-NEXT:  bl something
252  %buf = alloca [12 x i8], align 1
253  %cast = bitcast [12 x i8]* %buf to i8*
254  call void @llvm.memset.p0i8.i32(i8* %cast, i8 -86, i32 12, i1 false)
255  call void @something(i8* %cast)
256  ret void
257}
258
259define void @memset_16_stack() {
260; CHECK-LABEL: memset_16_stack:
261; CHECK:       mov x8, #-6148914691236517206
262; CHECK-NEXT:  mov x0, sp
263; CHECK-NEXT:  stp x8, x30, [sp, #8]
264; CHECK-NEXT:  str x8, [sp]
265; CHECK-NEXT:  bl something
266  %buf = alloca [16 x i8], align 1
267  %cast = bitcast [16 x i8]* %buf to i8*
268  call void @llvm.memset.p0i8.i32(i8* %cast, i8 -86, i32 16, i1 false)
269  call void @something(i8* %cast)
270  ret void
271}
272
273define void @memset_20_stack() {
274; CHECK-LABEL: memset_20_stack:
275; CHECK:       mov x8, #-6148914691236517206
276; CHECK-NEXT:  add x0, sp, #8
277; CHECK-NEXT:  stp x8, x8, [sp, #8]
278; CHECK-NEXT:  str w8, [sp, #24]
279; CHECK-NEXT:  bl something
280  %buf = alloca [20 x i8], align 1
281  %cast = bitcast [20 x i8]* %buf to i8*
282  call void @llvm.memset.p0i8.i32(i8* %cast, i8 -86, i32 20, i1 false)
283  call void @something(i8* %cast)
284  ret void
285}
286
287define void @memset_26_stack() {
288; CHECK-LABEL: memset_26_stack:
289; CHECK:       mov x8, #-6148914691236517206
290; CHECK-NEXT:  mov x0, sp
291; CHECK-NEXT:  stp x8, x8, [sp, #8]
292; CHECK-NEXT:  str x8, [sp]
293; CHECK-NEXT:  strh w8, [sp, #24]
294; CHECK-NEXT:  bl something
295  %buf = alloca [26 x i8], align 1
296  %cast = bitcast [26 x i8]* %buf to i8*
297  call void @llvm.memset.p0i8.i32(i8* %cast, i8 -86, i32 26, i1 false)
298  call void @something(i8* %cast)
299  ret void
300}
301
302define void @memset_32_stack() {
303; CHECK-LABEL: memset_32_stack:
304; CHECK:       movi v0.16b, #170
305; CHECK-NEXT:  mov x0, sp
306; CHECK-NEXT:  stp q0, q0, [sp]
307; CHECK-NEXT:  bl something
308  %buf = alloca [32 x i8], align 1
309  %cast = bitcast [32 x i8]* %buf to i8*
310  call void @llvm.memset.p0i8.i32(i8* %cast, i8 -86, i32 32, i1 false)
311  call void @something(i8* %cast)
312  ret void
313}
314
315define void @memset_40_stack() {
316; CHECK-LABEL: memset_40_stack:
317; CHECK:       mov x8, #-6148914691236517206
318; CHECK-NEXT:  movi v0.16b, #170
319; CHECK-NEXT:  mov x0, sp
320; CHECK-NEXT:  str x8, [sp, #32]
321; CHECK-NEXT:  stp q0, q0, [sp]
322; CHECK-NEXT: bl something
323  %buf = alloca [40 x i8], align 1
324  %cast = bitcast [40 x i8]* %buf to i8*
325  call void @llvm.memset.p0i8.i32(i8* %cast, i8 -86, i32 40, i1 false)
326  call void @something(i8* %cast)
327  ret void
328}
329
330define void @memset_64_stack() {
331; CHECK-LABEL: memset_64_stack:
332; CHECK:       movi v0.16b, #170
333; CHECK-NEXT:  mov x0, sp
334; CHECK-NEXT:  stp q0, q0, [sp, #32]
335; CHECK-NEXT:  stp q0, q0, [sp]
336; CHECK-NEXT:  bl something
337  %buf = alloca [64 x i8], align 1
338  %cast = bitcast [64 x i8]* %buf to i8*
339  call void @llvm.memset.p0i8.i32(i8* %cast, i8 -86, i32 64, i1 false)
340  call void @something(i8* %cast)
341  ret void
342}
343
344define void @memset_72_stack() {
345; CHECK-LABEL: memset_72_stack:
346; CHECK:       mov x8, #-6148914691236517206
347; CHECK-NEXT:  movi v0.16b, #170
348; CHECK-NEXT:  mov x0, sp
349; CHECK-NEXT:  str x8, [sp, #64]
350; CHECK-NEXT:  stp q0, q0, [sp, #32]
351; CHECK-NEXT:  stp q0, q0, [sp]
352; CHECK-NEXT:  bl something
353  %buf = alloca [72 x i8], align 1
354  %cast = bitcast [72 x i8]* %buf to i8*
355  call void @llvm.memset.p0i8.i32(i8* %cast, i8 -86, i32 72, i1 false)
356  call void @something(i8* %cast)
357  ret void
358}
359
360define void @memset_128_stack() {
361; CHECK-LABEL: memset_128_stack:
362; CHECK:       movi v0.16b, #170
363; CHECK-NEXT:  mov x0, sp
364; CHECK-NEXT:  stp q0, q0, [sp, #96]
365; CHECK-NEXT:  stp q0, q0, [sp, #64]
366; CHECK-NEXT:  stp q0, q0, [sp, #32]
367; CHECK-NEXT:  stp q0, q0, [sp]
368; CHECK-NEXT:  bl something
369  %buf = alloca [128 x i8], align 1
370  %cast = bitcast [128 x i8]* %buf to i8*
371  call void @llvm.memset.p0i8.i32(i8* %cast, i8 -86, i32 128, i1 false)
372  call void @something(i8* %cast)
373  ret void
374}
375
376define void @memset_256_stack() {
377; CHECK-LABEL: memset_256_stack:
378; CHECK:       movi	v0.16b, #170
379; CHECK-NEXT:  mov	x0, sp
380; CHECK-NEXT:  stp	q0, q0, [sp, #224]
381; CHECK-NEXT:  stp	q0, q0, [sp, #192]
382; CHECK-NEXT:  stp	q0, q0, [sp, #160]
383; CHECK-NEXT:  stp	q0, q0, [sp, #128]
384; CHECK-NEXT:  stp	q0, q0, [sp, #96]
385; CHECK-NEXT:  stp	q0, q0, [sp, #64]
386; CHECK-NEXT:  stp	q0, q0, [sp, #32]
387; CHECK-NEXT:  stp	q0, q0, [sp]
388; CHECK-NEXT:  bl something
389  %buf = alloca [256 x i8], align 1
390  %cast = bitcast [256 x i8]* %buf to i8*
391  call void @llvm.memset.p0i8.i32(i8* %cast, i8 -86, i32 256, i1 false)
392  call void @something(i8* %cast)
393  ret void
394}
395
396declare void @something(i8*)
397declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i1) nounwind
398declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
399