1 ; RUN: llc -mtriple=x86_64-apple-darwin %s -o %t
2 ; RUN: FileCheck %s -check-prefix=X86 < %t
3 ; RUN: FileCheck %s -check-prefix=X86-GOT-EQUIV < %t
4 ; RUN: FileCheck %s -check-prefix=X86-NOGOT-EQUIV < %t
6 ; GOT equivalent globals references can be replaced by the GOT entry of the
7 ; final symbol instead.
9 %struct.data = type { i32, %struct.anon }
10 %struct.anon = type { i32, i32 }
12 ; Check that these got equivalent symbols are never emitted.
14 ; X86-GOT-EQUIV-NOT: L_localgotequiv
15 ; X86-GOT-EQUIV-NOT: l_extgotequiv
16 @localfoo = global i32 42
17 @localgotequiv = private unnamed_addr constant i32* @localfoo
19 @extfoo = external global i32
20 @extgotequiv = private unnamed_addr constant i32* @extfoo
22 ; Don't replace GOT equivalent usage within instructions and emit the GOT
23 ; equivalent since it can't be replaced by the GOT entry. @bargotequiv is
24 ; used by an instruction inside @t0.
27 ; X86-NEXT: .quad _extbar
28 @extbar = external global i32
29 @bargotequiv = private unnamed_addr constant i32* @extbar
31 @table = global [4 x %struct.data] [
32 %struct.data { i32 1, %struct.anon { i32 2, i32 3 } },
33 ; Test GOT equivalent usage inside nested constant arrays.
36 ; X86-NOT: .long _localgotequiv-(_table+20)
37 ; X86-NEXT: .long _localfoo@GOTPCREL+4
38 %struct.data { i32 4, %struct.anon { i32 5,
39 i32 trunc (i64 sub (i64 ptrtoint (i32** @localgotequiv to i64),
40 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i64 1, i32 1, i32 1) to i64))
44 ; X86-NOT: _extgotequiv-(_table+32)
45 ; X86-NEXT: .long _extfoo@GOTPCREL+4
46 %struct.data { i32 4, %struct.anon { i32 5,
47 i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
48 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i64 2, i32 1, i32 1) to i64))
51 ; Test support for arbitrary constants into the GOTPCREL offset.
54 ; X86-NOT: _extgotequiv-(_table+44)
55 ; X86-NEXT: .long _extfoo@GOTPCREL+28
56 %struct.data { i32 4, %struct.anon { i32 5,
57 i32 add (i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
58 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i64 3, i32 1, i32 1) to i64))
63 ; Test multiple uses of GOT equivalents.
66 ; X86: .long _extfoo@GOTPCREL+4
67 @delta = global i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
68 i64 ptrtoint (i32* @delta to i64))
71 ; X86-LABEL: _deltaplus:
72 ; X86: .long _localfoo@GOTPCREL+59
73 @deltaplus = global i32 add (i32 trunc (i64 sub (i64 ptrtoint (i32** @localgotequiv to i64),
74 i64 ptrtoint (i32* @deltaplus to i64))
77 define i32 @t0(i32 %a) {
78 %x = add i32 trunc (i64 sub (i64 ptrtoint (i32** @bargotequiv to i64),
79 i64 ptrtoint (i32 (i32)* @t0 to i64))
84 ; Also test direct instruction uses.
86 ret i32** @bargotequiv
89 ; Do not crash when a pattern cannot be matched as a GOT equivalent
91 ; X86-NOGOT-EQUIV-LABEL: _foo:
92 ; X86-NOGOT-EQUIV: leaq _b(%rip), %rax
93 store i8** @b, i8*** null
96 @a = external global i8
97 @b = internal unnamed_addr constant i8* @a
99 ; X86-NOGOT-EQUIV-LABEL: _c:
100 ; X86-NOGOT-EQUIV: .quad _b