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