1 ; RUN: llc -mtriple=arm64-apple-darwin %s -o - | FileCheck %s
3 ; GOT equivalent globals references can be replaced by the GOT entry of the
4 ; final symbol instead.
6 %struct.data = type { i32, %struct.anon }
7 %struct.anon = type { i32, i32 }
9 @localfoo = global i32 42
10 @localgotequiv = private unnamed_addr constant i32* @localfoo
12 @extfoo = external global i32
13 @extgotequiv = private unnamed_addr constant i32* @extfoo
15 ; Don't replace GOT equivalent usage within instructions and emit the GOT
16 ; equivalent since it can't be replaced by the GOT entry. @bargotequiv is
17 ; used by an instruction inside @t0.
19 ; CHECK: l_bargotequiv:
20 ; CHECK-NEXT: .quad _extbar
21 @extbar = external global i32
22 @bargotequiv = private unnamed_addr constant i32* @extbar
24 @table = global [4 x %struct.data] [
26 %struct.data { i32 1, %struct.anon { i32 2, i32 3 } },
27 ; Test GOT equivalent usage inside nested constant arrays.
30 ; CHECK-NOT: .long _localgotequiv-(_table+20)
32 ; CHECK-NEXT: .long _localfoo@GOT-Ltmp0
33 %struct.data { i32 4, %struct.anon { i32 5,
34 i32 trunc (i64 sub (i64 ptrtoint (i32** @localgotequiv to i64),
35 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i64 1, i32 1, i32 1) to i64))
40 ; CHECK-NOT: _extgotequiv-(_table+32)
42 ; CHECK-NEXT: _extfoo@GOT-Ltmp1
43 %struct.data { i32 4, %struct.anon { i32 5,
44 i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
45 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i64 2, i32 1, i32 1) to i64))
48 ; Test support for arbitrary constants into the GOTPCREL offset, which is
49 ; supported on x86-64 but not on ARM64
52 ; CHECK-NEXT: .long ((l_extgotequiv-_table)-44)+24
53 %struct.data { i32 4, %struct.anon { i32 5,
54 i32 add (i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
55 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i64 3, i32 1, i32 1) to i64))
60 ; Test multiple uses of GOT equivalents.
64 ; CHECK-NEXT: .long _extfoo@GOT-Ltmp2
65 @delta = global i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
66 i64 ptrtoint (i32* @delta to i64))
69 ; CHECK-LABEL: _deltaplus:
70 ; CHECK: .long (l_localgotequiv-_deltaplus)+55
71 @deltaplus = global i32 add (i32 trunc (i64 sub (i64 ptrtoint (i32** @localgotequiv to i64),
72 i64 ptrtoint (i32* @deltaplus to i64))
75 define i32 @t0(i32 %a) {
76 %x = add i32 trunc (i64 sub (i64 ptrtoint (i32** @bargotequiv to i64),
77 i64 ptrtoint (i32 (i32)* @t0 to i64))
82 ; Check that these got equivalent symbols are emitted on ARM64. Since ARM64
83 ; does not support encoding an extra offset with @GOT, we still need to emit the
84 ; equivalents for use by such IR constructs. Check them at the end of the test
85 ; since they will start out as GOT equivalent candidates, but they are actually
86 ; needed and are therefore emitted at the end.
88 ; CHECK-LABEL: l_localgotequiv:
89 ; CHECK-NEXT: .quad _localfoo
91 ; CHECK-LABEL: l_extgotequiv:
92 ; CHECK-NEXT: .quad _extfoo