Debian Codegraph @

llvm/test/MC/MachO/AArch64/cstexpr-gotpcrel.ll

raw
1 ; RUN: llc -mtriple=arm64-apple-darwin %s -o - | FileCheck %s
2
3 ; GOT equivalent globals references can be replaced by the GOT entry of the
4 ; final symbol instead.
5
6 %struct.data = type { i32, %struct.anon }
7 %struct.anon = type { i32, i32 }
8
9 @localfoo = global i32 42
10 @localgotequiv = private unnamed_addr constant ptr @localfoo
11
12 @extfoo = external global i32
13 @extgotequiv = private unnamed_addr constant ptr @extfoo
14
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.
18 ;
19 ; CHECK: l_bargotequiv:
20 ; CHECK-NEXT: .quad _extbar
21 @extbar = external global i32
22 @bargotequiv = private unnamed_addr constant ptr @extbar
23
24 @table = global [4 x %struct.data] [
25 ; CHECK-LABEL: _table
26 %struct.data { i32 1, %struct.anon { i32 2, i32 3 } },
27 ; Test GOT equivalent usage inside nested constant arrays.
28
29 ; CHECK: .long 5
30 ; CHECK-NOT: .long _localgotequiv-(_table+20)
31 ; CHECK-NEXT: Ltmp0:
32 ; CHECK-NEXT: .long _localfoo@GOT-Ltmp0
33 %struct.data { i32 4, %struct.anon { i32 5,
34 i32 trunc (i64 sub (i64 ptrtoint (ptr @localgotequiv to i64),
35 i64 ptrtoint (ptr getelementptr inbounds ([4 x %struct.data], ptr @table, i32 0, i64 1, i32 1, i32 1) to i64))
36 to i32)}
37 },
38
39 ; CHECK: .long 5
40 ; CHECK-NOT: _extgotequiv-(_table+32)
41 ; CHECK-NEXT: Ltmp1:
42 ; CHECK-NEXT: _extfoo@GOT-Ltmp1
43 %struct.data { i32 4, %struct.anon { i32 5,
44 i32 trunc (i64 sub (i64 ptrtoint (ptr @extgotequiv to i64),
45 i64 ptrtoint (ptr getelementptr inbounds ([4 x %struct.data], ptr @table, i32 0, i64 2, i32 1, i32 1) to i64))
46 to i32)}
47 },
48 ; Test support for arbitrary constants into the GOTPCREL offset, which is
49 ; supported on x86-64 but not on ARM64
50
51 ; CHECK: .long 5
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 (ptr @extgotequiv to i64),
55 i64 ptrtoint (ptr getelementptr inbounds ([4 x %struct.data], ptr @table, i32 0, i64 3, i32 1, i32 1) to i64))
56 to i32), i32 24)}
57 }
58 ], align 16
59
60 ; Test multiple uses of GOT equivalents.
61
62 ; CHECK-LABEL: _delta
63 ; CHECK: Ltmp2:
64 ; CHECK-NEXT: .long _extfoo@GOT-Ltmp2
65 @delta = global i32 trunc (i64 sub (i64 ptrtoint (ptr @extgotequiv to i64),
66 i64 ptrtoint (ptr @delta to i64))
67 to i32)
68
69 ; CHECK-LABEL: _deltaplus:
70 ; CHECK: .long (l_localgotequiv-_deltaplus)+55
71 @deltaplus = global i32 add (i32 trunc (i64 sub (i64 ptrtoint (ptr @localgotequiv to i64),
72 i64 ptrtoint (ptr @deltaplus to i64))
73 to i32), i32 55)
74
75 define i32 @t0(i32 %a) {
76 %x = add i32 trunc (i64 sub (i64 ptrtoint (ptr @bargotequiv to i64),
77 i64 ptrtoint (ptr @t0 to i64))
78 to i32), %a
79 ret i32 %x
80 }
81
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.
87
88 ; CHECK-LABEL: l_localgotequiv:
89 ; CHECK-NEXT: .quad _localfoo
90
91 ; CHECK-LABEL: l_extgotequiv:
92 ; CHECK-NEXT: .quad _extfoo