• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu | FileCheck --check-prefix=CHECK %s
2; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu -mattr=-fp-armv8 | FileCheck --check-prefix=CHECK-NOFP %s
3
4%myStruct = type { i64 , i8, i32 }
5
6@var8 = global i8 0
7@var32 = global i32 0
8@var64 = global i64 0
9@var128 = global i128 0
10@varfloat = global float 0.0
11@vardouble = global double 0.0
12@varstruct = global %myStruct zeroinitializer
13
14define void @take_i8s(i8 %val1, i8 %val2) {
15; CHECK-LABEL: take_i8s:
16    store i8 %val2, i8* @var8
17    ; Not using w1 may be technically allowed, but it would indicate a
18    ; problem in itself.
19;  CHECK: strb w1, [{{x[0-9]+}}, {{#?}}:lo12:var8]
20    ret void
21}
22
23define void @add_floats(float %val1, float %val2) {
24; CHECK-LABEL: add_floats:
25    %newval = fadd float %val1, %val2
26; CHECK: fadd [[ADDRES:s[0-9]+]], s0, s1
27; CHECK-NOFP-NOT: fadd
28    store float %newval, float* @varfloat
29; CHECK: str [[ADDRES]], [{{x[0-9]+}}, {{#?}}:lo12:varfloat]
30    ret void
31}
32
33; byval pointers should be allocated to the stack and copied as if
34; with memcpy.
35define void @take_struct(%myStruct* byval %structval) {
36; CHECK-LABEL: take_struct:
37    %addr0 = getelementptr %myStruct* %structval, i64 0, i32 2
38    %addr1 = getelementptr %myStruct* %structval, i64 0, i32 0
39
40    %val0 = load volatile i32* %addr0
41    ; Some weird move means x0 is used for one access
42; CHECK: ldr [[REG32:w[0-9]+]], [{{x[0-9]+|sp}}, #12]
43    store volatile i32 %val0, i32* @var32
44; CHECK: str [[REG32]], [{{x[0-9]+}}, {{#?}}:lo12:var32]
45
46    %val1 = load volatile i64* %addr1
47; CHECK: ldr [[REG64:x[0-9]+]], [{{x[0-9]+|sp}}]
48    store volatile i64 %val1, i64* @var64
49; CHECK: str [[REG64]], [{{x[0-9]+}}, {{#?}}:lo12:var64]
50
51    ret void
52}
53
54; %structval should be at sp + 16
55define void @check_byval_align(i32* byval %ignore, %myStruct* byval align 16 %structval) {
56; CHECK-LABEL: check_byval_align:
57
58    %addr0 = getelementptr %myStruct* %structval, i64 0, i32 2
59    %addr1 = getelementptr %myStruct* %structval, i64 0, i32 0
60
61    %val0 = load volatile i32* %addr0
62    ; Some weird move means x0 is used for one access
63; CHECK: ldr [[REG32:w[0-9]+]], [sp, #28]
64    store i32 %val0, i32* @var32
65; CHECK: str [[REG32]], [{{x[0-9]+}}, {{#?}}:lo12:var32]
66
67    %val1 = load volatile i64* %addr1
68; CHECK: ldr [[REG64:x[0-9]+]], [sp, #16]
69    store i64 %val1, i64* @var64
70; CHECK: str [[REG64]], [{{x[0-9]+}}, {{#?}}:lo12:var64]
71
72    ret void
73}
74
75define i32 @return_int() {
76; CHECK-LABEL: return_int:
77    %val = load i32* @var32
78    ret i32 %val
79; CHECK: ldr w0, [{{x[0-9]+}}, {{#?}}:lo12:var32]
80    ; Make sure epilogue follows
81; CHECK-NEXT: ret
82}
83
84define double @return_double() {
85; CHECK-LABEL: return_double:
86    ret double 3.14
87; CHECK: ldr d0, [{{x[0-9]+}}, {{#?}}:lo12:.LCPI
88; CHECK-NOFP-NOT: ldr d0,
89}
90
91; This is the kind of IR clang will produce for returning a struct
92; small enough to go into registers. Not all that pretty, but it
93; works.
94define [2 x i64] @return_struct() {
95; CHECK-LABEL: return_struct:
96    %addr = bitcast %myStruct* @varstruct to [2 x i64]*
97    %val = load [2 x i64]* %addr
98    ret [2 x i64] %val
99; CHECK-DAG: ldr x0, [{{x[0-9]+}}, {{#?}}:lo12:varstruct]
100    ; Odd register regex below disallows x0 which we want to be live now.
101; CHECK-DAG: add {{x[1-9][0-9]*}}, {{x[1-9][0-9]*}}, {{#?}}:lo12:varstruct
102; CHECK: ldr x1, [{{x[1-9][0-9]*}}, #8]
103    ; Make sure epilogue immediately follows
104; CHECK-NEXT: ret
105}
106
107; Large structs are passed by reference (storage allocated by caller
108; to preserve value semantics) in x8. Strictly this only applies to
109; structs larger than 16 bytes, but C semantics can still be provided
110; if LLVM does it to %myStruct too. So this is the simplest check
111define void @return_large_struct(%myStruct* sret %retval) {
112; CHECK-LABEL: return_large_struct:
113    %addr0 = getelementptr %myStruct* %retval, i64 0, i32 0
114    %addr1 = getelementptr %myStruct* %retval, i64 0, i32 1
115    %addr2 = getelementptr %myStruct* %retval, i64 0, i32 2
116
117    store i64 42, i64* %addr0
118    store i8 2, i8* %addr1
119    store i32 9, i32* %addr2
120; CHECK: str {{x[0-9]+}}, [x8]
121; CHECK: strb {{w[0-9]+}}, [x8, #8]
122; CHECK: str {{w[0-9]+}}, [x8, #12]
123
124    ret void
125}
126
127; This struct is just too far along to go into registers: (only x7 is
128; available, but it needs two). Also make sure that %stacked doesn't
129; sneak into x7 behind.
130define i32 @struct_on_stack(i8 %var0, i16 %var1, i32 %var2, i64 %var3, i128 %var45,
131                          i32* %var6, %myStruct* byval %struct, i32* byval %stacked,
132                          double %notstacked) {
133; CHECK-LABEL: struct_on_stack:
134    %addr = getelementptr %myStruct* %struct, i64 0, i32 0
135    %val64 = load volatile i64* %addr
136    store volatile i64 %val64, i64* @var64
137    ; Currently nothing on local stack, so struct should be at sp
138; CHECK: ldr [[VAL64:x[0-9]+]], [sp]
139; CHECK: str [[VAL64]], [{{x[0-9]+}}, {{#?}}:lo12:var64]
140
141    store volatile double %notstacked, double* @vardouble
142; CHECK-NOT: ldr d0
143; CHECK: str d0, [{{x[0-9]+}}, {{#?}}:lo12:vardouble
144; CHECK-NOFP-NOT: str d0,
145
146    %retval = load volatile i32* %stacked
147    ret i32 %retval
148; CHECK-LE: ldr w0, [sp, #16]
149}
150
151define void @stacked_fpu(float %var0, double %var1, float %var2, float %var3,
152                         float %var4, float %var5, float %var6, float %var7,
153                         float %var8) {
154; CHECK-LABEL: stacked_fpu:
155    store float %var8, float* @varfloat
156    ; Beware as above: the offset would be different on big-endian
157    ; machines if the first ldr were changed to use s-registers.
158; CHECK: ldr {{[ds]}}[[VALFLOAT:[0-9]+]], [sp]
159; CHECK: str s[[VALFLOAT]], [{{x[0-9]+}}, {{#?}}:lo12:varfloat]
160
161    ret void
162}
163
164; 128-bit integer types should be passed in xEVEN, xODD rather than
165; the reverse. In this case x2 and x3. Nothing should use x1.
166define i64 @check_i128_regalign(i32 %val0, i128 %val1, i64 %val2) {
167; CHECK-LABEL: check_i128_regalign
168    store i128 %val1, i128* @var128
169; CHECK-DAG: str x2, [{{x[0-9]+}}, {{#?}}:lo12:var128]
170; CHECK-DAG: str x3, [{{x[0-9]+}}, #8]
171
172    ret i64 %val2
173; CHECK: mov x0, x4
174}
175
176define void @check_i128_stackalign(i32 %val0, i32 %val1, i32 %val2, i32 %val3,
177                                   i32 %val4, i32 %val5, i32 %val6, i32 %val7,
178                                   i32 %stack1, i128 %stack2) {
179; CHECK-LABEL: check_i128_stackalign
180    store i128 %stack2, i128* @var128
181    ; Nothing local on stack in current codegen, so first stack is 16 away
182; CHECK-LE: add     x[[REG:[0-9]+]], sp, #16
183; CHECK-LE: ldr {{x[0-9]+}}, [x[[REG]], #8]
184
185    ; Important point is that we address sp+24 for second dword
186
187; CHECK: ldp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #16]
188    ret void
189}
190
191declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
192
193define i32 @test_extern() {
194; CHECK-LABEL: test_extern:
195  call void @llvm.memcpy.p0i8.p0i8.i32(i8* undef, i8* undef, i32 undef, i32 4, i1 0)
196; CHECK: bl memcpy
197  ret i32 0
198}
199
200
201; A sub-i32 stack argument must be loaded on big endian with ldr{h,b}, not just
202; implicitly extended to a 32-bit load.
203define i16 @stacked_i16(i32 %val0, i32 %val1, i32 %val2, i32 %val3,
204                        i32 %val4, i32 %val5, i32 %val6, i32 %val7,
205                        i16 %stack1) {
206; CHECK-LABEL: stacked_i16
207  ret i16 %stack1
208}
209