Skip to content

Commit 60d49fd

Browse files
committed
Add test for TLS handling change
1 parent 8c3cb6b commit 60d49fd

File tree

1 file changed

+186
-0
lines changed

1 file changed

+186
-0
lines changed
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc -o - %s | FileCheck %s --check-prefix=NOPIC
3+
; RUN: llc -o - %s -relocation-model=pic | FileCheck %s --check-prefix=PIC
4+
; RUN: llc -o - %s -relocation-model=pic -enable-tlsdesc | FileCheck %s --check-prefix=TLSDESC
5+
6+
target triple = "x86_64--linux-gnu"
7+
8+
declare void @effect()
9+
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull)
10+
11+
@foo_local = dso_local thread_local(localexec) global i32 0, align 4
12+
13+
define i32 @func_local_tls(i32 %arg0, i32 %arg1) nounwind {
14+
; NOPIC-LABEL: func_local_tls:
15+
; NOPIC: # %bb.0: # %entry
16+
; NOPIC-NEXT: pushq %r14
17+
; NOPIC-NEXT: pushq %rbx
18+
; NOPIC-NEXT: pushq %rax
19+
; NOPIC-NEXT: movl %fs:foo_local@TPOFF, %ebx
20+
; NOPIC-NEXT: testl %edi, %edi
21+
; NOPIC-NEXT: movl %ebx, %eax
22+
; NOPIC-NEXT: jne .LBB0_2
23+
; NOPIC-NEXT: # %bb.1: # %if.then
24+
; NOPIC-NEXT: movq %fs:0, %rax
25+
; NOPIC-NEXT: leaq foo_local@TPOFF(%rax), %r14
26+
; NOPIC-NEXT: callq effect@PLT
27+
; NOPIC-NEXT: movl (%r14), %eax
28+
; NOPIC-NEXT: .LBB0_2: # %if.end
29+
; NOPIC-NEXT: addl %ebx, %eax
30+
; NOPIC-NEXT: addq $8, %rsp
31+
; NOPIC-NEXT: popq %rbx
32+
; NOPIC-NEXT: popq %r14
33+
; NOPIC-NEXT: retq
34+
;
35+
; PIC-LABEL: func_local_tls:
36+
; PIC: # %bb.0: # %entry
37+
; PIC-NEXT: pushq %r14
38+
; PIC-NEXT: pushq %rbx
39+
; PIC-NEXT: pushq %rax
40+
; PIC-NEXT: movl %fs:.Lfoo_local$local@TPOFF, %ebx
41+
; PIC-NEXT: testl %edi, %edi
42+
; PIC-NEXT: movl %ebx, %eax
43+
; PIC-NEXT: jne .LBB0_2
44+
; PIC-NEXT: # %bb.1: # %if.then
45+
; PIC-NEXT: movq %fs:0, %rax
46+
; PIC-NEXT: leaq .Lfoo_local$local@TPOFF(%rax), %r14
47+
; PIC-NEXT: callq effect@PLT
48+
; PIC-NEXT: movl (%r14), %eax
49+
; PIC-NEXT: .LBB0_2: # %if.end
50+
; PIC-NEXT: addl %ebx, %eax
51+
; PIC-NEXT: addq $8, %rsp
52+
; PIC-NEXT: popq %rbx
53+
; PIC-NEXT: popq %r14
54+
; PIC-NEXT: retq
55+
;
56+
; TLSDESC-LABEL: func_local_tls:
57+
; TLSDESC: # %bb.0: # %entry
58+
; TLSDESC-NEXT: pushq %r14
59+
; TLSDESC-NEXT: pushq %rbx
60+
; TLSDESC-NEXT: pushq %rax
61+
; TLSDESC-NEXT: movl %fs:.Lfoo_local$local@TPOFF, %ebx
62+
; TLSDESC-NEXT: testl %edi, %edi
63+
; TLSDESC-NEXT: movl %ebx, %eax
64+
; TLSDESC-NEXT: jne .LBB0_2
65+
; TLSDESC-NEXT: # %bb.1: # %if.then
66+
; TLSDESC-NEXT: movq %fs:0, %rax
67+
; TLSDESC-NEXT: leaq .Lfoo_local$local@TPOFF(%rax), %r14
68+
; TLSDESC-NEXT: callq effect@PLT
69+
; TLSDESC-NEXT: movl (%r14), %eax
70+
; TLSDESC-NEXT: .LBB0_2: # %if.end
71+
; TLSDESC-NEXT: addl %ebx, %eax
72+
; TLSDESC-NEXT: addq $8, %rsp
73+
; TLSDESC-NEXT: popq %rbx
74+
; TLSDESC-NEXT: popq %r14
75+
; TLSDESC-NEXT: retq
76+
entry:
77+
%addr = tail call ptr @llvm.threadlocal.address.p0(ptr @foo_local)
78+
%load0 = load i32, ptr %addr, align 4
79+
%cond = icmp eq i32 %arg0, 0
80+
br i1 %cond, label %if.then, label %if.end
81+
82+
if.then:
83+
tail call void @effect()
84+
%x = add i32 %arg1, 42
85+
%addr1 = getelementptr inbounds i32, ptr %addr, i32 %x
86+
%load1 = load i32, ptr %addr, align 4
87+
br label %if.end
88+
89+
if.end:
90+
%phi = phi i32 [ %load1, %if.then ], [ %load0, %entry ]
91+
%ret = add i32 %phi, %load0
92+
ret i32 %ret
93+
}
94+
95+
@foo_nonlocal = thread_local global i32 0, align 4
96+
97+
define i32 @func_nonlocal_tls(i32 %arg0, i32 %arg1) nounwind {
98+
; NOPIC-LABEL: func_nonlocal_tls:
99+
; NOPIC: # %bb.0: # %entry
100+
; NOPIC-NEXT: pushq %r14
101+
; NOPIC-NEXT: pushq %rbx
102+
; NOPIC-NEXT: pushq %rax
103+
; NOPIC-NEXT: movq foo_nonlocal@GOTTPOFF(%rip), %r14
104+
; NOPIC-NEXT: movl %fs:(%r14), %ebx
105+
; NOPIC-NEXT: testl %edi, %edi
106+
; NOPIC-NEXT: movl %ebx, %eax
107+
; NOPIC-NEXT: jne .LBB1_2
108+
; NOPIC-NEXT: # %bb.1: # %if.then
109+
; NOPIC-NEXT: addq %fs:0, %r14
110+
; NOPIC-NEXT: callq effect@PLT
111+
; NOPIC-NEXT: movl (%r14), %eax
112+
; NOPIC-NEXT: .LBB1_2: # %if.end
113+
; NOPIC-NEXT: addl %ebx, %eax
114+
; NOPIC-NEXT: addq $8, %rsp
115+
; NOPIC-NEXT: popq %rbx
116+
; NOPIC-NEXT: popq %r14
117+
; NOPIC-NEXT: retq
118+
;
119+
; PIC-LABEL: func_nonlocal_tls:
120+
; PIC: # %bb.0: # %entry
121+
; PIC-NEXT: pushq %rbp
122+
; PIC-NEXT: pushq %r14
123+
; PIC-NEXT: pushq %rbx
124+
; PIC-NEXT: movl %edi, %ebp
125+
; PIC-NEXT: data16
126+
; PIC-NEXT: leaq foo_nonlocal@TLSGD(%rip), %rdi
127+
; PIC-NEXT: data16
128+
; PIC-NEXT: data16
129+
; PIC-NEXT: rex64
130+
; PIC-NEXT: callq __tls_get_addr@PLT
131+
; PIC-NEXT: movq %rax, %rbx
132+
; PIC-NEXT: movl (%rax), %r14d
133+
; PIC-NEXT: testl %ebp, %ebp
134+
; PIC-NEXT: movl %r14d, %eax
135+
; PIC-NEXT: jne .LBB1_2
136+
; PIC-NEXT: # %bb.1: # %if.then
137+
; PIC-NEXT: callq effect@PLT
138+
; PIC-NEXT: movl (%rbx), %eax
139+
; PIC-NEXT: .LBB1_2: # %if.end
140+
; PIC-NEXT: addl %r14d, %eax
141+
; PIC-NEXT: popq %rbx
142+
; PIC-NEXT: popq %r14
143+
; PIC-NEXT: popq %rbp
144+
; PIC-NEXT: retq
145+
;
146+
; TLSDESC-LABEL: func_nonlocal_tls:
147+
; TLSDESC: # %bb.0: # %entry
148+
; TLSDESC-NEXT: pushq %r14
149+
; TLSDESC-NEXT: pushq %rbx
150+
; TLSDESC-NEXT: pushq %rax
151+
; TLSDESC-NEXT: leaq foo_nonlocal@tlsdesc(%rip), %rax
152+
; TLSDESC-NEXT: callq *foo_nonlocal@tlscall(%rax)
153+
; TLSDESC-NEXT: movl %fs:(%rax), %ebx
154+
; TLSDESC-NEXT: testl %edi, %edi
155+
; TLSDESC-NEXT: movl %ebx, %ecx
156+
; TLSDESC-NEXT: jne .LBB1_2
157+
; TLSDESC-NEXT: # %bb.1: # %if.then
158+
; TLSDESC-NEXT: addq %fs:0, %rax
159+
; TLSDESC-NEXT: movq %rax, %r14
160+
; TLSDESC-NEXT: callq effect@PLT
161+
; TLSDESC-NEXT: movl (%r14), %ecx
162+
; TLSDESC-NEXT: .LBB1_2: # %if.end
163+
; TLSDESC-NEXT: addl %ebx, %ecx
164+
; TLSDESC-NEXT: movl %ecx, %eax
165+
; TLSDESC-NEXT: addq $8, %rsp
166+
; TLSDESC-NEXT: popq %rbx
167+
; TLSDESC-NEXT: popq %r14
168+
; TLSDESC-NEXT: retq
169+
entry:
170+
%addr = tail call ptr @llvm.threadlocal.address.p0(ptr @foo_nonlocal)
171+
%load0 = load i32, ptr %addr, align 4
172+
%cond = icmp eq i32 %arg0, 0
173+
br i1 %cond, label %if.then, label %if.end
174+
175+
if.then:
176+
tail call void @effect()
177+
%x = add i32 %arg1, 42
178+
%addr1 = getelementptr inbounds i32, ptr %addr, i32 %x
179+
%load1 = load i32, ptr %addr, align 4
180+
br label %if.end
181+
182+
if.end:
183+
%phi = phi i32 [ %load1, %if.then ], [ %load0, %entry ]
184+
%ret = add i32 %phi, %load0
185+
ret i32 %ret
186+
}

0 commit comments

Comments
 (0)