blob: 70fe501040bf74888d583e7a942411f9e1dee4a0 [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 Ren19c7bbe2015-12-04 17:40:13 +00007%struct.S = type { i8 }
8
9@sg = internal thread_local global %struct.S zeroinitializer, align 1
10@__dso_handle = external global i8
11@__tls_guard = internal thread_local unnamed_addr global i1 false
12
13declare void @_ZN1SC1Ev(%struct.S*)
14declare void @_ZN1SD1Ev(%struct.S*)
15declare i32 @_tlv_atexit(void (i8*)*, i8*, i8*)
16
17; Every GPR should be saved - except rdi, rax, and rsp
18; CHECK-LABEL: _ZTW2sg
Manman Rened967f32016-01-12 01:08:46 +000019; CHECK-NOT: pushq %r11
20; CHECK-NOT: pushq %r10
21; CHECK-NOT: pushq %r9
22; CHECK-NOT: pushq %r8
23; CHECK-NOT: pushq %rsi
24; CHECK-NOT: pushq %rdx
25; CHECK-NOT: pushq %rcx
26; CHECK-NOT: pushq %rbx
Manman Ren19c7bbe2015-12-04 17:40:13 +000027; CHECK: callq
28; CHECK: jne
29; CHECK: callq
30; CHECK: tlv_atexit
31; CHECK: callq
Manman Rened967f32016-01-12 01:08:46 +000032; CHECK-NOT: popq %rbx
33; CHECK-NOT: popq %rcx
34; CHECK-NOT: popq %rdx
35; CHECK-NOT: popq %rsi
36; CHECK-NOT: popq %r8
37; CHECK-NOT: popq %r9
38; CHECK-NOT: popq %r10
39; CHECK-NOT: popq %r11
40define cxx_fast_tlscc nonnull %struct.S* @_ZTW2sg() nounwind {
Manman Ren19c7bbe2015-12-04 17:40:13 +000041 %.b.i = load i1, i1* @__tls_guard, align 1
42 br i1 %.b.i, label %__tls_init.exit, label %init.i
43
44init.i:
45 store i1 true, i1* @__tls_guard, align 1
46 tail call void @_ZN1SC1Ev(%struct.S* nonnull @sg) #2
47 %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
48 br label %__tls_init.exit
49
50__tls_init.exit:
51 ret %struct.S* @sg
52}