1 ; RUN: llc -mtriple=i386-apple-darwin %s -o %t
2 ; RUN: FileCheck %s < %t
3 ; RUN: FileCheck %s -check-prefix=GOT-EQUIV < %t
5 ; GOT equivalent globals references can be replaced by the GOT entry of the
6 ; final symbol instead.
8 %struct.data = type { i32, %struct.anon }
9 %struct.anon = type { i32, i32 }
11 ; Check that these got equivalent symbols are never emitted or used
12 ; GOT-EQUIV-NOT: _localgotequiv
13 ; GOT-EQUIV-NOT: _extgotequiv
14 @localfoo = global i32 42
15 @localgotequiv = private unnamed_addr constant ptr @localfoo
17 @extfoo = external global i32
18 @extgotequiv = private unnamed_addr constant ptr @extfoo
20 ; Don't replace GOT equivalent usage within instructions and emit the GOT
21 ; equivalent since it can't be replaced by the GOT entry. @bargotequiv is
22 ; used by an instruction inside @t0.
24 ; CHECK: l_bargotequiv:
25 ; CHECK-NEXT: .long _extbar
26 @extbar = external global i32
27 @bargotequiv = private unnamed_addr constant ptr @extbar
29 @table = global [4 x %struct.data] [
31 %struct.data { i32 1, %struct.anon { i32 2, i32 3 } },
32 ; Test GOT equivalent usage inside nested constant arrays.
34 ; CHECK-NOT: l_localgotequiv-(_table+20)
35 ; CHECK-NEXT: L_localfoo$non_lazy_ptr-(_table+20)
36 %struct.data { i32 4, %struct.anon { i32 5,
37 i32 sub (i32 ptrtoint (ptr @localgotequiv to i32),
38 i32 ptrtoint (ptr getelementptr inbounds ([4 x %struct.data], ptr @table, i32 0, i32 1, i32 1, i32 1) to i32))}
41 ; CHECK-NOT: l_extgotequiv-(_table+32)
42 ; CHECK-NEXT: L_extfoo$non_lazy_ptr-(_table+32)
43 %struct.data { i32 4, %struct.anon { i32 5,
44 i32 sub (i32 ptrtoint (ptr @extgotequiv to i32),
45 i32 ptrtoint (ptr getelementptr inbounds ([4 x %struct.data], ptr @table, i32 0, i32 2, i32 1, i32 1) to i32))}
47 ; Test support for arbitrary constants into the GOTPCREL offset
49 ; CHECK-NOT: (l_extgotequiv-(_table+44))+24
50 ; CHECK-NEXT: L_extfoo$non_lazy_ptr-(_table+20)
51 %struct.data { i32 4, %struct.anon { i32 5,
52 i32 add (i32 sub (i32 ptrtoint (ptr @extgotequiv to i32),
53 i32 ptrtoint (ptr getelementptr inbounds ([4 x %struct.data], ptr @table, i32 0, i32 3, i32 1, i32 1) to i32)),
58 ; Test multiple uses of GOT equivalents.
60 ; CHECK: .long L_extfoo$non_lazy_ptr-_delta
61 @delta = global i32 sub (i32 ptrtoint (ptr @extgotequiv to i32),
62 i32 ptrtoint (ptr @delta to i32))
64 ; CHECK-LABEL: _deltaplus:
65 ; CHECK: .long L_localfoo$non_lazy_ptr-(_deltaplus-55)
66 @deltaplus = global i32 add (i32 sub (i32 ptrtoint (ptr @localgotequiv to i32),
67 i32 ptrtoint (ptr @deltaplus to i32)),
70 define i32 @t0(i32 %a) {
71 %x = add i32 sub (i32 ptrtoint (ptr @bargotequiv to i32),
72 i32 ptrtoint (ptr @t0 to i32)), %a
76 ; Test indirect local symbols.
77 ; CHECK-LABEL: _localindirect
79 @localindirect = internal constant i32 65603
80 @got.localindirect = private unnamed_addr constant ptr @localindirect
82 ; CHECK-LABEL: _localindirectuser:
83 ; CHECK: .long L_localindirect$non_lazy_ptr-_localindirectuser
84 @localindirectuser = internal constant
85 i32 sub (i32 ptrtoint (ptr @got.localindirect to i32),
86 i32 ptrtoint (ptr @localindirectuser to i32))
88 ; Test internal indirect local symbols where the user doesn't see the
89 ; definition of the other symbols yet.
91 ; We used to check if the symbol is defined and not external to guess if it has
92 ; local linkage, but that doesn't work if the symbol is defined after. The code
93 ; should check if the GlobalValue itself has local linkage.
95 ; CHECK-LABEL: _undeflocalindirectuser:
96 ; CHECK: .long L_undeflocalindirect$non_lazy_ptr-_undeflocalindirectuser
97 @undeflocalindirectuser = internal constant
98 i32 sub (i32 ptrtoint (ptr @got.undeflocalindirect to i32),
99 i32 ptrtoint (ptr @undeflocalindirectuser to i32)),
100 section "__TEXT,__const"
102 ; CHECK-LABEL: _undeflocalindirect:
104 @undeflocalindirect = internal constant i32 65603
105 @got.undeflocalindirect = private unnamed_addr constant ptr @undeflocalindirect
107 ; CHECK-LABEL: .section __IMPORT,__pointers
109 ; CHECK-LABEL: L_localfoo$non_lazy_ptr:
110 ; CHECK: .indirect_symbol _localfoo
111 ; CHECK-NOT: .long _localfoo
112 ; CHECK-NEXT: .long 0
114 ; CHECK-LABEL: L_localindirect$non_lazy_ptr:
115 ; CHECK: .indirect_symbol _localindirect
117 ; CHECK-NEXT: .long _localindirect
119 ; CHECK-LABEL: L_undeflocalindirect$non_lazy_ptr:
120 ; CHECK: .indirect_symbol _undeflocalindirect
122 ; CHECK-NEXT: .long _undeflocalindirect