1 ; RUN: llc < %s -mtriple=i386-linux-gnu | FileCheck -check-prefix=X86_LINUX %s
2 ; RUN: llc < %s -mtriple=x86_64-linux-gnu | FileCheck -check-prefix=X64_LINUX %s
3 ; RUN: llc < %s -mtriple=i386-linux-gnu -fast-isel | FileCheck -check-prefix=X86_ISEL_LINUX %s
4 ; RUN: llc < %s -mtriple=x86_64-linux-gnu -fast-isel | FileCheck -check-prefix=X64_ISEL_LINUX %s
5 ; RUN: llc < %s -mtriple=i686-pc-win32 | FileCheck -check-prefix=X86_WIN %s
6 ; RUN: llc < %s -mtriple=x86_64-pc-win32 | FileCheck -check-prefix=X64_WIN %s
7 ; RUN: llc < %s -mtriple=i686-pc-windows-gnu | FileCheck -check-prefix=MINGW32 %s
8 ; RUN: llc < %s -mtriple=x86_64-pc-windows-gnu | FileCheck -check-prefix=X64_WIN %s
10 @i1 = thread_local global i32 15
11 @i2 = external thread_local global i32
12 @i3 = internal thread_local global i32 15
13 @i4 = hidden thread_local global i32 15
14 @i5 = external hidden thread_local global i32
15 @i6 = external protected thread_local global i32
16 @s1 = thread_local global i16 15
17 @b1 = thread_local global i8 0
18 @b2 = thread_local(localexec) global i8 0
21 ; X86_LINUX-LABEL: f1:
22 ; X86_LINUX: movl %gs:i1@NTPOFF, %eax
24 ; X64_LINUX-LABEL: f1:
25 ; X64_LINUX: movl %fs:i1@TPOFF, %eax
28 ; X86_WIN: movl __tls_index, %eax
29 ; X86_WIN-NEXT: movl %fs:__tls_array, %ecx
30 ; X86_WIN-NEXT: movl (%ecx,%eax,4), %eax
31 ; X86_WIN-NEXT: movl _i1@SECREL32(%eax), %eax
34 ; X64_WIN: movl _tls_index(%rip), %eax
35 ; X64_WIN-NEXT: movq %gs:88, %rcx
36 ; X64_WIN-NEXT: movq (%rcx,%rax,8), %rax
37 ; X64_WIN-NEXT: movl i1@SECREL32(%rax), %eax
40 ; MINGW32: movl __tls_index, %eax
41 ; MINGW32-NEXT: movl %fs:44, %ecx
42 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
43 ; MINGW32-NEXT: movl _i1@SECREL32(%eax), %eax
47 %tmp1 = load i32, i32* @i1
52 ; X86_LINUX-LABEL: f2:
53 ; X86_LINUX: movl %gs:0, %eax
54 ; X86_LINUX-NEXT: leal i1@NTPOFF(%eax), %eax
56 ; X64_LINUX-LABEL: f2:
57 ; X64_LINUX: movq %fs:0, %rax
58 ; X64_LINUX-NEXT: leaq i1@TPOFF(%rax), %rax
61 ; X86_WIN: movl __tls_index, %eax
62 ; X86_WIN-NEXT: movl %fs:__tls_array, %ecx
63 ; X86_WIN-NEXT: movl (%ecx,%eax,4), %eax
64 ; X86_WIN-NEXT: leal _i1@SECREL32(%eax), %eax
67 ; X64_WIN: movl _tls_index(%rip), %eax
68 ; X64_WIN-NEXT: movq %gs:88, %rcx
69 ; X64_WIN-NEXT: movq (%rcx,%rax,8), %rax
70 ; X64_WIN-NEXT: leaq i1@SECREL32(%rax), %rax
73 ; MINGW32: movl __tls_index, %eax
74 ; MINGW32-NEXT: movl %fs:44, %ecx
75 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
76 ; MINGW32-NEXT: leal _i1@SECREL32(%eax), %eax
83 define i32 @f3() nounwind {
84 ; X86_LINUX-LABEL: f3:
85 ; X86_LINUX: movl i2@INDNTPOFF, %eax
86 ; X86_LINUX-NEXT: movl %gs:(%eax), %eax
88 ; X64_LINUX-LABEL: f3:
89 ; X64_LINUX: movq i2@GOTTPOFF(%rip), %rax
90 ; X64_LINUX-NEXT: movl %fs:(%rax), %eax
93 ; X86_WIN: movl __tls_index, %eax
94 ; X86_WIN-NEXT: movl %fs:__tls_array, %ecx
95 ; X86_WIN-NEXT: movl (%ecx,%eax,4), %eax
96 ; X86_WIN-NEXT: movl _i2@SECREL32(%eax), %eax
99 ; X64_WIN: movl _tls_index(%rip), %eax
100 ; X64_WIN-NEXT: movq %gs:88, %rcx
101 ; X64_WIN-NEXT: movq (%rcx,%rax,8), %rax
102 ; X64_WIN-NEXT: movl i2@SECREL32(%rax), %eax
104 ; MINGW32-LABEL: _f3:
105 ; MINGW32: movl __tls_index, %eax
106 ; MINGW32-NEXT: movl %fs:44, %ecx
107 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
108 ; MINGW32-NEXT: movl _i2@SECREL32(%eax), %eax
112 %tmp1 = load i32, i32* @i2
117 ; X86_LINUX-LABEL: f4:
118 ; X86_LINUX: movl %gs:0, %eax
119 ; X86_LINUX-NEXT: addl i2@INDNTPOFF, %eax
120 ; X86_LINUX-NEXT: ret
121 ; X64_LINUX-LABEL: f4:
122 ; X64_LINUX: movq %fs:0, %rax
123 ; X64_LINUX-NEXT: addq i2@GOTTPOFF(%rip), %rax
124 ; X64_LINUX-NEXT: ret
126 ; X86_WIN: movl __tls_index, %eax
127 ; X86_WIN-NEXT: movl %fs:__tls_array, %ecx
128 ; X86_WIN-NEXT: movl (%ecx,%eax,4), %eax
129 ; X86_WIN-NEXT: leal _i2@SECREL32(%eax), %eax
132 ; X64_WIN: movl _tls_index(%rip), %eax
133 ; X64_WIN-NEXT: movq %gs:88, %rcx
134 ; X64_WIN-NEXT: movq (%rcx,%rax,8), %rax
135 ; X64_WIN-NEXT: leaq i2@SECREL32(%rax), %rax
137 ; MINGW32-LABEL: _f4:
138 ; MINGW32: movl __tls_index, %eax
139 ; MINGW32-NEXT: movl %fs:44, %ecx
140 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
141 ; MINGW32-NEXT: leal _i2@SECREL32(%eax), %eax
148 define i32 @f5() nounwind {
149 ; X86_LINUX-LABEL: f5:
150 ; X86_LINUX: movl %gs:i3@NTPOFF, %eax
151 ; X86_LINUX-NEXT: ret
152 ; X64_LINUX-LABEL: f5:
153 ; X64_LINUX: movl %fs:i3@TPOFF, %eax
154 ; X64_LINUX-NEXT: ret
156 ; X86_WIN: movl __tls_index, %eax
157 ; X86_WIN-NEXT: movl %fs:__tls_array, %ecx
158 ; X86_WIN-NEXT: movl (%ecx,%eax,4), %eax
159 ; X86_WIN-NEXT: movl _i3@SECREL32(%eax), %eax
162 ; X64_WIN: movl _tls_index(%rip), %eax
163 ; X64_WIN-NEXT: movq %gs:88, %rcx
164 ; X64_WIN-NEXT: movq (%rcx,%rax,8), %rax
165 ; X64_WIN-NEXT: movl i3@SECREL32(%rax), %eax
167 ; MINGW32-LABEL: _f5:
168 ; MINGW32: movl __tls_index, %eax
169 ; MINGW32-NEXT: movl %fs:44, %ecx
170 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
171 ; MINGW32-NEXT: movl _i3@SECREL32(%eax), %eax
175 %tmp1 = load i32, i32* @i3
180 ; X86_LINUX-LABEL: f6:
181 ; X86_LINUX: movl %gs:0, %eax
182 ; X86_LINUX-NEXT: leal i3@NTPOFF(%eax), %eax
183 ; X86_LINUX-NEXT: ret
184 ; X64_LINUX-LABEL: f6:
185 ; X64_LINUX: movq %fs:0, %rax
186 ; X64_LINUX-NEXT: leaq i3@TPOFF(%rax), %rax
187 ; X64_LINUX-NEXT: ret
189 ; X86_WIN: movl __tls_index, %eax
190 ; X86_WIN-NEXT: movl %fs:__tls_array, %ecx
191 ; X86_WIN-NEXT: movl (%ecx,%eax,4), %eax
192 ; X86_WIN-NEXT: leal _i3@SECREL32(%eax), %eax
195 ; X64_WIN: movl _tls_index(%rip), %eax
196 ; X64_WIN-NEXT: movq %gs:88, %rcx
197 ; X64_WIN-NEXT: movq (%rcx,%rax,8), %rax
198 ; X64_WIN-NEXT: leaq i3@SECREL32(%rax), %rax
200 ; MINGW32-LABEL: _f6:
201 ; MINGW32: movl __tls_index, %eax
202 ; MINGW32-NEXT: movl %fs:44, %ecx
203 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
204 ; MINGW32-NEXT: leal _i3@SECREL32(%eax), %eax
212 ; X86_LINUX-LABEL: f7:
213 ; X86_LINUX: movl %gs:i4@NTPOFF, %eax
214 ; X86_LINUX-NEXT: ret
215 ; X64_LINUX-LABEL: f7:
216 ; X64_LINUX: movl %fs:i4@TPOFF, %eax
217 ; X64_LINUX-NEXT: ret
218 ; MINGW32-LABEL: _f7:
219 ; MINGW32: movl __tls_index, %eax
220 ; MINGW32-NEXT: movl %fs:44, %ecx
221 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
222 ; MINGW32-NEXT: movl _i4@SECREL32(%eax), %eax
226 %tmp1 = load i32, i32* @i4
231 ; X86_LINUX-LABEL: f8:
232 ; X86_LINUX: movl %gs:0, %eax
233 ; X86_LINUX-NEXT: leal i4@NTPOFF(%eax), %eax
234 ; X86_LINUX-NEXT: ret
235 ; X64_LINUX-LABEL: f8:
236 ; X64_LINUX: movq %fs:0, %rax
237 ; X64_LINUX-NEXT: leaq i4@TPOFF(%rax), %rax
238 ; X64_LINUX-NEXT: ret
239 ; MINGW32-LABEL: _f8:
240 ; MINGW32: movl __tls_index, %eax
241 ; MINGW32-NEXT: movl %fs:44, %ecx
242 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
243 ; MINGW32-NEXT: leal _i4@SECREL32(%eax), %eax
251 ; X86_LINUX-LABEL: f9:
252 ; X86_LINUX: movl %gs:i5@NTPOFF, %eax
253 ; X86_LINUX-NEXT: ret
254 ; X64_LINUX-LABEL: f9:
255 ; X64_LINUX: movl %fs:i5@TPOFF, %eax
256 ; X64_LINUX-NEXT: ret
257 ; MINGW32-LABEL: _f9:
258 ; MINGW32: movl __tls_index, %eax
259 ; MINGW32-NEXT: movl %fs:44, %ecx
260 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
261 ; MINGW32-NEXT: movl _i5@SECREL32(%eax), %eax
265 %tmp1 = load i32, i32* @i5
270 ; X86_LINUX-LABEL: f10:
271 ; X86_LINUX: movl %gs:0, %eax
272 ; X86_LINUX-NEXT: leal i5@NTPOFF(%eax), %eax
273 ; X86_LINUX-NEXT: ret
274 ; X64_LINUX-LABEL: f10:
275 ; X64_LINUX: movq %fs:0, %rax
276 ; X64_LINUX-NEXT: leaq i5@TPOFF(%rax), %rax
277 ; X64_LINUX-NEXT: ret
278 ; MINGW32-LABEL: _f10:
279 ; MINGW32: movl __tls_index, %eax
280 ; MINGW32-NEXT: movl %fs:44, %ecx
281 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
282 ; MINGW32-NEXT: leal _i5@SECREL32(%eax), %eax
290 ; X86_LINUX-LABEL: f11:
291 ; X86_LINUX: movzwl %gs:s1@NTPOFF, %eax
293 ; X64_LINUX-LABEL: f11:
294 ; X64_LINUX: movzwl %fs:s1@TPOFF, %eax
296 ; X86_WIN-LABEL: f11:
297 ; X86_WIN: movl __tls_index, %eax
298 ; X86_WIN-NEXT: movl %fs:__tls_array, %ecx
299 ; X86_WIN-NEXT: movl (%ecx,%eax,4), %eax
300 ; X86_WIN-NEXT: movzwl _s1@SECREL32(%eax), %eax
302 ; X64_WIN-LABEL: f11:
303 ; X64_WIN: movl _tls_index(%rip), %eax
304 ; X64_WIN-NEXT: movq %gs:88, %rcx
305 ; X64_WIN-NEXT: movq (%rcx,%rax,8), %rax
306 ; X64_WIN-NEXT: movzwl s1@SECREL32(%rax), %eax
308 ; MINGW32-LABEL: _f11:
309 ; MINGW32: movl __tls_index, %eax
310 ; MINGW32-NEXT: movl %fs:44, %ecx
311 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
312 ; MINGW32-NEXT: movzwl _s1@SECREL32(%eax), %eax
316 %tmp1 = load i16, i16* @s1
321 ; X86_LINUX-LABEL: f12:
322 ; X86_LINUX: movswl %gs:s1@NTPOFF, %eax
323 ; X86_LINUX-NEXT: ret
324 ; X64_LINUX-LABEL: f12:
325 ; X64_LINUX: movswl %fs:s1@TPOFF, %eax
326 ; X64_LINUX-NEXT: ret
327 ; X86_WIN-LABEL: f12:
328 ; X86_WIN: movl __tls_index, %eax
329 ; X86_WIN-NEXT: movl %fs:__tls_array, %ecx
330 ; X86_WIN-NEXT: movl (%ecx,%eax,4), %eax
331 ; X86_WIN-NEXT: movswl _s1@SECREL32(%eax), %eax
333 ; X64_WIN-LABEL: f12:
334 ; X64_WIN: movl _tls_index(%rip), %eax
335 ; X64_WIN-NEXT: movq %gs:88, %rcx
336 ; X64_WIN-NEXT: movq (%rcx,%rax,8), %rax
337 ; X64_WIN-NEXT: movswl s1@SECREL32(%rax), %eax
339 ; MINGW32-LABEL: _f12:
340 ; MINGW32: movl __tls_index, %eax
341 ; MINGW32-NEXT: movl %fs:44, %ecx
342 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
343 ; MINGW32-NEXT: movswl _s1@SECREL32(%eax), %eax
348 %tmp1 = load i16, i16* @s1
349 %tmp2 = sext i16 %tmp1 to i32
354 ; X86_LINUX-LABEL: f13:
355 ; X86_LINUX: movb %gs:b1@NTPOFF, %al
356 ; X86_LINUX-NEXT: ret
357 ; X64_LINUX-LABEL: f13:
358 ; X64_LINUX: movb %fs:b1@TPOFF, %al
359 ; X64_LINUX-NEXT: ret
360 ; X86_WIN-LABEL: f13:
361 ; X86_WIN: movl __tls_index, %eax
362 ; X86_WIN-NEXT: movl %fs:__tls_array, %ecx
363 ; X86_WIN-NEXT: movl (%ecx,%eax,4), %eax
364 ; X86_WIN-NEXT: movb _b1@SECREL32(%eax), %al
366 ; X64_WIN-LABEL: f13:
367 ; X64_WIN: movl _tls_index(%rip), %eax
368 ; X64_WIN-NEXT: movq %gs:88, %rcx
369 ; X64_WIN-NEXT: movq (%rcx,%rax,8), %rax
370 ; X64_WIN-NEXT: movb b1@SECREL32(%rax), %al
372 ; MINGW32-LABEL: _f13:
373 ; MINGW32: movl __tls_index, %eax
374 ; MINGW32-NEXT: movl %fs:44, %ecx
375 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
376 ; MINGW32-NEXT: movb _b1@SECREL32(%eax), %al
380 %tmp1 = load i8, i8* @b1
385 ; X86_LINUX-LABEL: f14:
386 ; X86_LINUX: movsbl %gs:b1@NTPOFF, %eax
387 ; X86_LINUX-NEXT: ret
388 ; X64_LINUX-LABEL: f14:
389 ; X64_LINUX: movsbl %fs:b1@TPOFF, %eax
390 ; X64_LINUX-NEXT: ret
391 ; X86_WIN-LABEL: f14:
392 ; X86_WIN: movl __tls_index, %eax
393 ; X86_WIN-NEXT: movl %fs:__tls_array, %ecx
394 ; X86_WIN-NEXT: movl (%ecx,%eax,4), %eax
395 ; X86_WIN-NEXT: movsbl _b1@SECREL32(%eax), %eax
397 ; X64_WIN-LABEL: f14:
398 ; X64_WIN: movl _tls_index(%rip), %eax
399 ; X64_WIN-NEXT: movq %gs:88, %rcx
400 ; X64_WIN-NEXT: movq (%rcx,%rax,8), %rax
401 ; X64_WIN-NEXT: movsbl b1@SECREL32(%rax), %eax
403 ; MINGW32-LABEL: _f14:
404 ; MINGW32: movl __tls_index, %eax
405 ; MINGW32-NEXT: movl %fs:44, %ecx
406 ; MINGW32-NEXT: movl (%ecx,%eax,4), %eax
407 ; MINGW32-NEXT: movsbl _b1@SECREL32(%eax), %eax
411 %tmp1 = load i8, i8* @b1
412 %tmp2 = sext i8 %tmp1 to i32
417 ; X86_LINUX-LABEL: f15:
418 ; X86_LINUX: movl %gs:0, %eax
419 ; X86_LINUX-NEXT: leal b2@NTPOFF(%eax), %eax
420 ; X86_LINUX-NEXT: ret
421 ; X64_LINUX-LABEL: f15:
422 ; X64_LINUX: movq %fs:0, %rax
423 ; X64_LINUX-NEXT: leaq b2@TPOFF(%rax), %rax
424 ; X64_LINUX-NEXT: ret
425 ; X86_WIN-LABEL: f15:
426 ; X86_WIN: movl %fs:__tls_array, %eax
427 ; X86_WIN-NEXT: movl (%eax), %eax
428 ; X86_WIN-NEXT: leal _b2@SECREL32(%eax), %eax
430 ; X64_WIN-LABEL: f15:
431 ; X64_WIN: movq %gs:88, %rax
432 ; X64_WIN-NEXT: movq (%rax), %rax
433 ; X64_WIN-NEXT: leaq b2@SECREL32(%rax), %rax
435 ; MINGW32-LABEL: f15:
436 ; MINGW32: movl %fs:44, %eax
437 ; MINGW32-NEXT: movl (%eax), %eax
438 ; MINGW32-NEXT: leal _b2@SECREL32(%eax), %eax
446 ; X86_LINUX-LABEL: f16:
447 ; X86_LINUX: movl %gs:0, %eax
448 ; X86_LINUX-NEXT: leal i6@NTPOFF(%eax), %eax
449 ; X86_LINUX-NEXT: ret
451 ; X64_LINUX-LABEL: f16:
452 ; X64_LINUX: movq %fs:0, %rax
453 ; X64_LINUX-NEXT: leaq i6@TPOFF(%rax), %rax
454 ; X64_LINUX-NEXT: ret
459 ; NOTE: Similar to f1() but with direct TLS segment access disabled
460 define i32 @f17() #0 {
461 ; X86_LINUX-LABEL: f17:
462 ; X86_LINUX: movl %gs:0, %eax
463 ; X86_LINUX-NEXT: movl i1@NTPOFF(%eax), %eax
464 ; X86_LINUX-NEXT: ret
465 ; X64_LINUX-LABEL: f17:
466 ; X64_LINUX: movq %fs:0, %rax
467 ; X64_LINUX-NEXT: movl i1@TPOFF(%rax), %eax
468 ; X64_LINUX-NEXT: ret
469 ; X86_ISEL_LINUX-LABEL: f17:
470 ; X86_ISEL_LINUX: movl %gs:0, %eax
471 ; X86_ISEL_LINUX-NEXT: movl i1@NTPOFF(%eax), %eax
472 ; X86_ISEL_LINUX-NEXT: ret
473 ; X64_ISEL_LINUX-LABEL: f17:
474 ; X64_ISEL_LINUX: movq %fs:0, %rax
475 ; X64_ISEL_LINUX-NEXT: movl i1@TPOFF(%rax), %eax
476 ; X64_ISEL_LINUX-NEXT: ret
479 %tmp1 = load i32, i32* @i1
483 ; NOTE: Similar to f3() but with direct TLS segment access disabled
484 define i32 @f18() #1 {
485 ; X86_LINUX-LABEL: f18:
486 ; X86_LINUX: movl i2@INDNTPOFF, %eax
487 ; X86_LINUX-NEXT: movl %gs:0, %ecx
488 ; X86_LINUX-NEXT: movl (%ecx,%eax), %eax
489 ; X86_LINUX-NEXT: ret
490 ; X64_LINUX-LABEL: f18:
491 ; X64_LINUX: movq i2@GOTTPOFF(%rip), %rax
492 ; X64_LINUX-NEXT: movq %fs:0, %rcx
493 ; X64_LINUX-NEXT: movl (%rcx,%rax), %eax
494 ; X64_LINUX-NEXT: ret
495 ; X86_ISEL_LINUX-LABEL: f18:
496 ; X86_ISEL_LINUX: movl i2@INDNTPOFF, %eax
497 ; X86_ISEL_LINUX-NEXT: movl %gs:0, %ecx
498 ; X86_ISEL_LINUX-NEXT: movl (%ecx,%eax), %eax
499 ; X86_ISEL_LINUX-NEXT: ret
500 ; X64_ISEL_LINUX-LABEL: f18:
501 ; X64_ISEL_LINUX: movq i2@GOTTPOFF(%rip), %rax
502 ; X64_ISEL_LINUX-NEXT: movq %fs:0, %rcx
503 ; X64_ISEL_LINUX-NEXT: movl (%rcx,%rax), %eax
504 ; X64_ISEL_LINUX-NEXT: ret
508 %tmp1 = load i32, i32* @i2
512 attributes #0 = { "indirect-tls-seg-refs" }
513 attributes #1 = { nounwind "indirect-tls-seg-refs" }