1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; Run with --no_x86_scrub_rip because we care a lot about how globals are
3 ; accessed in the code model.
5 ; RUN: llc -verify-machineinstrs < %s -relocation-model=static -code-model=small | FileCheck %s --check-prefix=CHECK --check-prefix=SMALL-STATIC
6 ; RUN: llc -verify-machineinstrs < %s -relocation-model=static -code-model=medium | FileCheck %s --check-prefix=CHECK --check-prefix=MEDIUM-STATIC
7 ; RUN: llc -verify-machineinstrs < %s -relocation-model=static -code-model=large | FileCheck %s --check-prefix=CHECK --check-prefix=LARGE-STATIC
8 ; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=small | FileCheck %s --check-prefix=CHECK --check-prefix=SMALL-PIC
9 ; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=medium | FileCheck %s --check-prefix=CHECK --check-prefix=MEDIUM-PIC
10 ; RUN: llc -verify-machineinstrs < %s -relocation-model=pic -code-model=large | FileCheck %s --check-prefix=CHECK --check-prefix=LARGE-PIC
12 ; Generated from this C source:
14 ; static int static_data[10];
15 ; int global_data[10] = {1, 2};
16 ; extern int extern_data[10];
18 ; int *lea_static_data() { return &static_data[0]; }
19 ; int *lea_global_data() { return &global_data[0]; }
20 ; int *lea_extern_data() { return &extern_data[0]; }
22 ; static void static_fn(void) {}
23 ; void global_fn(void) {}
24 ; void extern_fn(void);
26 ; typedef void (*void_fn)(void);
27 ; void_fn lea_static_fn() { return &static_fn; }
28 ; void_fn lea_global_fn() { return &global_fn; }
29 ; void_fn lea_extern_fn() { return &extern_fn; }
32 ; ModuleID = 'model.c'
33 source_filename = "model.c"
34 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
35 target triple = "x86_64--linux"
37 @global_data = dso_local global [10 x i32] [i32 1, i32 2, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0], align 16
38 @static_data = internal global [10 x i32] zeroinitializer, align 16
39 @extern_data = external global [10 x i32], align 16
41 define dso_local i32* @lea_static_data() #0 {
42 ; SMALL-STATIC-LABEL: lea_static_data:
43 ; SMALL-STATIC: # %bb.0:
44 ; SMALL-STATIC-NEXT: movl $static_data, %eax
45 ; SMALL-STATIC-NEXT: retq
47 ; MEDIUM-STATIC-LABEL: lea_static_data:
48 ; MEDIUM-STATIC: # %bb.0:
49 ; MEDIUM-STATIC-NEXT: movabsq $static_data, %rax
50 ; MEDIUM-STATIC-NEXT: retq
52 ; LARGE-STATIC-LABEL: lea_static_data:
53 ; LARGE-STATIC: # %bb.0:
54 ; LARGE-STATIC-NEXT: movabsq $static_data, %rax
55 ; LARGE-STATIC-NEXT: retq
57 ; SMALL-PIC-LABEL: lea_static_data:
59 ; SMALL-PIC-NEXT: leaq static_data(%rip), %rax
60 ; SMALL-PIC-NEXT: retq
62 ; MEDIUM-PIC-LABEL: lea_static_data:
63 ; MEDIUM-PIC: # %bb.0:
64 ; MEDIUM-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx
65 ; MEDIUM-PIC-NEXT: movabsq $static_data@GOTOFF, %rax
66 ; MEDIUM-PIC-NEXT: addq %rcx, %rax
67 ; MEDIUM-PIC-NEXT: retq
69 ; LARGE-PIC-LABEL: lea_static_data:
71 ; LARGE-PIC-NEXT: .L0$pb:
72 ; LARGE-PIC-NEXT: leaq .L0$pb(%rip), %rax
73 ; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L0$pb, %rcx
74 ; LARGE-PIC-NEXT: addq %rax, %rcx
75 ; LARGE-PIC-NEXT: movabsq $static_data@GOTOFF, %rax
76 ; LARGE-PIC-NEXT: addq %rcx, %rax
77 ; LARGE-PIC-NEXT: retq
78 ret i32* getelementptr inbounds ([10 x i32], [10 x i32]* @static_data, i64 0, i64 0)
81 define dso_local i32* @lea_global_data() #0 {
82 ; SMALL-STATIC-LABEL: lea_global_data:
83 ; SMALL-STATIC: # %bb.0:
84 ; SMALL-STATIC-NEXT: movl $global_data, %eax
85 ; SMALL-STATIC-NEXT: retq
87 ; MEDIUM-STATIC-LABEL: lea_global_data:
88 ; MEDIUM-STATIC: # %bb.0:
89 ; MEDIUM-STATIC-NEXT: movabsq $global_data, %rax
90 ; MEDIUM-STATIC-NEXT: retq
92 ; LARGE-STATIC-LABEL: lea_global_data:
93 ; LARGE-STATIC: # %bb.0:
94 ; LARGE-STATIC-NEXT: movabsq $global_data, %rax
95 ; LARGE-STATIC-NEXT: retq
97 ; SMALL-PIC-LABEL: lea_global_data:
99 ; SMALL-PIC-NEXT: leaq global_data(%rip), %rax
100 ; SMALL-PIC-NEXT: retq
102 ; MEDIUM-PIC-LABEL: lea_global_data:
103 ; MEDIUM-PIC: # %bb.0:
104 ; MEDIUM-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rcx
105 ; MEDIUM-PIC-NEXT: movabsq $global_data@GOTOFF, %rax
106 ; MEDIUM-PIC-NEXT: addq %rcx, %rax
107 ; MEDIUM-PIC-NEXT: retq
109 ; LARGE-PIC-LABEL: lea_global_data:
110 ; LARGE-PIC: # %bb.0:
111 ; LARGE-PIC-NEXT: .L1$pb:
112 ; LARGE-PIC-NEXT: leaq .L1$pb(%rip), %rax
113 ; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L1$pb, %rcx
114 ; LARGE-PIC-NEXT: addq %rax, %rcx
115 ; LARGE-PIC-NEXT: movabsq $global_data@GOTOFF, %rax
116 ; LARGE-PIC-NEXT: addq %rcx, %rax
117 ; LARGE-PIC-NEXT: retq
118 ret i32* getelementptr inbounds ([10 x i32], [10 x i32]* @global_data, i64 0, i64 0)
121 define dso_local i32* @lea_extern_data() #0 {
122 ; SMALL-STATIC-LABEL: lea_extern_data:
123 ; SMALL-STATIC: # %bb.0:
124 ; SMALL-STATIC-NEXT: movl $extern_data, %eax
125 ; SMALL-STATIC-NEXT: retq
127 ; MEDIUM-STATIC-LABEL: lea_extern_data:
128 ; MEDIUM-STATIC: # %bb.0:
129 ; MEDIUM-STATIC-NEXT: movabsq $extern_data, %rax
130 ; MEDIUM-STATIC-NEXT: retq
132 ; LARGE-STATIC-LABEL: lea_extern_data:
133 ; LARGE-STATIC: # %bb.0:
134 ; LARGE-STATIC-NEXT: movabsq $extern_data, %rax
135 ; LARGE-STATIC-NEXT: retq
137 ; SMALL-PIC-LABEL: lea_extern_data:
138 ; SMALL-PIC: # %bb.0:
139 ; SMALL-PIC-NEXT: movq extern_data@GOTPCREL(%rip), %rax
140 ; SMALL-PIC-NEXT: retq
142 ; MEDIUM-PIC-LABEL: lea_extern_data:
143 ; MEDIUM-PIC: # %bb.0:
144 ; MEDIUM-PIC-NEXT: movq extern_data@GOTPCREL(%rip), %rax
145 ; MEDIUM-PIC-NEXT: retq
147 ; LARGE-PIC-LABEL: lea_extern_data:
148 ; LARGE-PIC: # %bb.0:
149 ; LARGE-PIC-NEXT: .L2$pb:
150 ; LARGE-PIC-NEXT: leaq .L2$pb(%rip), %rax
151 ; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L2$pb, %rcx
152 ; LARGE-PIC-NEXT: addq %rax, %rcx
153 ; LARGE-PIC-NEXT: movabsq $extern_data@GOT, %rax
154 ; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
155 ; LARGE-PIC-NEXT: retq
156 ret i32* getelementptr inbounds ([10 x i32], [10 x i32]* @extern_data, i64 0, i64 0)
159 define dso_local i32 @load_global_data() #0 {
160 ; SMALL-STATIC-LABEL: load_global_data:
161 ; SMALL-STATIC: # %bb.0:
162 ; SMALL-STATIC-NEXT: movl global_data+8(%rip), %eax
163 ; SMALL-STATIC-NEXT: retq
165 ; MEDIUM-STATIC-LABEL: load_global_data:
166 ; MEDIUM-STATIC: # %bb.0:
167 ; MEDIUM-STATIC-NEXT: movabsq $global_data, %rax
168 ; MEDIUM-STATIC-NEXT: movl 8(%rax), %eax
169 ; MEDIUM-STATIC-NEXT: retq
171 ; LARGE-STATIC-LABEL: load_global_data:
172 ; LARGE-STATIC: # %bb.0:
173 ; LARGE-STATIC-NEXT: movabsq $global_data, %rax
174 ; LARGE-STATIC-NEXT: movl 8(%rax), %eax
175 ; LARGE-STATIC-NEXT: retq
177 ; SMALL-PIC-LABEL: load_global_data:
178 ; SMALL-PIC: # %bb.0:
179 ; SMALL-PIC-NEXT: movl global_data+8(%rip), %eax
180 ; SMALL-PIC-NEXT: retq
182 ; MEDIUM-PIC-LABEL: load_global_data:
183 ; MEDIUM-PIC: # %bb.0:
184 ; MEDIUM-PIC-NEXT: leaq _GLOBAL_OFFSET_TABLE_(%rip), %rax
185 ; MEDIUM-PIC-NEXT: movabsq $global_data@GOTOFF, %rcx
186 ; MEDIUM-PIC-NEXT: movl 8(%rax,%rcx), %eax
187 ; MEDIUM-PIC-NEXT: retq
189 ; LARGE-PIC-LABEL: load_global_data:
190 ; LARGE-PIC: # %bb.0:
191 ; LARGE-PIC-NEXT: .L3$pb:
192 ; LARGE-PIC-NEXT: leaq .L3$pb(%rip), %rax
193 ; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L3$pb, %rcx
194 ; LARGE-PIC-NEXT: addq %rax, %rcx
195 ; LARGE-PIC-NEXT: movabsq $global_data@GOTOFF, %rax
196 ; LARGE-PIC-NEXT: movl 8(%rcx,%rax), %eax
197 ; LARGE-PIC-NEXT: retq
198 %rv = load i32, i32* getelementptr inbounds ([10 x i32], [10 x i32]* @global_data, i64 0, i64 2)
202 define dso_local i32 @load_extern_data() #0 {
203 ; SMALL-STATIC-LABEL: load_extern_data:
204 ; SMALL-STATIC: # %bb.0:
205 ; SMALL-STATIC-NEXT: movl extern_data+8(%rip), %eax
206 ; SMALL-STATIC-NEXT: retq
208 ; MEDIUM-STATIC-LABEL: load_extern_data:
209 ; MEDIUM-STATIC: # %bb.0:
210 ; MEDIUM-STATIC-NEXT: movabsq $extern_data, %rax
211 ; MEDIUM-STATIC-NEXT: movl 8(%rax), %eax
212 ; MEDIUM-STATIC-NEXT: retq
214 ; LARGE-STATIC-LABEL: load_extern_data:
215 ; LARGE-STATIC: # %bb.0:
216 ; LARGE-STATIC-NEXT: movabsq $extern_data, %rax
217 ; LARGE-STATIC-NEXT: movl 8(%rax), %eax
218 ; LARGE-STATIC-NEXT: retq
220 ; SMALL-PIC-LABEL: load_extern_data:
221 ; SMALL-PIC: # %bb.0:
222 ; SMALL-PIC-NEXT: movq extern_data@GOTPCREL(%rip), %rax
223 ; SMALL-PIC-NEXT: movl 8(%rax), %eax
224 ; SMALL-PIC-NEXT: retq
226 ; MEDIUM-PIC-LABEL: load_extern_data:
227 ; MEDIUM-PIC: # %bb.0:
228 ; MEDIUM-PIC-NEXT: movq extern_data@GOTPCREL(%rip), %rax
229 ; MEDIUM-PIC-NEXT: movl 8(%rax), %eax
230 ; MEDIUM-PIC-NEXT: retq
232 ; LARGE-PIC-LABEL: load_extern_data:
233 ; LARGE-PIC: # %bb.0:
234 ; LARGE-PIC-NEXT: .L4$pb:
235 ; LARGE-PIC-NEXT: leaq .L4$pb(%rip), %rax
236 ; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L4$pb, %rcx
237 ; LARGE-PIC-NEXT: addq %rax, %rcx
238 ; LARGE-PIC-NEXT: movabsq $extern_data@GOT, %rax
239 ; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
240 ; LARGE-PIC-NEXT: movl 8(%rax), %eax
241 ; LARGE-PIC-NEXT: retq
242 %rv = load i32, i32* getelementptr inbounds ([10 x i32], [10 x i32]* @extern_data, i64 0, i64 2)
246 define dso_local void @global_fn() #0 {
247 ; CHECK-LABEL: global_fn:
253 define internal void @static_fn() #0 {
254 ; CHECK-LABEL: static_fn:
260 declare void @extern_fn()
262 define dso_local void ()* @lea_static_fn() #0 {
263 ; SMALL-STATIC-LABEL: lea_static_fn:
264 ; SMALL-STATIC: # %bb.0:
265 ; SMALL-STATIC-NEXT: movl $static_fn, %eax
266 ; SMALL-STATIC-NEXT: retq
268 ; MEDIUM-STATIC-LABEL: lea_static_fn:
269 ; MEDIUM-STATIC: # %bb.0:
270 ; MEDIUM-STATIC-NEXT: movabsq $static_fn, %rax
271 ; MEDIUM-STATIC-NEXT: retq
273 ; LARGE-STATIC-LABEL: lea_static_fn:
274 ; LARGE-STATIC: # %bb.0:
275 ; LARGE-STATIC-NEXT: movabsq $static_fn, %rax
276 ; LARGE-STATIC-NEXT: retq
278 ; SMALL-PIC-LABEL: lea_static_fn:
279 ; SMALL-PIC: # %bb.0:
280 ; SMALL-PIC-NEXT: leaq static_fn(%rip), %rax
281 ; SMALL-PIC-NEXT: retq
283 ; MEDIUM-PIC-LABEL: lea_static_fn:
284 ; MEDIUM-PIC: # %bb.0:
285 ; MEDIUM-PIC-NEXT: movabsq $static_fn, %rax
286 ; MEDIUM-PIC-NEXT: retq
288 ; LARGE-PIC-LABEL: lea_static_fn:
289 ; LARGE-PIC: # %bb.0:
290 ; LARGE-PIC-NEXT: .L7$pb:
291 ; LARGE-PIC-NEXT: leaq .L7$pb(%rip), %rax
292 ; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L7$pb, %rcx
293 ; LARGE-PIC-NEXT: addq %rax, %rcx
294 ; LARGE-PIC-NEXT: movabsq $static_fn@GOTOFF, %rax
295 ; LARGE-PIC-NEXT: addq %rcx, %rax
296 ; LARGE-PIC-NEXT: retq
297 ret void ()* @static_fn
300 define dso_local void ()* @lea_global_fn() #0 {
301 ; SMALL-STATIC-LABEL: lea_global_fn:
302 ; SMALL-STATIC: # %bb.0:
303 ; SMALL-STATIC-NEXT: movl $global_fn, %eax
304 ; SMALL-STATIC-NEXT: retq
306 ; MEDIUM-STATIC-LABEL: lea_global_fn:
307 ; MEDIUM-STATIC: # %bb.0:
308 ; MEDIUM-STATIC-NEXT: movabsq $global_fn, %rax
309 ; MEDIUM-STATIC-NEXT: retq
311 ; LARGE-STATIC-LABEL: lea_global_fn:
312 ; LARGE-STATIC: # %bb.0:
313 ; LARGE-STATIC-NEXT: movabsq $global_fn, %rax
314 ; LARGE-STATIC-NEXT: retq
316 ; SMALL-PIC-LABEL: lea_global_fn:
317 ; SMALL-PIC: # %bb.0:
318 ; SMALL-PIC-NEXT: leaq global_fn(%rip), %rax
319 ; SMALL-PIC-NEXT: retq
321 ; MEDIUM-PIC-LABEL: lea_global_fn:
322 ; MEDIUM-PIC: # %bb.0:
323 ; MEDIUM-PIC-NEXT: movabsq $global_fn, %rax
324 ; MEDIUM-PIC-NEXT: retq
326 ; LARGE-PIC-LABEL: lea_global_fn:
327 ; LARGE-PIC: # %bb.0:
328 ; LARGE-PIC-NEXT: .L8$pb:
329 ; LARGE-PIC-NEXT: leaq .L8$pb(%rip), %rax
330 ; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L8$pb, %rcx
331 ; LARGE-PIC-NEXT: addq %rax, %rcx
332 ; LARGE-PIC-NEXT: movabsq $global_fn@GOTOFF, %rax
333 ; LARGE-PIC-NEXT: addq %rcx, %rax
334 ; LARGE-PIC-NEXT: retq
335 ret void ()* @global_fn
338 define dso_local void ()* @lea_extern_fn() #0 {
339 ; SMALL-STATIC-LABEL: lea_extern_fn:
340 ; SMALL-STATIC: # %bb.0:
341 ; SMALL-STATIC-NEXT: movl $extern_fn, %eax
342 ; SMALL-STATIC-NEXT: retq
344 ; MEDIUM-STATIC-LABEL: lea_extern_fn:
345 ; MEDIUM-STATIC: # %bb.0:
346 ; MEDIUM-STATIC-NEXT: movabsq $extern_fn, %rax
347 ; MEDIUM-STATIC-NEXT: retq
349 ; LARGE-STATIC-LABEL: lea_extern_fn:
350 ; LARGE-STATIC: # %bb.0:
351 ; LARGE-STATIC-NEXT: movabsq $extern_fn, %rax
352 ; LARGE-STATIC-NEXT: retq
354 ; SMALL-PIC-LABEL: lea_extern_fn:
355 ; SMALL-PIC: # %bb.0:
356 ; SMALL-PIC-NEXT: movq extern_fn@GOTPCREL(%rip), %rax
357 ; SMALL-PIC-NEXT: retq
359 ; MEDIUM-PIC-LABEL: lea_extern_fn:
360 ; MEDIUM-PIC: # %bb.0:
361 ; MEDIUM-PIC-NEXT: movq extern_fn@GOTPCREL(%rip), %rax
362 ; MEDIUM-PIC-NEXT: retq
364 ; LARGE-PIC-LABEL: lea_extern_fn:
365 ; LARGE-PIC: # %bb.0:
366 ; LARGE-PIC-NEXT: .L9$pb:
367 ; LARGE-PIC-NEXT: leaq .L9$pb(%rip), %rax
368 ; LARGE-PIC-NEXT: movabsq $_GLOBAL_OFFSET_TABLE_-.L9$pb, %rcx
369 ; LARGE-PIC-NEXT: addq %rax, %rcx
370 ; LARGE-PIC-NEXT: movabsq $extern_fn@GOT, %rax
371 ; LARGE-PIC-NEXT: movq (%rcx,%rax), %rax
372 ; LARGE-PIC-NEXT: retq
373 ret void ()* @extern_fn
376 attributes #0 = { noinline nounwind uwtable }
378 !llvm.module.flags = !{!0, !1, !2}
381 !0 = !{i32 1, !"wchar_size", i32 4}
382 !1 = !{i32 7, !"PIC Level", i32 2}
383 !2 = !{i32 7, !"PIE Level", i32 2}
384 !3 = !{!"clang version 7.0.0 "}