1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -relocation-model=pic < %s \
3 ; RUN: | FileCheck -check-prefix=RV32-PIC %s
4 ; RUN: llc -mtriple=riscv64 -relocation-model=pic < %s \
5 ; RUN: | FileCheck -check-prefix=RV64-PIC %s
6 ; RUN: llc -mtriple=riscv32 < %s | FileCheck -check-prefix=NOPIC %s
7 ; RUN: llc -mtriple=riscv64 < %s | FileCheck -check-prefix=NOPIC %s
9 ; Check that TLS symbols are lowered correctly based on the specified
12 @unspecified = thread_local global i32 42
13 @ld = thread_local(localdynamic) global i32 42
14 @ie = thread_local(initialexec) global i32 42
15 @le = thread_local(localexec) global i32 42
20 define i32* @f1() nounwind {
22 ; RV32-PIC: # %bb.0: # %entry
23 ; RV32-PIC-NEXT: addi sp, sp, -16
24 ; RV32-PIC-NEXT: sw ra, 12(sp)
25 ; RV32-PIC-NEXT: .LBB0_1: # %entry
26 ; RV32-PIC-NEXT: # Label of block must be emitted
27 ; RV32-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(unspecified)
28 ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.LBB0_1)
29 ; RV32-PIC-NEXT: call __tls_get_addr@plt
30 ; RV32-PIC-NEXT: lw ra, 12(sp)
31 ; RV32-PIC-NEXT: addi sp, sp, 16
35 ; RV64-PIC: # %bb.0: # %entry
36 ; RV64-PIC-NEXT: addi sp, sp, -16
37 ; RV64-PIC-NEXT: sd ra, 8(sp)
38 ; RV64-PIC-NEXT: .LBB0_1: # %entry
39 ; RV64-PIC-NEXT: # Label of block must be emitted
40 ; RV64-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(unspecified)
41 ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.LBB0_1)
42 ; RV64-PIC-NEXT: call __tls_get_addr@plt
43 ; RV64-PIC-NEXT: ld ra, 8(sp)
44 ; RV64-PIC-NEXT: addi sp, sp, 16
48 ; NOPIC: # %bb.0: # %entry
49 ; NOPIC-NEXT: lui a0, %tprel_hi(unspecified)
50 ; NOPIC-NEXT: add a0, a0, tp, %tprel_add(unspecified)
51 ; NOPIC-NEXT: addi a0, a0, %tprel_lo(unspecified)
58 ; localdynamic specified
60 define i32* @f2() nounwind {
62 ; RV32-PIC: # %bb.0: # %entry
63 ; RV32-PIC-NEXT: addi sp, sp, -16
64 ; RV32-PIC-NEXT: sw ra, 12(sp)
65 ; RV32-PIC-NEXT: .LBB1_1: # %entry
66 ; RV32-PIC-NEXT: # Label of block must be emitted
67 ; RV32-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(ld)
68 ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.LBB1_1)
69 ; RV32-PIC-NEXT: call __tls_get_addr@plt
70 ; RV32-PIC-NEXT: lw ra, 12(sp)
71 ; RV32-PIC-NEXT: addi sp, sp, 16
75 ; RV64-PIC: # %bb.0: # %entry
76 ; RV64-PIC-NEXT: addi sp, sp, -16
77 ; RV64-PIC-NEXT: sd ra, 8(sp)
78 ; RV64-PIC-NEXT: .LBB1_1: # %entry
79 ; RV64-PIC-NEXT: # Label of block must be emitted
80 ; RV64-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(ld)
81 ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.LBB1_1)
82 ; RV64-PIC-NEXT: call __tls_get_addr@plt
83 ; RV64-PIC-NEXT: ld ra, 8(sp)
84 ; RV64-PIC-NEXT: addi sp, sp, 16
88 ; NOPIC: # %bb.0: # %entry
89 ; NOPIC-NEXT: lui a0, %tprel_hi(ld)
90 ; NOPIC-NEXT: add a0, a0, tp, %tprel_add(ld)
91 ; NOPIC-NEXT: addi a0, a0, %tprel_lo(ld)
98 ; initialexec specified
100 define i32* @f3() nounwind {
101 ; RV32-PIC-LABEL: f3:
102 ; RV32-PIC: # %bb.0: # %entry
103 ; RV32-PIC-NEXT: .LBB2_1: # %entry
104 ; RV32-PIC-NEXT: # Label of block must be emitted
105 ; RV32-PIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
106 ; RV32-PIC-NEXT: lw a0, %pcrel_lo(.LBB2_1)(a0)
107 ; RV32-PIC-NEXT: add a0, a0, tp
110 ; RV64-PIC-LABEL: f3:
111 ; RV64-PIC: # %bb.0: # %entry
112 ; RV64-PIC-NEXT: .LBB2_1: # %entry
113 ; RV64-PIC-NEXT: # Label of block must be emitted
114 ; RV64-PIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
115 ; RV64-PIC-NEXT: ld a0, %pcrel_lo(.LBB2_1)(a0)
116 ; RV64-PIC-NEXT: add a0, a0, tp
120 ; NOPIC: # %bb.0: # %entry
121 ; NOPIC-NEXT: lui a0, %tprel_hi(ie)
122 ; NOPIC-NEXT: add a0, a0, tp, %tprel_add(ie)
123 ; NOPIC-NEXT: addi a0, a0, %tprel_lo(ie)
130 ; localexec specified
132 define i32* @f4() nounwind {
133 ; RV32-PIC-LABEL: f4:
134 ; RV32-PIC: # %bb.0: # %entry
135 ; RV32-PIC-NEXT: lui a0, %tprel_hi(le)
136 ; RV32-PIC-NEXT: add a0, a0, tp, %tprel_add(le)
137 ; RV32-PIC-NEXT: addi a0, a0, %tprel_lo(le)
140 ; RV64-PIC-LABEL: f4:
141 ; RV64-PIC: # %bb.0: # %entry
142 ; RV64-PIC-NEXT: lui a0, %tprel_hi(le)
143 ; RV64-PIC-NEXT: add a0, a0, tp, %tprel_add(le)
144 ; RV64-PIC-NEXT: addi a0, a0, %tprel_lo(le)
148 ; NOPIC: # %bb.0: # %entry
149 ; NOPIC-NEXT: lui a0, %tprel_hi(le)
150 ; NOPIC-NEXT: add a0, a0, tp, %tprel_add(le)
151 ; NOPIC-NEXT: addi a0, a0, %tprel_lo(le)