blob: 6c8e45e42d156913b25f787ca9e8e74493aff54b [file] [log] [blame]
Manman Ren19c7bbe2015-12-04 17:40:13 +00001; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s
Quentin Colombeteb61e8e2016-01-06 19:09:26 +00002; TLS function were wrongly model and after fixing that, shrink-wrapping
3; cannot help here. To achieve the expected lowering, we need to playing
4; tricks similar to AArch64 fast TLS calling convention (r255821).
Manman Rened967f32016-01-12 01:08:46 +00005; Applying tricks on x86-64 similar to r255821.
6; RUN: llc < %s -mtriple=x86_64-apple-darwin -enable-shrink-wrap=true | FileCheck %s
Manman Ren53a54c42016-01-16 16:39:46 +00007; RUN: llc < %s -mtriple=x86_64-apple-darwin -O0 | FileCheck %s --check-prefix=CHECK-O0
Manman Ren19c7bbe2015-12-04 17:40:13 +00008%struct.S = type { i8 }
9
10@sg = internal thread_local global %struct.S zeroinitializer, align 1
11@__dso_handle = external global i8
12@__tls_guard = internal thread_local unnamed_addr global i1 false
Manman Ren4fe01bd2016-01-15 19:35:42 +000013@sum1 = internal thread_local global i32 0, align 4
Manman Ren19c7bbe2015-12-04 17:40:13 +000014
15declare void @_ZN1SC1Ev(%struct.S*)
16declare void @_ZN1SD1Ev(%struct.S*)
17declare i32 @_tlv_atexit(void (i8*)*, i8*, i8*)
18
19; Every GPR should be saved - except rdi, rax, and rsp
20; CHECK-LABEL: _ZTW2sg
Manman Rened967f32016-01-12 01:08:46 +000021; CHECK-NOT: pushq %r11
22; CHECK-NOT: pushq %r10
23; CHECK-NOT: pushq %r9
24; CHECK-NOT: pushq %r8
25; CHECK-NOT: pushq %rsi
26; CHECK-NOT: pushq %rdx
27; CHECK-NOT: pushq %rcx
28; CHECK-NOT: pushq %rbx
Manman Ren19c7bbe2015-12-04 17:40:13 +000029; CHECK: callq
30; CHECK: jne
31; CHECK: callq
32; CHECK: tlv_atexit
33; CHECK: callq
Manman Rened967f32016-01-12 01:08:46 +000034; CHECK-NOT: popq %rbx
35; CHECK-NOT: popq %rcx
36; CHECK-NOT: popq %rdx
37; CHECK-NOT: popq %rsi
38; CHECK-NOT: popq %r8
39; CHECK-NOT: popq %r9
40; CHECK-NOT: popq %r10
41; CHECK-NOT: popq %r11
42define cxx_fast_tlscc nonnull %struct.S* @_ZTW2sg() nounwind {
Manman Ren19c7bbe2015-12-04 17:40:13 +000043 %.b.i = load i1, i1* @__tls_guard, align 1
44 br i1 %.b.i, label %__tls_init.exit, label %init.i
45
46init.i:
47 store i1 true, i1* @__tls_guard, align 1
48 tail call void @_ZN1SC1Ev(%struct.S* nonnull @sg) #2
49 %1 = tail call i32 @_tlv_atexit(void (i8*)* nonnull bitcast (void (%struct.S*)* @_ZN1SD1Ev to void (i8*)*), i8* nonnull getelementptr inbounds (%struct.S, %struct.S* @sg, i64 0, i32 0), i8* nonnull @__dso_handle) #2
50 br label %__tls_init.exit
51
52__tls_init.exit:
53 ret %struct.S* @sg
54}
Manman Ren4fe01bd2016-01-15 19:35:42 +000055
56; CHECK-LABEL: _ZTW4sum1
57; CHECK-NOT: pushq %r11
58; CHECK-NOT: pushq %r10
59; CHECK-NOT: pushq %r9
60; CHECK-NOT: pushq %r8
61; CHECK-NOT: pushq %rsi
62; CHECK-NOT: pushq %rdx
63; CHECK-NOT: pushq %rcx
64; CHECK-NOT: pushq %rbx
65; CHECK: callq
66define cxx_fast_tlscc nonnull i32* @_ZTW4sum1() nounwind {
67 ret i32* @sum1
68}
Manman Ren53a54c42016-01-16 16:39:46 +000069
70; Make sure at O0 we don't overwrite RBP.
71; CHECK-O0-LABEL: _ZTW4sum2
72; CHECK-O0: pushq %rbp
73; CHECK-O0: movq %rsp, %rbp
74; CHECK-O0-NOT: movq %r{{.*}}, (%rbp)
75define cxx_fast_tlscc i32* @_ZTW4sum2() #0 {
76 ret i32* @sum1
77}
78
79attributes #0 = { nounwind "no-frame-pointer-elim"="true" }