1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -verify-machineinstrs -o - -mtriple=aarch64-none-linux-gnu -code-model=tiny < %s | FileCheck %s
3; RUN: llc -verify-machineinstrs -o - -mtriple=aarch64-none-linux-gnu -code-model=tiny -fast-isel < %s | FileCheck %s
4; RUN: llc -verify-machineinstrs -o - -mtriple=aarch64-none-linux-gnu -code-model=tiny -global-isel < %s | FileCheck %s --check-prefix=CHECK-GLOBISEL
5; RUN: llc -verify-machineinstrs -o - -mtriple=aarch64-none-linux-gnu -code-model=tiny -relocation-model=pic < %s | FileCheck %s --check-prefix=CHECK-PIC
6; RUN: llc -verify-machineinstrs -o - -mtriple=aarch64-none-linux-gnu -code-model=tiny -relocation-model=pic -fast-isel < %s | FileCheck %s --check-prefix=CHECK-PIC
7; RUN: llc -verify-machineinstrs -o - -mtriple=aarch64-none-linux-gnu -code-model=tiny -relocation-model=pic -global-isel < %s | FileCheck %s --check-prefix=CHECK-PIC-GLOBISEL
8
9; Note fast-isel tests here will fall back to isel
10
11@src = external local_unnamed_addr global [65536 x i8], align 1
12@dst = external global [65536 x i8], align 1
13@ptr = external local_unnamed_addr global i8*, align 8
14
15define void @foo1() {
16; CHECK-LABEL: foo1:
17; CHECK:       // %bb.0: // %entry
18; CHECK-NEXT:    adr x8, src
19; CHECK-NEXT:    ldrb w8, [x8]
20; CHECK-NEXT:    adr x9, dst
21; CHECK-NEXT:    strb w8, [x9]
22; CHECK-NEXT:    ret
23;
24; CHECK-GLOBISEL-LABEL: foo1:
25; CHECK-GLOBISEL:       // %bb.0: // %entry
26; CHECK-GLOBISEL-NEXT:    adr x8, src
27; CHECK-GLOBISEL-NEXT:    ldrb w8, [x8]
28; CHECK-GLOBISEL-NEXT:    adr x9, dst
29; CHECK-GLOBISEL-NEXT:    strb w8, [x9]
30; CHECK-GLOBISEL-NEXT:    ret
31;
32; CHECK-PIC-LABEL: foo1:
33; CHECK-PIC:       // %bb.0: // %entry
34; CHECK-PIC-NEXT:    ldr x8, :got:src
35; CHECK-PIC-NEXT:    ldrb w8, [x8]
36; CHECK-PIC-NEXT:    ldr x9, :got:dst
37; CHECK-PIC-NEXT:    strb w8, [x9]
38; CHECK-PIC-NEXT:    ret
39;
40; CHECK-PIC-GLOBISEL-LABEL: foo1:
41; CHECK-PIC-GLOBISEL:       // %bb.0: // %entry
42; CHECK-PIC-GLOBISEL-NEXT:    ldr x8, :got:src
43; CHECK-PIC-GLOBISEL-NEXT:    ldrb w8, [x8]
44; CHECK-PIC-GLOBISEL-NEXT:    ldr x9, :got:dst
45; CHECK-PIC-GLOBISEL-NEXT:    strb w8, [x9]
46; CHECK-PIC-GLOBISEL-NEXT:    ret
47entry:
48  %0 = load i8, i8* getelementptr inbounds ([65536 x i8], [65536 x i8]* @src, i64 0, i64 0), align 1
49  store i8 %0, i8* getelementptr inbounds ([65536 x i8], [65536 x i8]* @dst, i64 0, i64 0), align 1
50  ret void
51}
52
53define void @foo2() {
54; CHECK-LABEL: foo2:
55; CHECK:       // %bb.0: // %entry
56; CHECK-NEXT:    adr x8, ptr
57; CHECK-NEXT:    adr x9, dst
58; CHECK-NEXT:    str x9, [x8]
59; CHECK-NEXT:    ret
60;
61; CHECK-GLOBISEL-LABEL: foo2:
62; CHECK-GLOBISEL:       // %bb.0: // %entry
63; CHECK-GLOBISEL-NEXT:    adr x8, dst
64; CHECK-GLOBISEL-NEXT:    adr x9, ptr
65; CHECK-GLOBISEL-NEXT:    str x8, [x9]
66; CHECK-GLOBISEL-NEXT:    ret
67;
68; CHECK-PIC-LABEL: foo2:
69; CHECK-PIC:       // %bb.0: // %entry
70; CHECK-PIC-NEXT:    ldr x8, :got:ptr
71; CHECK-PIC-NEXT:    ldr x9, :got:dst
72; CHECK-PIC-NEXT:    str x9, [x8]
73; CHECK-PIC-NEXT:    ret
74;
75; CHECK-PIC-GLOBISEL-LABEL: foo2:
76; CHECK-PIC-GLOBISEL:       // %bb.0: // %entry
77; CHECK-PIC-GLOBISEL-NEXT:    ldr x8, :got:dst
78; CHECK-PIC-GLOBISEL-NEXT:    ldr x9, :got:ptr
79; CHECK-PIC-GLOBISEL-NEXT:    str x8, [x9]
80; CHECK-PIC-GLOBISEL-NEXT:    ret
81entry:
82  store i8* getelementptr inbounds ([65536 x i8], [65536 x i8]* @dst, i64 0, i64 0), i8** @ptr, align 8
83  ret void
84}
85
86define void @foo3() {
87; FIXME: Needn't adr ptr
88;
89; CHECK-LABEL: foo3:
90; CHECK:       // %bb.0: // %entry
91; CHECK-NEXT:    adr x8, src
92; CHECK-NEXT:    ldrb w8, [x8]
93; CHECK-NEXT:    ldr x9, ptr
94; CHECK-NEXT:    strb w8, [x9]
95; CHECK-NEXT:    ret
96;
97; CHECK-GLOBISEL-LABEL: foo3:
98; CHECK-GLOBISEL:       // %bb.0: // %entry
99; CHECK-GLOBISEL-NEXT:    adr x8, src
100; CHECK-GLOBISEL-NEXT:    adr x9, ptr
101; CHECK-GLOBISEL-NEXT:    ldrb w8, [x8]
102; CHECK-GLOBISEL-NEXT:    ldr x9, [x9]
103; CHECK-GLOBISEL-NEXT:    strb w8, [x9]
104; CHECK-GLOBISEL-NEXT:    ret
105;
106; CHECK-PIC-LABEL: foo3:
107; CHECK-PIC:       // %bb.0: // %entry
108; CHECK-PIC-NEXT:    ldr x8, :got:src
109; CHECK-PIC-NEXT:    ldr x9, :got:ptr
110; CHECK-PIC-NEXT:    ldrb w8, [x8]
111; CHECK-PIC-NEXT:    ldr x9, [x9]
112; CHECK-PIC-NEXT:    strb w8, [x9]
113; CHECK-PIC-NEXT:    ret
114;
115; CHECK-PIC-GLOBISEL-LABEL: foo3:
116; CHECK-PIC-GLOBISEL:       // %bb.0: // %entry
117; CHECK-PIC-GLOBISEL-NEXT:    ldr x8, :got:src
118; CHECK-PIC-GLOBISEL-NEXT:    ldr x9, :got:ptr
119; CHECK-PIC-GLOBISEL-NEXT:    ldrb w8, [x8]
120; CHECK-PIC-GLOBISEL-NEXT:    ldr x9, [x9]
121; CHECK-PIC-GLOBISEL-NEXT:    strb w8, [x9]
122; CHECK-PIC-GLOBISEL-NEXT:    ret
123entry:
124  %0 = load i8, i8* getelementptr inbounds ([65536 x i8], [65536 x i8]* @src, i64 0, i64 0), align 1
125  %1 = load i8*, i8** @ptr, align 8
126  store i8 %0, i8* %1, align 1
127  ret void
128}
129
130@lsrc = internal global i8 0, align 4
131@ldst = internal global i8 0, align 4
132@lptr = internal global i8* null, align 8
133
134define void @bar1() {
135; CHECK-LABEL: bar1:
136; CHECK:       // %bb.0: // %entry
137; CHECK-NEXT:    adr x8, lsrc
138; CHECK-NEXT:    ldrb w8, [x8]
139; CHECK-NEXT:    adr x9, ldst
140; CHECK-NEXT:    strb w8, [x9]
141; CHECK-NEXT:    ret
142;
143; CHECK-GLOBISEL-LABEL: bar1:
144; CHECK-GLOBISEL:       // %bb.0: // %entry
145; CHECK-GLOBISEL-NEXT:    adr x8, lsrc
146; CHECK-GLOBISEL-NEXT:    ldrb w8, [x8]
147; CHECK-GLOBISEL-NEXT:    adr x9, ldst
148; CHECK-GLOBISEL-NEXT:    strb w8, [x9]
149; CHECK-GLOBISEL-NEXT:    ret
150;
151; CHECK-PIC-LABEL: bar1:
152; CHECK-PIC:       // %bb.0: // %entry
153; CHECK-PIC-NEXT:    adr x8, lsrc
154; CHECK-PIC-NEXT:    ldrb w8, [x8]
155; CHECK-PIC-NEXT:    adr x9, ldst
156; CHECK-PIC-NEXT:    strb w8, [x9]
157; CHECK-PIC-NEXT:    ret
158;
159; CHECK-PIC-GLOBISEL-LABEL: bar1:
160; CHECK-PIC-GLOBISEL:       // %bb.0: // %entry
161; CHECK-PIC-GLOBISEL-NEXT:    adr x8, lsrc
162; CHECK-PIC-GLOBISEL-NEXT:    ldrb w8, [x8]
163; CHECK-PIC-GLOBISEL-NEXT:    adr x9, ldst
164; CHECK-PIC-GLOBISEL-NEXT:    strb w8, [x9]
165; CHECK-PIC-GLOBISEL-NEXT:    ret
166entry:
167  %0 = load i8, i8* @lsrc, align 4
168  store i8 %0, i8* @ldst, align 4
169  ret void
170}
171
172define void @bar2() {
173; CHECK-LABEL: bar2:
174; CHECK:       // %bb.0: // %entry
175; CHECK-NEXT:    adr x8, lptr
176; CHECK-NEXT:    adr x9, ldst
177; CHECK-NEXT:    str x9, [x8]
178; CHECK-NEXT:    ret
179;
180; CHECK-GLOBISEL-LABEL: bar2:
181; CHECK-GLOBISEL:       // %bb.0: // %entry
182; CHECK-GLOBISEL-NEXT:    adr x8, ldst
183; CHECK-GLOBISEL-NEXT:    adr x9, lptr
184; CHECK-GLOBISEL-NEXT:    str x8, [x9]
185; CHECK-GLOBISEL-NEXT:    ret
186;
187; CHECK-PIC-LABEL: bar2:
188; CHECK-PIC:       // %bb.0: // %entry
189; CHECK-PIC-NEXT:    adr x8, lptr
190; CHECK-PIC-NEXT:    adr x9, ldst
191; CHECK-PIC-NEXT:    str x9, [x8]
192; CHECK-PIC-NEXT:    ret
193;
194; CHECK-PIC-GLOBISEL-LABEL: bar2:
195; CHECK-PIC-GLOBISEL:       // %bb.0: // %entry
196; CHECK-PIC-GLOBISEL-NEXT:    adr x8, ldst
197; CHECK-PIC-GLOBISEL-NEXT:    adr x9, lptr
198; CHECK-PIC-GLOBISEL-NEXT:    str x8, [x9]
199; CHECK-PIC-GLOBISEL-NEXT:    ret
200entry:
201  store i8* @ldst, i8** @lptr, align 8
202  ret void
203}
204
205define void @bar3() {
206; FIXME: Needn't adr lptr
207;
208; CHECK-LABEL: bar3:
209; CHECK:       // %bb.0: // %entry
210; CHECK-NEXT:    adr x8, lsrc
211; CHECK-NEXT:    ldrb w8, [x8]
212; CHECK-NEXT:    ldr x9, lptr
213; CHECK-NEXT:    strb w8, [x9]
214; CHECK-NEXT:    ret
215;
216; CHECK-GLOBISEL-LABEL: bar3:
217; CHECK-GLOBISEL:       // %bb.0: // %entry
218; CHECK-GLOBISEL-NEXT:    adr x8, lsrc
219; CHECK-GLOBISEL-NEXT:    adr x9, lptr
220; CHECK-GLOBISEL-NEXT:    ldrb w8, [x8]
221; CHECK-GLOBISEL-NEXT:    ldr x9, [x9]
222; CHECK-GLOBISEL-NEXT:    strb w8, [x9]
223; CHECK-GLOBISEL-NEXT:    ret
224;
225; CHECK-PIC-LABEL: bar3:
226; CHECK-PIC:       // %bb.0: // %entry
227; CHECK-PIC-NEXT:    adr x8, lsrc
228; CHECK-PIC-NEXT:    ldrb w8, [x8]
229; CHECK-PIC-NEXT:    ldr x9, lptr
230; CHECK-PIC-NEXT:    strb w8, [x9]
231; CHECK-PIC-NEXT:    ret
232;
233; CHECK-PIC-GLOBISEL-LABEL: bar3:
234; CHECK-PIC-GLOBISEL:       // %bb.0: // %entry
235; CHECK-PIC-GLOBISEL-NEXT:    adr x8, lsrc
236; CHECK-PIC-GLOBISEL-NEXT:    adr x9, lptr
237; CHECK-PIC-GLOBISEL-NEXT:    ldrb w8, [x8]
238; CHECK-PIC-GLOBISEL-NEXT:    ldr x9, [x9]
239; CHECK-PIC-GLOBISEL-NEXT:    strb w8, [x9]
240; CHECK-PIC-GLOBISEL-NEXT:    ret
241entry:
242  %0 = load i8, i8* @lsrc, align 4
243  %1 = load i8*, i8** @lptr, align 8
244  store i8 %0, i8* %1, align 1
245  ret void
246}
247
248
249@lbsrc = internal global [65536 x i8] zeroinitializer, align 4
250@lbdst = internal global [65536 x i8] zeroinitializer, align 4
251
252define void @baz1() {
253; CHECK-LABEL: baz1:
254; CHECK:       // %bb.0: // %entry
255; CHECK-NEXT:    adr x8, lbsrc
256; CHECK-NEXT:    ldrb w8, [x8]
257; CHECK-NEXT:    adr x9, lbdst
258; CHECK-NEXT:    strb w8, [x9]
259; CHECK-NEXT:    ret
260;
261; CHECK-GLOBISEL-LABEL: baz1:
262; CHECK-GLOBISEL:       // %bb.0: // %entry
263; CHECK-GLOBISEL-NEXT:    adr x8, lbsrc
264; CHECK-GLOBISEL-NEXT:    ldrb w8, [x8]
265; CHECK-GLOBISEL-NEXT:    adr x9, lbdst
266; CHECK-GLOBISEL-NEXT:    strb w8, [x9]
267; CHECK-GLOBISEL-NEXT:    ret
268;
269; CHECK-PIC-LABEL: baz1:
270; CHECK-PIC:       // %bb.0: // %entry
271; CHECK-PIC-NEXT:    adr x8, lbsrc
272; CHECK-PIC-NEXT:    ldrb w8, [x8]
273; CHECK-PIC-NEXT:    adr x9, lbdst
274; CHECK-PIC-NEXT:    strb w8, [x9]
275; CHECK-PIC-NEXT:    ret
276;
277; CHECK-PIC-GLOBISEL-LABEL: baz1:
278; CHECK-PIC-GLOBISEL:       // %bb.0: // %entry
279; CHECK-PIC-GLOBISEL-NEXT:    adr x8, lbsrc
280; CHECK-PIC-GLOBISEL-NEXT:    ldrb w8, [x8]
281; CHECK-PIC-GLOBISEL-NEXT:    adr x9, lbdst
282; CHECK-PIC-GLOBISEL-NEXT:    strb w8, [x9]
283; CHECK-PIC-GLOBISEL-NEXT:    ret
284entry:
285  %0 = load i8, i8* getelementptr inbounds ([65536 x i8], [65536 x i8]* @lbsrc, i64 0, i64 0), align 4
286  store i8 %0, i8* getelementptr inbounds ([65536 x i8], [65536 x i8]* @lbdst, i64 0, i64 0), align 4
287  ret void
288}
289
290define void @baz2() {
291; CHECK-LABEL: baz2:
292; CHECK:       // %bb.0: // %entry
293; CHECK-NEXT:    adr x8, lptr
294; CHECK-NEXT:    adr x9, lbdst
295; CHECK-NEXT:    str x9, [x8]
296; CHECK-NEXT:    ret
297;
298; CHECK-GLOBISEL-LABEL: baz2:
299; CHECK-GLOBISEL:       // %bb.0: // %entry
300; CHECK-GLOBISEL-NEXT:    adr x8, lbdst
301; CHECK-GLOBISEL-NEXT:    adr x9, lptr
302; CHECK-GLOBISEL-NEXT:    str x8, [x9]
303; CHECK-GLOBISEL-NEXT:    ret
304;
305; CHECK-PIC-LABEL: baz2:
306; CHECK-PIC:       // %bb.0: // %entry
307; CHECK-PIC-NEXT:    adr x8, lptr
308; CHECK-PIC-NEXT:    adr x9, lbdst
309; CHECK-PIC-NEXT:    str x9, [x8]
310; CHECK-PIC-NEXT:    ret
311;
312; CHECK-PIC-GLOBISEL-LABEL: baz2:
313; CHECK-PIC-GLOBISEL:       // %bb.0: // %entry
314; CHECK-PIC-GLOBISEL-NEXT:    adr x8, lbdst
315; CHECK-PIC-GLOBISEL-NEXT:    adr x9, lptr
316; CHECK-PIC-GLOBISEL-NEXT:    str x8, [x9]
317; CHECK-PIC-GLOBISEL-NEXT:    ret
318entry:
319  store i8* getelementptr inbounds ([65536 x i8], [65536 x i8]* @lbdst, i64 0, i64 0), i8** @lptr, align 8
320  ret void
321}
322
323define void @baz3() {
324; FIXME: Needn't adr lptr
325;
326; CHECK-LABEL: baz3:
327; CHECK:       // %bb.0: // %entry
328; CHECK-NEXT:    adr x8, lbsrc
329; CHECK-NEXT:    ldrb w8, [x8]
330; CHECK-NEXT:    ldr x9, lptr
331; CHECK-NEXT:    strb w8, [x9]
332; CHECK-NEXT:    ret
333;
334; CHECK-GLOBISEL-LABEL: baz3:
335; CHECK-GLOBISEL:       // %bb.0: // %entry
336; CHECK-GLOBISEL-NEXT:    adr x8, lbsrc
337; CHECK-GLOBISEL-NEXT:    adr x9, lptr
338; CHECK-GLOBISEL-NEXT:    ldrb w8, [x8]
339; CHECK-GLOBISEL-NEXT:    ldr x9, [x9]
340; CHECK-GLOBISEL-NEXT:    strb w8, [x9]
341; CHECK-GLOBISEL-NEXT:    ret
342;
343; CHECK-PIC-LABEL: baz3:
344; CHECK-PIC:       // %bb.0: // %entry
345; CHECK-PIC-NEXT:    adr x8, lbsrc
346; CHECK-PIC-NEXT:    ldrb w8, [x8]
347; CHECK-PIC-NEXT:    ldr x9, lptr
348; CHECK-PIC-NEXT:    strb w8, [x9]
349; CHECK-PIC-NEXT:    ret
350;
351; CHECK-PIC-GLOBISEL-LABEL: baz3:
352; CHECK-PIC-GLOBISEL:       // %bb.0: // %entry
353; CHECK-PIC-GLOBISEL-NEXT:    adr x8, lbsrc
354; CHECK-PIC-GLOBISEL-NEXT:    adr x9, lptr
355; CHECK-PIC-GLOBISEL-NEXT:    ldrb w8, [x8]
356; CHECK-PIC-GLOBISEL-NEXT:    ldr x9, [x9]
357; CHECK-PIC-GLOBISEL-NEXT:    strb w8, [x9]
358; CHECK-PIC-GLOBISEL-NEXT:    ret
359entry:
360  %0 = load i8, i8* getelementptr inbounds ([65536 x i8], [65536 x i8]* @lbsrc, i64 0, i64 0), align 4
361  %1 = load i8*, i8** @lptr, align 8
362  store i8 %0, i8* %1, align 1
363  ret void
364}
365
366
367declare void @func(...)
368
369define i8* @externfuncaddr() {
370; CHECK-LABEL: externfuncaddr:
371; CHECK:       // %bb.0: // %entry
372; CHECK-NEXT:    adr x0, func
373; CHECK-NEXT:    ret
374;
375; CHECK-GLOBISEL-LABEL: externfuncaddr:
376; CHECK-GLOBISEL:       // %bb.0: // %entry
377; CHECK-GLOBISEL-NEXT:    adr x0, func
378; CHECK-GLOBISEL-NEXT:    ret
379;
380; CHECK-PIC-LABEL: externfuncaddr:
381; CHECK-PIC:       // %bb.0: // %entry
382; CHECK-PIC-NEXT:    ldr x0, :got:func
383; CHECK-PIC-NEXT:    ret
384;
385; CHECK-PIC-GLOBISEL-LABEL: externfuncaddr:
386; CHECK-PIC-GLOBISEL:       // %bb.0: // %entry
387; CHECK-PIC-GLOBISEL-NEXT:    ldr x0, :got:func
388; CHECK-PIC-GLOBISEL-NEXT:    ret
389entry:
390      ret i8* bitcast (void (...)* @func to i8*)
391}
392
393define i8* @localfuncaddr() {
394; CHECK-LABEL: localfuncaddr:
395; CHECK:       // %bb.0: // %entry
396; CHECK-NEXT:    adr x0, externfuncaddr
397; CHECK-NEXT:    ret
398;
399; CHECK-GLOBISEL-LABEL: localfuncaddr:
400; CHECK-GLOBISEL:       // %bb.0: // %entry
401; CHECK-GLOBISEL-NEXT:    adr x0, externfuncaddr
402; CHECK-GLOBISEL-NEXT:    ret
403;
404; CHECK-PIC-LABEL: localfuncaddr:
405; CHECK-PIC:       // %bb.0: // %entry
406; CHECK-PIC-NEXT:    ldr x0, :got:externfuncaddr
407; CHECK-PIC-NEXT:    ret
408;
409; CHECK-PIC-GLOBISEL-LABEL: localfuncaddr:
410; CHECK-PIC-GLOBISEL:       // %bb.0: // %entry
411; CHECK-PIC-GLOBISEL-NEXT:    ldr x0, :got:externfuncaddr
412; CHECK-PIC-GLOBISEL-NEXT:    ret
413entry:
414      ret i8* bitcast (i8* ()* @externfuncaddr to i8*)
415}
416
417