xref: /aosp_15_r20/external/llvm/test/MC/MachO/cstexpr-gotpcrel-32.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -mtriple=i386-apple-darwin %s -o %t
2*9880d681SAndroid Build Coastguard Worker; RUN:  FileCheck %s < %t
3*9880d681SAndroid Build Coastguard Worker; RUN:  FileCheck %s -check-prefix=GOT-EQUIV < %t
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker; GOT equivalent globals references can be replaced by the GOT entry of the
6*9880d681SAndroid Build Coastguard Worker; final symbol instead.
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Worker%struct.data = type { i32, %struct.anon }
9*9880d681SAndroid Build Coastguard Worker%struct.anon = type { i32, i32 }
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker; Check that these got equivalent symbols are never emitted or used
12*9880d681SAndroid Build Coastguard Worker; GOT-EQUIV-NOT: _localgotequiv
13*9880d681SAndroid Build Coastguard Worker; GOT-EQUIV-NOT: _extgotequiv
14*9880d681SAndroid Build Coastguard Worker@localfoo = global i32 42
15*9880d681SAndroid Build Coastguard Worker@localgotequiv = private unnamed_addr constant i32* @localfoo
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker@extfoo = external global i32
18*9880d681SAndroid Build Coastguard Worker@extgotequiv = private unnamed_addr constant i32* @extfoo
19*9880d681SAndroid Build Coastguard Worker
20*9880d681SAndroid Build Coastguard Worker; Don't replace GOT equivalent usage within instructions and emit the GOT
21*9880d681SAndroid Build Coastguard Worker; equivalent since it can't be replaced by the GOT entry. @bargotequiv is
22*9880d681SAndroid Build Coastguard Worker; used by an instruction inside @t0.
23*9880d681SAndroid Build Coastguard Worker;
24*9880d681SAndroid Build Coastguard Worker; CHECK: l_bargotequiv:
25*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:  .long   _extbar
26*9880d681SAndroid Build Coastguard Worker@extbar = external global i32
27*9880d681SAndroid Build Coastguard Worker@bargotequiv = private unnamed_addr constant i32* @extbar
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Worker@table = global [4 x %struct.data] [
30*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _table
31*9880d681SAndroid Build Coastguard Worker  %struct.data { i32 1, %struct.anon { i32 2, i32 3 } },
32*9880d681SAndroid Build Coastguard Worker; Test GOT equivalent usage inside nested constant arrays.
33*9880d681SAndroid Build Coastguard Worker; CHECK: .long   5
34*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: l_localgotequiv-(_table+20)
35*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: L_localfoo$non_lazy_ptr-(_table+20)
36*9880d681SAndroid Build Coastguard Worker  %struct.data { i32 4, %struct.anon { i32 5,
37*9880d681SAndroid Build Coastguard Worker    i32 sub (i32 ptrtoint (i32** @localgotequiv to i32),
38*9880d681SAndroid Build Coastguard Worker             i32 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i32 1, i32 1, i32 1) to i32))}
39*9880d681SAndroid Build Coastguard Worker  },
40*9880d681SAndroid Build Coastguard Worker; CHECK: .long   5
41*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: l_extgotequiv-(_table+32)
42*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: L_extfoo$non_lazy_ptr-(_table+32)
43*9880d681SAndroid Build Coastguard Worker  %struct.data { i32 4, %struct.anon { i32 5,
44*9880d681SAndroid Build Coastguard Worker    i32 sub (i32 ptrtoint (i32** @extgotequiv to i32),
45*9880d681SAndroid Build Coastguard Worker             i32 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i32 2, i32 1, i32 1) to i32))}
46*9880d681SAndroid Build Coastguard Worker  },
47*9880d681SAndroid Build Coastguard Worker; Test support for arbitrary constants into the GOTPCREL offset
48*9880d681SAndroid Build Coastguard Worker; CHECK: .long   5
49*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: (l_extgotequiv-(_table+44))+24
50*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: L_extfoo$non_lazy_ptr-(_table+20)
51*9880d681SAndroid Build Coastguard Worker  %struct.data { i32 4, %struct.anon { i32 5,
52*9880d681SAndroid Build Coastguard Worker    i32 add (i32 sub (i32 ptrtoint (i32** @extgotequiv to i32),
53*9880d681SAndroid Build Coastguard Worker                      i32 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i32 3, i32 1, i32 1) to i32)),
54*9880d681SAndroid Build Coastguard Worker                      i32 24)}
55*9880d681SAndroid Build Coastguard Worker  }
56*9880d681SAndroid Build Coastguard Worker], align 16
57*9880d681SAndroid Build Coastguard Worker
58*9880d681SAndroid Build Coastguard Worker; Test multiple uses of GOT equivalents.
59*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _delta
60*9880d681SAndroid Build Coastguard Worker; CHECK: .long   L_extfoo$non_lazy_ptr-_delta
61*9880d681SAndroid Build Coastguard Worker@delta = global i32 sub (i32 ptrtoint (i32** @extgotequiv to i32),
62*9880d681SAndroid Build Coastguard Worker                         i32 ptrtoint (i32* @delta to i32))
63*9880d681SAndroid Build Coastguard Worker
64*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _deltaplus:
65*9880d681SAndroid Build Coastguard Worker; CHECK: .long   L_localfoo$non_lazy_ptr-(_deltaplus-55)
66*9880d681SAndroid Build Coastguard Worker@deltaplus = global i32 add (i32 sub (i32 ptrtoint (i32** @localgotequiv to i32),
67*9880d681SAndroid Build Coastguard Worker                             i32 ptrtoint (i32* @deltaplus to i32)),
68*9880d681SAndroid Build Coastguard Worker                             i32 55)
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard Workerdefine i32 @t0(i32 %a) {
71*9880d681SAndroid Build Coastguard Worker  %x = add i32 sub (i32 ptrtoint (i32** @bargotequiv to i32),
72*9880d681SAndroid Build Coastguard Worker                    i32 ptrtoint (i32 (i32)* @t0 to i32)), %a
73*9880d681SAndroid Build Coastguard Worker  ret i32 %x
74*9880d681SAndroid Build Coastguard Worker}
75