1; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64 %s
2; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu -relocation-model=pic | FileCheck -check-prefix=X64_PIC %s
3; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu | FileCheck -check-prefix=X32 %s
4; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu -relocation-model=pic | FileCheck -check-prefix=X32_PIC %s
5
6; Darwin always uses the same model.
7; RUN: llc < %s -march=x86-64 -mtriple=x86_64-apple-darwin | FileCheck -check-prefix=DARWIN %s
8
9@external_gd = external thread_local global i32
10@internal_gd = internal thread_local global i32 42
11
12@external_ld = external thread_local(localdynamic) global i32
13@internal_ld = internal thread_local(localdynamic) global i32 42
14
15@external_ie = external thread_local(initialexec) global i32
16@internal_ie = internal thread_local(initialexec) global i32 42
17
18@external_le = external thread_local(localexec) global i32
19@internal_le = internal thread_local(localexec) global i32 42
20
21; ----- no model specified -----
22
23define i32* @f1() {
24entry:
25  ret i32* @external_gd
26
27  ; Non-PIC code can use initial-exec, PIC code has to use general dynamic.
28  ; X64-LABEL:     f1:
29  ; X64:     external_gd@GOTTPOFF
30  ; X32-LABEL:     f1:
31  ; X32:     external_gd@INDNTPOFF
32  ; X64_PIC-LABEL: f1:
33  ; X64_PIC: external_gd@TLSGD
34  ; X32_PIC-LABEL: f1:
35  ; X32_PIC: external_gd@TLSGD
36  ; DARWIN-LABEL:  f1:
37  ; DARWIN:  _external_gd@TLVP
38}
39
40define i32* @f2() {
41entry:
42  ret i32* @internal_gd
43
44  ; Non-PIC code can use local exec, PIC code can use local dynamic.
45  ; X64-LABEL:     f2:
46  ; X64:     internal_gd@TPOFF
47  ; X32-LABEL:     f2:
48  ; X32:     internal_gd@NTPOFF
49  ; X64_PIC-LABEL: f2:
50  ; X64_PIC: internal_gd@TLSLD
51  ; X32_PIC-LABEL: f2:
52  ; X32_PIC: internal_gd@TLSLDM
53  ; DARWIN-LABEL:  f2:
54  ; DARWIN:  _internal_gd@TLVP
55}
56
57
58; ----- localdynamic specified -----
59
60define i32* @f3() {
61entry:
62  ret i32* @external_ld
63
64  ; Non-PIC code can use initial exec, PIC code use local dynamic as specified.
65  ; X64-LABEL:     f3:
66  ; X64:     external_ld@GOTTPOFF
67  ; X32-LABEL:     f3:
68  ; X32:     external_ld@INDNTPOFF
69  ; X64_PIC-LABEL: f3:
70  ; X64_PIC: external_ld@TLSLD
71  ; X32_PIC-LABEL: f3:
72  ; X32_PIC: external_ld@TLSLDM
73  ; DARWIN-LABEL:  f3:
74  ; DARWIN:  _external_ld@TLVP
75}
76
77define i32* @f4() {
78entry:
79  ret i32* @internal_ld
80
81  ; Non-PIC code can use local exec, PIC code can use local dynamic.
82  ; X64-LABEL:     f4:
83  ; X64:     internal_ld@TPOFF
84  ; X32-LABEL:     f4:
85  ; X32:     internal_ld@NTPOFF
86  ; X64_PIC-LABEL: f4:
87  ; X64_PIC: internal_ld@TLSLD
88  ; X32_PIC-LABEL: f4:
89  ; X32_PIC: internal_ld@TLSLDM
90  ; DARWIN-LABEL:  f4:
91  ; DARWIN:  _internal_ld@TLVP
92}
93
94
95; ----- initialexec specified -----
96
97define i32* @f5() {
98entry:
99  ret i32* @external_ie
100
101  ; Non-PIC and PIC code will use initial exec as specified.
102  ; X64-LABEL:     f5:
103  ; X64:     external_ie@GOTTPOFF
104  ; X32-LABEL:     f5:
105  ; X32:     external_ie@INDNTPOFF
106  ; X64_PIC-LABEL: f5:
107  ; X64_PIC: external_ie@GOTTPOFF
108  ; X32_PIC-LABEL: f5:
109  ; X32_PIC: external_ie@GOTNTPOFF
110  ; DARWIN-LABEL:  f5:
111  ; DARWIN:  _external_ie@TLVP
112}
113
114define i32* @f6() {
115entry:
116  ret i32* @internal_ie
117
118  ; Non-PIC code can use local exec, PIC code use initial exec as specified.
119  ; X64-LABEL:     f6:
120  ; X64:     internal_ie@TPOFF
121  ; X32-LABEL:     f6:
122  ; X32:     internal_ie@NTPOFF
123  ; X64_PIC-LABEL: f6:
124  ; X64_PIC: internal_ie@GOTTPOFF
125  ; X32_PIC-LABEL: f6:
126  ; X32_PIC: internal_ie@GOTNTPOFF
127  ; DARWIN-LABEL:  f6:
128  ; DARWIN:  _internal_ie@TLVP
129}
130
131define i32 @PR22083() {
132entry:
133  ret i32 ptrtoint (i32* @external_ie to i32)
134  ; X64-LABEL:     PR22083:
135  ; X64:     movq    external_ie@GOTTPOFF(%rip), %rax
136  ; X64_PIC-LABEL: PR22083:
137  ; X64_PIC: movq    external_ie@GOTTPOFF(%rip), %rax
138}
139
140; ----- localexec specified -----
141
142define i32* @f7() {
143entry:
144  ret i32* @external_le
145
146  ; Non-PIC and PIC code will use local exec as specified.
147  ; X64-LABEL:     f7:
148  ; X64:     external_le@TPOFF
149  ; X32-LABEL:     f7:
150  ; X32:     external_le@NTPOFF
151  ; X64_PIC-LABEL: f7:
152  ; X64_PIC: external_le@TPOFF
153  ; X32_PIC-LABEL: f7:
154  ; X32_PIC: external_le@NTPOFF
155  ; DARWIN-LABEL:  f7:
156  ; DARWIN:  _external_le@TLVP
157}
158
159define i32* @f8() {
160entry:
161  ret i32* @internal_le
162
163  ; Non-PIC and PIC code will use local exec as specified.
164  ; X64-LABEL:     f8:
165  ; X64:     internal_le@TPOFF
166  ; X32-LABEL:     f8:
167  ; X32:     internal_le@NTPOFF
168  ; X64_PIC-LABEL: f8:
169  ; X64_PIC: internal_le@TPOFF
170  ; X32_PIC-LABEL: f8:
171  ; X32_PIC: internal_le@NTPOFF
172  ; DARWIN-LABEL:  f8:
173  ; DARWIN:  _internal_le@TLVP
174}
175