1 ; RUN: llc -mtriple=arm64-apple-darwin %s -o %t
2 ; RUN: FileCheck %s -check-prefix=ARM < %t
3 ; RUN: FileCheck %s -check-prefix=ARM-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 on x86-64 and
12 ; emitted on ARM64. Since ARM64 does not support encoding an extra offset with
13 ; @GOT, we still need to emit the equivalents for use by such IR constructs.
15 ; ARM-GOT-EQUIV-LABEL: l_extgotequiv:
16 ; ARM-GOT-EQUIV-LABEL: l_localgotequiv:
17 @localfoo = global i32 42
18 @localgotequiv = private unnamed_addr constant i32* @localfoo
20 @extfoo = external global i32
21 @extgotequiv = private unnamed_addr constant i32* @extfoo
23 ; Don't replace GOT equivalent usage within instructions and emit the GOT
24 ; equivalent since it can't be replaced by the GOT entry. @bargotequiv is
25 ; used by an instruction inside @t0.
28 ; ARM-NEXT: .quad _extbar
29 @extbar = external global i32
30 @bargotequiv = private unnamed_addr constant i32* @extbar
32 @table = global [4 x %struct.data] [
34 %struct.data { i32 1, %struct.anon { i32 2, i32 3 } },
35 ; Test GOT equivalent usage inside nested constant arrays.
38 ; ARM-NOT: .long _localgotequiv-(_table+20)
40 ; ARM-NEXT: .long _localfoo@GOT-Ltmp1
41 %struct.data { i32 4, %struct.anon { i32 5,
42 i32 trunc (i64 sub (i64 ptrtoint (i32** @localgotequiv to i64),
43 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data]* @table, i32 0, i64 1, i32 1, i32 1) to i64))
48 ; ARM-NOT: _extgotequiv-(_table+32)
50 ; ARM-NEXT: _extfoo@GOT-Ltmp2
51 %struct.data { i32 4, %struct.anon { i32 5,
52 i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
53 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data]* @table, i32 0, i64 2, i32 1, i32 1) to i64))
56 ; Test support for arbitrary constants into the GOTPCREL offset, which is
57 ; supported on x86-64 but not on ARM64
60 ; ARM-NEXT: .long (l_extgotequiv-(_table+44))+24
61 %struct.data { i32 4, %struct.anon { i32 5,
62 i32 add (i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
63 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data]* @table, i32 0, i64 3, i32 1, i32 1) to i64))
68 ; Test multiple uses of GOT equivalents.
72 ; ARM-NEXT: .long _extfoo@GOT-Ltmp3
73 @delta = global i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
74 i64 ptrtoint (i32* @delta to i64))
77 ; ARM-LABEL: _deltaplus:
78 ; ARM: .long (l_localgotequiv-_deltaplus)+55
79 @deltaplus = global i32 add (i32 trunc (i64 sub (i64 ptrtoint (i32** @localgotequiv to i64),
80 i64 ptrtoint (i32* @deltaplus to i64))
83 define i32 @t0(i32 %a) {
84 %x = add i32 trunc (i64 sub (i64 ptrtoint (i32** @bargotequiv to i64),
85 i64 ptrtoint (i32 (i32)* @t0 to i64))