xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/cxx_tlscc64.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -verify-machineinstrs < %s -mtriple=x86_64-apple-darwin | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; TLS function were wrongly model and after fixing that, shrink-wrapping
3*9880d681SAndroid Build Coastguard Worker; cannot help here. To achieve the expected lowering, we need to playing
4*9880d681SAndroid Build Coastguard Worker; tricks similar to AArch64 fast TLS calling convention (r255821).
5*9880d681SAndroid Build Coastguard Worker; Applying tricks on x86-64 similar to r255821.
6*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=x86_64-apple-darwin -enable-shrink-wrap=true | FileCheck %s
7*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mtriple=x86_64-apple-darwin -O0 | FileCheck %s --check-prefix=CHECK-O0
8*9880d681SAndroid Build Coastguard Worker%struct.S = type { i8 }
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Worker@sg = internal thread_local global %struct.S zeroinitializer, align 1
11*9880d681SAndroid Build Coastguard Worker@__dso_handle = external global i8
12*9880d681SAndroid Build Coastguard Worker@__tls_guard = internal thread_local unnamed_addr global i1 false
13*9880d681SAndroid Build Coastguard Worker@sum1 = internal thread_local global i32 0, align 4
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Workerdeclare void @_ZN1SC1Ev(%struct.S*)
16*9880d681SAndroid Build Coastguard Workerdeclare void @_ZN1SD1Ev(%struct.S*)
17*9880d681SAndroid Build Coastguard Workerdeclare i32 @_tlv_atexit(void (i8*)*, i8*, i8*)
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker; Every GPR should be saved - except rdi, rax, and rsp
20*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _ZTW2sg
21*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %r11
22*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %r10
23*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %r9
24*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %r8
25*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %rsi
26*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %rdx
27*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %rcx
28*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %rbx
29*9880d681SAndroid Build Coastguard Worker; CHECK: callq
30*9880d681SAndroid Build Coastguard Worker; CHECK: jne
31*9880d681SAndroid Build Coastguard Worker; CHECK: callq
32*9880d681SAndroid Build Coastguard Worker; CHECK: tlv_atexit
33*9880d681SAndroid Build Coastguard Worker; CHECK: callq
34*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: popq %rbx
35*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: popq %rcx
36*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: popq %rdx
37*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: popq %rsi
38*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: popq %r8
39*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: popq %r9
40*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: popq %r10
41*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: popq %r11
42*9880d681SAndroid Build Coastguard Worker
43*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: _ZTW2sg
44*9880d681SAndroid Build Coastguard Worker; CHECK-O0: pushq %r11
45*9880d681SAndroid Build Coastguard Worker; CHECK-O0: pushq %r10
46*9880d681SAndroid Build Coastguard Worker; CHECK-O0: pushq %r9
47*9880d681SAndroid Build Coastguard Worker; CHECK-O0: pushq %r8
48*9880d681SAndroid Build Coastguard Worker; CHECK-O0: pushq %rsi
49*9880d681SAndroid Build Coastguard Worker; CHECK-O0: pushq %rdx
50*9880d681SAndroid Build Coastguard Worker; CHECK-O0: pushq %rcx
51*9880d681SAndroid Build Coastguard Worker; CHECK-O0: callq
52*9880d681SAndroid Build Coastguard Worker; CHECK-O0: jne
53*9880d681SAndroid Build Coastguard Worker; CHECK-O0: callq
54*9880d681SAndroid Build Coastguard Worker; CHECK-O0: tlv_atexit
55*9880d681SAndroid Build Coastguard Worker; CHECK-O0: callq
56*9880d681SAndroid Build Coastguard Worker; CHECK-O0: popq %rcx
57*9880d681SAndroid Build Coastguard Worker; CHECK-O0: popq %rdx
58*9880d681SAndroid Build Coastguard Worker; CHECK-O0: popq %rsi
59*9880d681SAndroid Build Coastguard Worker; CHECK-O0: popq %r8
60*9880d681SAndroid Build Coastguard Worker; CHECK-O0: popq %r9
61*9880d681SAndroid Build Coastguard Worker; CHECK-O0: popq %r10
62*9880d681SAndroid Build Coastguard Worker; CHECK-O0: popq %r11
63*9880d681SAndroid Build Coastguard Workerdefine cxx_fast_tlscc nonnull %struct.S* @_ZTW2sg() nounwind {
64*9880d681SAndroid Build Coastguard Worker  %.b.i = load i1, i1* @__tls_guard, align 1
65*9880d681SAndroid Build Coastguard Worker  br i1 %.b.i, label %__tls_init.exit, label %init.i
66*9880d681SAndroid Build Coastguard Worker
67*9880d681SAndroid Build Coastguard Workerinit.i:
68*9880d681SAndroid Build Coastguard Worker  store i1 true, i1* @__tls_guard, align 1
69*9880d681SAndroid Build Coastguard Worker  tail call void @_ZN1SC1Ev(%struct.S* nonnull @sg) #2
70*9880d681SAndroid Build Coastguard Worker  %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
71*9880d681SAndroid Build Coastguard Worker  br label %__tls_init.exit
72*9880d681SAndroid Build Coastguard Worker
73*9880d681SAndroid Build Coastguard Worker__tls_init.exit:
74*9880d681SAndroid Build Coastguard Worker  ret %struct.S* @sg
75*9880d681SAndroid Build Coastguard Worker}
76*9880d681SAndroid Build Coastguard Worker
77*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: _ZTW4sum1
78*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %r11
79*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %r10
80*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %r9
81*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %r8
82*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %rsi
83*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %rdx
84*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %rcx
85*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %rbx
86*9880d681SAndroid Build Coastguard Worker; CHECK: callq
87*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: _ZTW4sum1
88*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %r11
89*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %r10
90*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %r9
91*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %r8
92*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %rsi
93*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %rdx
94*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %rcx
95*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %rbx
96*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: movq %r11
97*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: movq %r10
98*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: movq %r9
99*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: movq %r8
100*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: movq %rsi
101*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: movq %rdx
102*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: movq %rcx
103*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: movq %rbx
104*9880d681SAndroid Build Coastguard Worker; CHECK-O0: callq
105*9880d681SAndroid Build Coastguard Workerdefine cxx_fast_tlscc nonnull i32* @_ZTW4sum1() nounwind {
106*9880d681SAndroid Build Coastguard Worker  ret i32* @sum1
107*9880d681SAndroid Build Coastguard Worker}
108*9880d681SAndroid Build Coastguard Worker
109*9880d681SAndroid Build Coastguard Worker; Make sure at O0 we don't overwrite RBP.
110*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: _ZTW4sum2
111*9880d681SAndroid Build Coastguard Worker; CHECK-O0: pushq %rbp
112*9880d681SAndroid Build Coastguard Worker; CHECK-O0: movq %rsp, %rbp
113*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: movq %r{{.*}}, (%rbp)
114*9880d681SAndroid Build Coastguard Workerdefine cxx_fast_tlscc i32* @_ZTW4sum2() #0 {
115*9880d681SAndroid Build Coastguard Worker  ret i32* @sum1
116*9880d681SAndroid Build Coastguard Worker}
117*9880d681SAndroid Build Coastguard Worker
118*9880d681SAndroid Build Coastguard Worker; Make sure at O0, we don't generate spilling/reloading of the CSRs.
119*9880d681SAndroid Build Coastguard Worker; CHECK-O0-LABEL: tls_test2
120*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %r11
121*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %r10
122*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %r9
123*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %r8
124*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %rsi
125*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: pushq %rdx
126*9880d681SAndroid Build Coastguard Worker; CHECK-O0: callq {{.*}}tls_helper
127*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: popq %rdx
128*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: popq %rsi
129*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: popq %r8
130*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: popq %r9
131*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: popq %r10
132*9880d681SAndroid Build Coastguard Worker; CHECK-O0-NOT: popq %r11
133*9880d681SAndroid Build Coastguard Worker; CHECK-O0: ret
134*9880d681SAndroid Build Coastguard Worker%class.C = type { i32 }
135*9880d681SAndroid Build Coastguard Worker@tC = internal thread_local global %class.C zeroinitializer, align 4
136*9880d681SAndroid Build Coastguard Workerdeclare cxx_fast_tlscc void @tls_helper()
137*9880d681SAndroid Build Coastguard Workerdefine cxx_fast_tlscc %class.C* @tls_test2() #1 {
138*9880d681SAndroid Build Coastguard Worker  call cxx_fast_tlscc void @tls_helper()
139*9880d681SAndroid Build Coastguard Worker  ret %class.C* @tC
140*9880d681SAndroid Build Coastguard Worker}
141*9880d681SAndroid Build Coastguard Worker
142*9880d681SAndroid Build Coastguard Worker; Make sure we do not allow tail call when caller and callee have different
143*9880d681SAndroid Build Coastguard Worker; calling conventions.
144*9880d681SAndroid Build Coastguard Workerdeclare %class.C* @_ZN1CD1Ev(%class.C* readnone returned %this)
145*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: tls_test
146*9880d681SAndroid Build Coastguard Worker; CHECK: callq {{.*}}tlv_atexit
147*9880d681SAndroid Build Coastguard Workerdefine cxx_fast_tlscc void @tls_test() {
148*9880d681SAndroid Build Coastguard Workerentry:
149*9880d681SAndroid Build Coastguard Worker  store i32 0, i32* getelementptr inbounds (%class.C, %class.C* @tC, i64 0, i32 0), align 4
150*9880d681SAndroid Build Coastguard Worker  %0 = tail call i32 @_tlv_atexit(void (i8*)* bitcast (%class.C* (%class.C*)* @_ZN1CD1Ev to void (i8*)*), i8* bitcast (%class.C* @tC to i8*), i8* nonnull @__dso_handle) #1
151*9880d681SAndroid Build Coastguard Worker  ret void
152*9880d681SAndroid Build Coastguard Worker}
153*9880d681SAndroid Build Coastguard Worker
154*9880d681SAndroid Build Coastguard Worker@ssp_var = internal thread_local global i8 0, align 1
155*9880d681SAndroid Build Coastguard Worker
156*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_ssp
157*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %r11
158*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %r10
159*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %r9
160*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %r8
161*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %rsi
162*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %rdx
163*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %rcx
164*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: pushq %rbx
165*9880d681SAndroid Build Coastguard Worker; CHECK: callq
166*9880d681SAndroid Build Coastguard Workerdefine cxx_fast_tlscc nonnull i8* @test_ssp() #2 {
167*9880d681SAndroid Build Coastguard Worker  ret i8* @ssp_var
168*9880d681SAndroid Build Coastguard Worker}
169*9880d681SAndroid Build Coastguard Workerattributes #0 = { nounwind "no-frame-pointer-elim"="true" }
170*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind }
171*9880d681SAndroid Build Coastguard Workerattributes #2 = { nounwind sspreq }
172