• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc -mtriple=i386-apple-darwin %s -o %t
2; RUN:  FileCheck %s < %t
3; RUN:  FileCheck %s -check-prefix=GOT-EQUIV < %t
4
5; GOT equivalent globals references can be replaced by the GOT entry of the
6; final symbol instead.
7
8%struct.data = type { i32, %struct.anon }
9%struct.anon = type { i32, i32 }
10
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 i32* @localfoo
16
17@extfoo = external global i32
18@extgotequiv = private unnamed_addr constant i32* @extfoo
19
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.
23;
24; CHECK: l_bargotequiv:
25; CHECK-NEXT:  .long   _extbar
26@extbar = external global i32
27@bargotequiv = private unnamed_addr constant i32* @extbar
28
29@table = global [4 x %struct.data] [
30; CHECK-LABEL: _table
31  %struct.data { i32 1, %struct.anon { i32 2, i32 3 } },
32; Test GOT equivalent usage inside nested constant arrays.
33; CHECK: .long   5
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 (i32** @localgotequiv to i32),
38             i32 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i32 1, i32 1, i32 1) to i32))}
39  },
40; CHECK: .long   5
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 (i32** @extgotequiv to i32),
45             i32 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i32 2, i32 1, i32 1) to i32))}
46  },
47; Test support for arbitrary constants into the GOTPCREL offset
48; CHECK: .long   5
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 (i32** @extgotequiv to i32),
53                      i32 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i32 3, i32 1, i32 1) to i32)),
54                      i32 24)}
55  }
56], align 16
57
58; Test multiple uses of GOT equivalents.
59; CHECK-LABEL: _delta
60; CHECK: .long   L_extfoo$non_lazy_ptr-_delta
61@delta = global i32 sub (i32 ptrtoint (i32** @extgotequiv to i32),
62                         i32 ptrtoint (i32* @delta to i32))
63
64; CHECK-LABEL: _deltaplus:
65; CHECK: .long   L_localfoo$non_lazy_ptr-(_deltaplus-55)
66@deltaplus = global i32 add (i32 sub (i32 ptrtoint (i32** @localgotequiv to i32),
67                             i32 ptrtoint (i32* @deltaplus to i32)),
68                             i32 55)
69
70define i32 @t0(i32 %a) {
71  %x = add i32 sub (i32 ptrtoint (i32** @bargotequiv to i32),
72                    i32 ptrtoint (i32 (i32)* @t0 to i32)), %a
73  ret i32 %x
74}
75
76; Test indirect local symbols.
77; CHECK-LABEL: _localindirect
78; CHECK: .long 65603
79@localindirect = internal constant i32  65603
80@got.localindirect = private unnamed_addr constant i32* @localindirect
81
82; CHECK-LABEL: _localindirectuser:
83; CHECK: .long   L_localindirect$non_lazy_ptr-_localindirectuser
84@localindirectuser = internal constant
85  i32 sub (i32 ptrtoint (i32** @got.localindirect to i32),
86           i32 ptrtoint (i32* @localindirectuser to i32))
87
88; Test internal indirect local symbols where the user doesn't see the
89; definition of the other symbols yet.
90
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.
94
95; CHECK-LABEL: _undeflocalindirectuser:
96; CHECK: .long L_undeflocalindirect$non_lazy_ptr-_undeflocalindirectuser
97@undeflocalindirectuser = internal constant
98  i32 sub (i32 ptrtoint (i32** @got.undeflocalindirect to i32),
99           i32 ptrtoint (i32* @undeflocalindirectuser to i32)),
100  section "__TEXT,__const"
101
102; CHECK-LABEL: _undeflocalindirect:
103; CHECK: .long 65603
104@undeflocalindirect = internal constant i32  65603
105@got.undeflocalindirect = private unnamed_addr constant i32* @undeflocalindirect
106
107; CHECK-LABEL: .section __IMPORT,__pointers
108
109; CHECK-LABEL: L_localfoo$non_lazy_ptr:
110; CHECK: .indirect_symbol _localfoo
111; CHECK-NOT: .long _localfoo
112; CHECK-NEXT: .long 0
113
114; CHECK-LABEL: L_localindirect$non_lazy_ptr:
115; CHECK: .indirect_symbol _localindirect
116; CHECK-NOT: .long 0
117; CHECK-NEXT: .long _localindirect
118
119; CHECK-LABEL: L_undeflocalindirect$non_lazy_ptr:
120; CHECK: .indirect_symbol _undeflocalindirect
121; CHECK-NOT: .long 0
122; CHECK-NEXT: .long _undeflocalindirect
123