Home | History | Annotate | Download | only in X86
      1 ; RUN: llc < %s -march=x86-64 -mtriple=x86_64-linux-gnu -relocation-model=pic | FileCheck  %s
      2 
      3 @x = internal thread_local global i32 0, align 4
      4 @y = internal thread_local global i32 0, align 4
      5 
      6 ; get_x and get_y are here to prevent x and y to be optimized away as 0
      7 
      8 define i32* @get_x() {
      9 entry:
     10   ret i32* @x
     11 ; FIXME: This function uses a single thread-local variable,
     12 ; so we might want to fall back to general-dynamic here.
     13 ; CHECK-LABEL:       get_x:
     14 ; CHECK:       leaq x@TLSLD(%rip), %rdi
     15 ; CHECK-NEXT:  callq __tls_get_addr@PLT
     16 ; CHECK:       x@DTPOFF
     17 }
     18 
     19 define i32* @get_y() {
     20 entry:
     21   ret i32* @y
     22 }
     23 
     24 define i32 @f(i32 %i) {
     25 entry:
     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.
     29 ; CHECK-LABEL:       f:
     30 ; CHECK-NOT:   __tls_get_addr
     31 ; CHECK:       je
     32 
     33 
     34 if.else:
     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.
     39 ; CHECK:       # %if.else
     40 ; CHECK:       leaq x@TLSLD(%rip), %rdi
     41 ; CHECK-NEXT:  callq __tls_get_addr@PLT
     42 ; CHECK:       x@DTPOFF
     43 
     44 
     45 if.then2:
     46   %1 = load i32, i32* @y, align 4
     47   %add = add nsw i32 %1, %0
     48   br label %return
     49 ; This accesses TLS, but is dominated by the previous block,
     50 ; so should not have to call __tls_get_addr again.
     51 ; CHECK:       # %if.then2
     52 ; CHECK-NOT:   __tls_get_addr
     53 ; CHECK:       y@DTPOFF
     54 
     55 
     56 return:
     57   %retval.0 = phi i32 [ %add, %if.then2 ], [ 5, %entry ], [ %0, %if.else ]
     58   ret i32 %retval.0
     59 }
     60