1 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic \
2 ; RUN: | FileCheck -check-prefix=X64 %s
3 ; RUN: llc < %s -emulated-tls -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic \
4 ; RUN: | FileCheck -check-prefix=X32 %s
7 @a = global i32 0, align 4
9 define i32 @my_access_global_a() #0 {
10 ; X32-LABEL: my_access_global_a:
11 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
12 ; X32-NEXT: movl a@GOTOFF(%eax), %eax
13 ; X64-LABEL: my_access_global_a:
14 ; X64: movl a(%rip), %eax
17 %0 = load i32, i32* @a, align 4
22 @b = weak global i32 0, align 4
24 define i32 @my_access_global_b() #0 {
25 ; X32-LABEL: my_access_global_b:
26 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
27 ; X32-NEXT: movl b@GOTOFF(%eax), %eax
28 ; X64-LABEL: my_access_global_b:
29 ; X64: movl b(%rip), %eax
32 %0 = load i32, i32* @b, align 4
37 @c = internal global i32 0, align 4
39 define i32 @my_access_global_c() #0 {
40 ; X32-LABEL: my_access_global_c:
41 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
42 ; X32-NEXT: movl c@GOTOFF(%eax), %eax
43 ; X64-LABEL: my_access_global_c:
44 ; X64: movl c(%rip), %eax
47 %0 = load i32, i32* @c, align 4
51 ; External Linkage, only declaration.
52 @d = external global i32, align 4
54 define i32 @my_access_global_load_d() #0 {
55 ; X32-LABEL: my_access_global_load_d:
56 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
57 ; X32-NEXT: movl d@GOT(%eax), %eax
58 ; X32-NEXT: movl (%eax), %eax
59 ; X64-LABEL: my_access_global_load_d:
60 ; X64: movq d@GOTPCREL(%rip), %rax
61 ; X64-NEXT: movl (%rax), %eax
64 %0 = load i32, i32* @d, align 4
68 ; External Linkage, only declaration, store a value.
70 define i32 @my_access_global_store_d() #0 {
71 ; X32-LABEL: my_access_global_store_d:
72 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
73 ; X32-NEXT: movl d@GOT(%eax), %eax
74 ; X32-NEXT: movl $2, (%eax)
75 ; X64-LABEL: my_access_global_store_d:
76 ; X64: movq d@GOTPCREL(%rip), %rax
77 ; X64-NEXT: movl $2, (%rax)
80 store i32 2, i32* @d, align 4
84 ; External Linkage, function pointer access.
85 declare i32 @access_fp(i32 ()*)
88 define i32 @my_access_fp_foo() #0 {
89 ; X32-LABEL: my_access_fp_foo:
90 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %ebx
91 ; X32-NEXT: movl foo@GOT(%ebx), %eax
92 ; X64-LABEL: my_access_fp_foo:
93 ; X64: movq foo@GOTPCREL(%rip), %rdi
96 %call = call i32 @access_fp(i32 ()* @foo)
100 ; LinkOnceODR Linkage, function pointer access.
104 define linkonce_odr i32 @bar() comdat {
109 define i32 @my_access_fp_bar() #0 {
110 ; X32-LABEL: my_access_fp_bar:
111 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %ebx
112 ; X32-NEXT: leal bar@GOTOFF(%ebx), %eax
113 ; X64-LABEL: my_access_fp_bar:
114 ; X64: leaq bar(%rip), %rdi
117 %call = call i32 @access_fp(i32 ()* @bar)
121 !llvm.module.flags = !{!0, !1}
122 !0 = !{i32 1, !"PIC Level", i32 1}
123 !1 = !{i32 1, !"PIE Level", i32 1}