1 ; RUN: llc < %s -emulated-tls -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
6 ; RUN: llc < %s -mcpu=generic -mtriple=x86_64-linux-gnu -relocation-model=pic \
7 ; RUN: | FileCheck -check-prefix=X64 %s
8 ; RUN: llc < %s -mcpu=generic -mtriple=i386-linux-gnu -relocation-model=pic \
9 ; RUN: | FileCheck -check-prefix=X32 %s
12 @a = global i32 0, align 4
14 define i32 @my_access_global_a() #0 {
15 ; X32-LABEL: my_access_global_a:
16 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
17 ; X32-NEXT: movl a@GOTOFF(%eax), %eax
18 ; X64-LABEL: my_access_global_a:
19 ; X64: movl a(%rip), %eax
22 %0 = load i32, i32* @a, align 4
27 @b = weak global i32 0, align 4
29 define i32 @my_access_global_b() #0 {
30 ; X32-LABEL: my_access_global_b:
31 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
32 ; X32-NEXT: movl b@GOTOFF(%eax), %eax
33 ; X64-LABEL: my_access_global_b:
34 ; X64: movl b(%rip), %eax
37 %0 = load i32, i32* @b, align 4
42 @c = internal global i32 0, align 4
44 define i32 @my_access_global_c() #0 {
45 ; X32-LABEL: my_access_global_c:
46 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
47 ; X32-NEXT: movl c@GOTOFF(%eax), %eax
48 ; X64-LABEL: my_access_global_c:
49 ; X64: movl c(%rip), %eax
52 %0 = load i32, i32* @c, align 4
56 ; External Linkage, only declaration.
57 @d = external global i32, align 4
59 define i32 @my_access_global_load_d() #0 {
60 ; X32-LABEL: my_access_global_load_d:
61 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
62 ; X32-NEXT: movl d@GOT(%eax), %eax
63 ; X32-NEXT: movl (%eax), %eax
64 ; X64-LABEL: my_access_global_load_d:
65 ; X64: movq d@GOTPCREL(%rip), %rax
66 ; X64-NEXT: movl (%rax), %eax
69 %0 = load i32, i32* @d, align 4
73 ; External Linkage, only declaration, store a value.
75 define i32 @my_access_global_store_d() #0 {
76 ; X32-LABEL: my_access_global_store_d:
77 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax
78 ; X32-NEXT: movl d@GOT(%eax), %eax
79 ; X32-NEXT: movl $2, (%eax)
80 ; X64-LABEL: my_access_global_store_d:
81 ; X64: movq d@GOTPCREL(%rip), %rax
82 ; X64-NEXT: movl $2, (%rax)
85 store i32 2, i32* @d, align 4
89 ; External Linkage, function pointer access.
90 declare i32 @access_fp(i32 ()*)
93 define i32 @my_access_fp_foo() #0 {
94 ; X32-LABEL: my_access_fp_foo:
95 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %ebx
96 ; X32-NEXT: movl foo@GOT(%ebx), %eax
97 ; X64-LABEL: my_access_fp_foo:
98 ; X64: movq foo@GOTPCREL(%rip), %rdi
101 %call = call i32 @access_fp(i32 ()* @foo)
105 ; LinkOnceODR Linkage, function pointer access.
109 define linkonce_odr i32 @bar() comdat {
114 define i32 @my_access_fp_bar() #0 {
115 ; X32-LABEL: my_access_fp_bar:
116 ; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %ebx
117 ; X32-NEXT: leal bar@GOTOFF(%ebx), %eax
118 ; X64-LABEL: my_access_fp_bar:
119 ; X64: leaq bar(%rip), %rdi
122 %call = call i32 @access_fp(i32 ()* @bar)
126 !llvm.module.flags = !{!0, !1}
127 !0 = !{i32 1, !"PIC Level", i32 1}
128 !1 = !{i32 1, !"PIE Level", i32 1}