1 ; RUN: llc < %s -mtriple=x86_64-linux-gnu -relocation-model=pic | FileCheck %s
3 @x = internal thread_local global i32 0, align 4
4 @y = internal thread_local global i32 0, align 4
6 ; get_x and get_y are here to prevent x and y to be optimized away as 0
11 ; FIXME: This function uses a single thread-local variable,
12 ; so we might want to fall back to general-dynamic here.
14 ; CHECK: leaq x@TLSLD(%rip), %rdi
15 ; CHECK-NEXT: callq __tls_get_addr@PLT
19 define i32* @get_y() {
24 define i32 @f(i32 %i) {
26 %cmp = icmp eq i32 %i, 1
27 br i1 %cmp, label %return, label %if.else
28 ; This bb does not access TLS, so should not call __tls_get_addr.
30 ; CHECK-NOT: __tls_get_addr
35 %0 = load i32, i32* @x, align 4
36 %cmp1 = icmp eq i32 %i, 2
37 br i1 %cmp1, label %if.then2, label %return
38 ; Now we call __tls_get_addr.
40 ; CHECK: leaq x@TLSLD(%rip), %rdi
41 ; CHECK-NEXT: callq __tls_get_addr@PLT
46 %1 = load i32, i32* @y, align 4
47 %add = add nsw i32 %1, %0
49 ; This accesses TLS, but is dominated by the previous block,
50 ; so should not have to call __tls_get_addr again.
52 ; CHECK-NOT: __tls_get_addr
57 %retval.0 = phi i32 [ %add, %if.then2 ], [ 5, %entry ], [ %0, %if.else ]