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
5 ; GOT equivalent globals references can be replaced by the GOT entry of the
6 ; final symbol instead.
8 %struct.data = type { i32, %struct.anon }
9 %struct.anon = type { i32, i32 }
11 ; Check that these got equivalent symbols are never emitted.
13 ; X86-GOT-EQUIV-NOT: L_localgotequiv
14 ; X86-GOT-EQUIV-NOT: l_extgotequiv
15 @localfoo = global i32 42
16 @localgotequiv = private unnamed_addr constant i32* @localfoo
18 @extfoo = external global i32
19 @extgotequiv = private unnamed_addr constant i32* @extfoo
21 ; Don't replace GOT equivalent usage within instructions and emit the GOT
22 ; equivalent since it can't be replaced by the GOT entry. @bargotequiv is
23 ; used by an instruction inside @t0.
26 ; X86-NEXT: .quad _extbar
27 @extbar = external global i32
28 @bargotequiv = private unnamed_addr constant i32* @extbar
30 @table = global [4 x %struct.data] [
31 %struct.data { i32 1, %struct.anon { i32 2, i32 3 } },
32 ; Test GOT equivalent usage inside nested constant arrays.
35 ; X86-NOT: .long _localgotequiv-(_table+20)
36 ; X86-NEXT: .long _localfoo@GOTPCREL+4
37 %struct.data { i32 4, %struct.anon { i32 5,
38 i32 trunc (i64 sub (i64 ptrtoint (i32** @localgotequiv to i64),
39 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i64 1, i32 1, i32 1) to i64))
43 ; X86-NOT: _extgotequiv-(_table+32)
44 ; X86-NEXT: .long _extfoo@GOTPCREL+4
45 %struct.data { i32 4, %struct.anon { i32 5,
46 i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
47 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i64 2, i32 1, i32 1) to i64))
50 ; Test support for arbitrary constants into the GOTPCREL offset.
53 ; X86-NOT: _extgotequiv-(_table+44)
54 ; X86-NEXT: .long _extfoo@GOTPCREL+28
55 %struct.data { i32 4, %struct.anon { i32 5,
56 i32 add (i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
57 i64 ptrtoint (i32* getelementptr inbounds ([4 x %struct.data], [4 x %struct.data]* @table, i32 0, i64 3, i32 1, i32 1) to i64))
62 ; Test multiple uses of GOT equivalents.
65 ; X86: .long _extfoo@GOTPCREL+4
66 @delta = global i32 trunc (i64 sub (i64 ptrtoint (i32** @extgotequiv to i64),
67 i64 ptrtoint (i32* @delta to i64))
70 ; X86-LABEL: _deltaplus:
71 ; X86: .long _localfoo@GOTPCREL+59
72 @deltaplus = global i32 add (i32 trunc (i64 sub (i64 ptrtoint (i32** @localgotequiv to i64),
73 i64 ptrtoint (i32* @deltaplus to i64))
76 define i32 @t0(i32 %a) {
77 %x = add i32 trunc (i64 sub (i64 ptrtoint (i32** @bargotequiv to i64),
78 i64 ptrtoint (i32 (i32)* @t0 to i64))
83 ; Also test direct instruction uses.
85 ret i32** @bargotequiv
88 ; Do not crash when a pattern cannot be matched as a GOT equivalent
90 @a = external global i8
91 @b = internal unnamed_addr constant i8* @a