b65b902c1f9cbc0ec4d706396f55bd8b432ade01
[oota-llvm.git] / test / MC / MachO / AArch64 / cstexpr-gotpcrel.ll
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
4
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
7 ; equivalents.
8 ; XFAIL: *
9
10 ; GOT equivalent globals references can be replaced by the GOT entry of the
11 ; final symbol instead.
12
13 %struct.data = type { i32, %struct.anon }
14 %struct.anon = type { i32, i32 }
15
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.
19
20 ; ARM-GOT-EQUIV: {{.*}}extgotequiv:
21 ; ARM-GOT-EQUIV: {{.*}}localgotequiv:
22 @localfoo = global i32 42
23 @localgotequiv = private unnamed_addr constant i32* @localfoo
24
25 @extfoo = external global i32
26 @extgotequiv = private unnamed_addr constant i32* @extfoo
27
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.
31 ;
32 ; ARM: {{.*}}bargotequiv:
33 ; ARM-NEXT:  .quad   _extbar
34 @extbar = external global i32
35 @bargotequiv = private unnamed_addr constant i32* @extbar
36
37 @table = global [4 x %struct.data] [
38 ; ARM-LABEL: _table
39   %struct.data { i32 1, %struct.anon { i32 2, i32 3 } },
40 ; Test GOT equivalent usage inside nested constant arrays.
41
42 ; ARM: .long   5
43 ; ARM-NOT: .long   _localgotequiv-(_table+20)
44 ; ARM-NEXT: Ltmp1:
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))
49                         to i32)}
50   },
51
52 ; ARM: .long   5
53 ; ARM-NOT: _extgotequiv-(_table+32)
54 ; ARM-NEXT: Ltmp2:
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))
59                         to i32)}
60   },
61 ; Test support for arbitrary constants into the GOTPCREL offset, which is
62 ; supported on x86-64 but not on ARM64
63
64 ; ARM: .long   5
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))
69                                  to i32), i32 24)}
70   }
71 ], align 16
72
73 ; Test multiple uses of GOT equivalents.
74
75 ; ARM-LABEL: _delta
76 ; ARM: Ltmp3:
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))
80                            to i32)
81
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))
86                                         to i32), i32 55)
87
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))
91                            to i32), %a
92   ret i32 %x
93 }