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 ; FIXME: the checking for extgotequiv and localgotequiv rely on the emission
6 ; order, which is not guaranteed because we use DenseMap to hold the GOT
10 ; GOT equivalent globals references can be replaced by the GOT entry of the
11 ; final symbol instead.
13 %struct.data = type { i32, %struct.anon }
14 %struct.anon = type { i32, i32 }
16 ; Check that these got equivalent symbols are emitted on ARM64. Since ARM64 does
17 ; not support encoding an extra offset with @GOT, we still need to emit the
18 ; equivalents for use by such IR constructs.
20 ; ARM-GOT-EQUIV: {{.*}}extgotequiv:
21 ; ARM-GOT-EQUIV: {{.*}}localgotequiv:
22 @localfoo = global i32 42
23 @localgotequiv = private unnamed_addr constant i32* @localfoo
25 @extfoo = external global i32
26 @extgotequiv = private unnamed_addr constant i32* @extfoo
28 ; Don't replace GOT equivalent usage within instructions and emit the GOT
29 ; equivalent since it can't be replaced by the GOT entry. @bargotequiv is
30 ; used by an instruction inside @t0.
32 ; ARM: {{.*}}bargotequiv:
33 ; ARM-NEXT: .quad _extbar
34 @extbar = external global i32
35 @bargotequiv = private unnamed_addr constant i32* @extbar
37 @table = global [4 x %struct.data] [
39 %struct.data { i32 1, %struct.anon { i32 2, i32 3 } },
40 ; Test GOT equivalent usage inside nested constant arrays.
43 ; ARM-NOT: .long _localgotequiv-(_table+20)
45 ; ARM-NEXT: .long _localfoo@GOT-Ltmp1
46 %struct.data { i32 4, %struct.anon { i32 5,
47 i32 trunc (i64 sub (i64 ptrtoint (i32** @localgotequiv to i64),
48 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data]* @table, i32 0, i64 1, i32 1, i32 1) to i64))
53 ; ARM-NOT: _extgotequiv-(_table+32)
55 ; ARM-NEXT: _extfoo@GOT-Ltmp2
56 %struct.data { i32 4, %struct.anon { i32 5,
57 i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
58 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data]* @table, i32 0, i64 2, i32 1, i32 1) to i64))
61 ; Test support for arbitrary constants into the GOTPCREL offset, which is
62 ; supported on x86-64 but not on ARM64
65 ; ARM-NEXT: .long ({{.*}}extgotequiv-(_table+44))+24
66 %struct.data { i32 4, %struct.anon { i32 5,
67 i32 add (i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
68 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data]* @table, i32 0, i64 3, i32 1, i32 1) to i64))
73 ; Test multiple uses of GOT equivalents.
77 ; ARM-NEXT: .long _extfoo@GOT-Ltmp3
78 @delta = global i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
79 i64 ptrtoint (i32* @delta to i64))
82 ; ARM-LABEL: _deltaplus:
83 ; ARM: .long ({{.*}}localgotequiv-_deltaplus)+55
84 @deltaplus = global i32 add (i32 trunc (i64 sub (i64 ptrtoint (i32** @localgotequiv to i64),
85 i64 ptrtoint (i32* @deltaplus to i64))
88 define i32 @t0(i32 %a) {
89 %x = add i32 trunc (i64 sub (i64 ptrtoint (i32** @bargotequiv to i64),
90 i64 ptrtoint (i32 (i32)* @t0 to i64))