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=RV32-NOPIC %s
7 ; RUN: llc -mtriple=riscv64 < %s | FileCheck -check-prefix=RV64-NOPIC %s
9 ; Check that TLS symbols are lowered correctly based on the specified
10 ; model. Make sure they're external to avoid them all being optimised to Local
11 ; Exec for the executable.
13 @unspecified = external thread_local global i32
14 @ld = external thread_local(localdynamic) global i32
15 @ie = external thread_local(initialexec) global i32
16 @le = external thread_local(localexec) global i32
21 define ptr @f1() nounwind {
23 ; RV32-PIC: # %bb.0: # %entry
24 ; RV32-PIC-NEXT: addi sp, sp, -16
25 ; RV32-PIC-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
26 ; RV32-PIC-NEXT: .Lpcrel_hi0:
27 ; RV32-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(unspecified)
28 ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi0)
29 ; RV32-PIC-NEXT: call __tls_get_addr@plt
30 ; RV32-PIC-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
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) # 8-byte Folded Spill
38 ; RV64-PIC-NEXT: .Lpcrel_hi0:
39 ; RV64-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(unspecified)
40 ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi0)
41 ; RV64-PIC-NEXT: call __tls_get_addr@plt
42 ; RV64-PIC-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
43 ; RV64-PIC-NEXT: addi sp, sp, 16
46 ; RV32-NOPIC-LABEL: f1:
47 ; RV32-NOPIC: # %bb.0: # %entry
48 ; RV32-NOPIC-NEXT: .Lpcrel_hi0:
49 ; RV32-NOPIC-NEXT: auipc a0, %tls_ie_pcrel_hi(unspecified)
50 ; RV32-NOPIC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi0)(a0)
51 ; RV32-NOPIC-NEXT: add a0, a0, tp
52 ; RV32-NOPIC-NEXT: ret
54 ; RV64-NOPIC-LABEL: f1:
55 ; RV64-NOPIC: # %bb.0: # %entry
56 ; RV64-NOPIC-NEXT: .Lpcrel_hi0:
57 ; RV64-NOPIC-NEXT: auipc a0, %tls_ie_pcrel_hi(unspecified)
58 ; RV64-NOPIC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi0)(a0)
59 ; RV64-NOPIC-NEXT: add a0, a0, tp
60 ; RV64-NOPIC-NEXT: ret
66 ; localdynamic specified
68 define ptr @f2() nounwind {
70 ; RV32-PIC: # %bb.0: # %entry
71 ; RV32-PIC-NEXT: addi sp, sp, -16
72 ; RV32-PIC-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
73 ; RV32-PIC-NEXT: .Lpcrel_hi1:
74 ; RV32-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(ld)
75 ; RV32-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi1)
76 ; RV32-PIC-NEXT: call __tls_get_addr@plt
77 ; RV32-PIC-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
78 ; RV32-PIC-NEXT: addi sp, sp, 16
82 ; RV64-PIC: # %bb.0: # %entry
83 ; RV64-PIC-NEXT: addi sp, sp, -16
84 ; RV64-PIC-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
85 ; RV64-PIC-NEXT: .Lpcrel_hi1:
86 ; RV64-PIC-NEXT: auipc a0, %tls_gd_pcrel_hi(ld)
87 ; RV64-PIC-NEXT: addi a0, a0, %pcrel_lo(.Lpcrel_hi1)
88 ; RV64-PIC-NEXT: call __tls_get_addr@plt
89 ; RV64-PIC-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
90 ; RV64-PIC-NEXT: addi sp, sp, 16
93 ; RV32-NOPIC-LABEL: f2:
94 ; RV32-NOPIC: # %bb.0: # %entry
95 ; RV32-NOPIC-NEXT: .Lpcrel_hi1:
96 ; RV32-NOPIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ld)
97 ; RV32-NOPIC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi1)(a0)
98 ; RV32-NOPIC-NEXT: add a0, a0, tp
99 ; RV32-NOPIC-NEXT: ret
101 ; RV64-NOPIC-LABEL: f2:
102 ; RV64-NOPIC: # %bb.0: # %entry
103 ; RV64-NOPIC-NEXT: .Lpcrel_hi1:
104 ; RV64-NOPIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ld)
105 ; RV64-NOPIC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi1)(a0)
106 ; RV64-NOPIC-NEXT: add a0, a0, tp
107 ; RV64-NOPIC-NEXT: ret
113 ; initialexec specified
115 define ptr @f3() nounwind {
116 ; RV32-PIC-LABEL: f3:
117 ; RV32-PIC: # %bb.0: # %entry
118 ; RV32-PIC-NEXT: .Lpcrel_hi2:
119 ; RV32-PIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
120 ; RV32-PIC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi2)(a0)
121 ; RV32-PIC-NEXT: add a0, a0, tp
124 ; RV64-PIC-LABEL: f3:
125 ; RV64-PIC: # %bb.0: # %entry
126 ; RV64-PIC-NEXT: .Lpcrel_hi2:
127 ; RV64-PIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
128 ; RV64-PIC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi2)(a0)
129 ; RV64-PIC-NEXT: add a0, a0, tp
132 ; RV32-NOPIC-LABEL: f3:
133 ; RV32-NOPIC: # %bb.0: # %entry
134 ; RV32-NOPIC-NEXT: .Lpcrel_hi2:
135 ; RV32-NOPIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
136 ; RV32-NOPIC-NEXT: lw a0, %pcrel_lo(.Lpcrel_hi2)(a0)
137 ; RV32-NOPIC-NEXT: add a0, a0, tp
138 ; RV32-NOPIC-NEXT: ret
140 ; RV64-NOPIC-LABEL: f3:
141 ; RV64-NOPIC: # %bb.0: # %entry
142 ; RV64-NOPIC-NEXT: .Lpcrel_hi2:
143 ; RV64-NOPIC-NEXT: auipc a0, %tls_ie_pcrel_hi(ie)
144 ; RV64-NOPIC-NEXT: ld a0, %pcrel_lo(.Lpcrel_hi2)(a0)
145 ; RV64-NOPIC-NEXT: add a0, a0, tp
146 ; RV64-NOPIC-NEXT: ret
152 ; localexec specified
154 define ptr @f4() nounwind {
155 ; RV32-PIC-LABEL: f4:
156 ; RV32-PIC: # %bb.0: # %entry
157 ; RV32-PIC-NEXT: lui a0, %tprel_hi(le)
158 ; RV32-PIC-NEXT: add a0, a0, tp, %tprel_add(le)
159 ; RV32-PIC-NEXT: addi a0, a0, %tprel_lo(le)
162 ; RV64-PIC-LABEL: f4:
163 ; RV64-PIC: # %bb.0: # %entry
164 ; RV64-PIC-NEXT: lui a0, %tprel_hi(le)
165 ; RV64-PIC-NEXT: add a0, a0, tp, %tprel_add(le)
166 ; RV64-PIC-NEXT: addi a0, a0, %tprel_lo(le)
169 ; RV32-NOPIC-LABEL: f4:
170 ; RV32-NOPIC: # %bb.0: # %entry
171 ; RV32-NOPIC-NEXT: lui a0, %tprel_hi(le)
172 ; RV32-NOPIC-NEXT: add a0, a0, tp, %tprel_add(le)
173 ; RV32-NOPIC-NEXT: addi a0, a0, %tprel_lo(le)
174 ; RV32-NOPIC-NEXT: ret
176 ; RV64-NOPIC-LABEL: f4:
177 ; RV64-NOPIC: # %bb.0: # %entry
178 ; RV64-NOPIC-NEXT: lui a0, %tprel_hi(le)
179 ; RV64-NOPIC-NEXT: add a0, a0, tp, %tprel_add(le)
180 ; RV64-NOPIC-NEXT: addi a0, a0, %tprel_lo(le)
181 ; RV64-NOPIC-NEXT: ret