1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc --mtriple=loongarch32 --relocation-model=pic < %s | FileCheck %s --check-prefix=LA32PIC
3 ; RUN: llc --mtriple=loongarch64 --relocation-model=pic < %s | FileCheck %s --check-prefix=LA64PIC
4 ; RUN: llc --mtriple=loongarch64 --code-model=large --relocation-model=pic < %s | FileCheck %s --check-prefix=LA64LARGEPIC
5 ; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s --check-prefix=LA32NOPIC
6 ; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s --check-prefix=LA64NOPIC
7 ; RUN: llc --mtriple=loongarch64 --code-model=large < %s | FileCheck %s --check-prefix=LA64LARGENOPIC
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
18 ;; No model specified (global dynamic)
20 define ptr @f1() nounwind {
22 ; LA32PIC: # %bb.0: # %entry
23 ; LA32PIC-NEXT: addi.w $sp, $sp, -16
24 ; LA32PIC-NEXT: st.w $ra, $sp, 12 # 4-byte Folded Spill
25 ; LA32PIC-NEXT: pcalau12i $a0, %gd_pc_hi20(unspecified)
26 ; LA32PIC-NEXT: addi.w $a0, $a0, %got_pc_lo12(unspecified)
27 ; LA32PIC-NEXT: bl %plt(__tls_get_addr)
28 ; LA32PIC-NEXT: ld.w $ra, $sp, 12 # 4-byte Folded Reload
29 ; LA32PIC-NEXT: addi.w $sp, $sp, 16
33 ; LA64PIC: # %bb.0: # %entry
34 ; LA64PIC-NEXT: addi.d $sp, $sp, -16
35 ; LA64PIC-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
36 ; LA64PIC-NEXT: pcalau12i $a0, %gd_pc_hi20(unspecified)
37 ; LA64PIC-NEXT: addi.d $a0, $a0, %got_pc_lo12(unspecified)
38 ; LA64PIC-NEXT: bl %plt(__tls_get_addr)
39 ; LA64PIC-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
40 ; LA64PIC-NEXT: addi.d $sp, $sp, 16
43 ; LA64LARGEPIC-LABEL: f1:
44 ; LA64LARGEPIC: # %bb.0: # %entry
45 ; LA64LARGEPIC-NEXT: addi.d $sp, $sp, -16
46 ; LA64LARGEPIC-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
47 ; LA64LARGEPIC-NEXT: pcalau12i $a0, %gd_pc_hi20(unspecified)
48 ; LA64LARGEPIC-NEXT: addi.d $a1, $zero, %got_pc_lo12(unspecified)
49 ; LA64LARGEPIC-NEXT: lu32i.d $a1, %got64_pc_lo20(unspecified)
50 ; LA64LARGEPIC-NEXT: lu52i.d $a1, $a1, %got64_pc_hi12(unspecified)
51 ; LA64LARGEPIC-NEXT: add.d $a0, $a1, $a0
52 ; LA64LARGEPIC-NEXT: pcalau12i $a1, %pc_hi20(__tls_get_addr)
53 ; LA64LARGEPIC-NEXT: addi.d $ra, $zero, %pc_lo12(__tls_get_addr)
54 ; LA64LARGEPIC-NEXT: lu32i.d $ra, %pc64_lo20(__tls_get_addr)
55 ; LA64LARGEPIC-NEXT: lu52i.d $ra, $ra, %pc64_hi12(__tls_get_addr)
56 ; LA64LARGEPIC-NEXT: add.d $ra, $ra, $a1
57 ; LA64LARGEPIC-NEXT: jirl $ra, $ra, 0
58 ; LA64LARGEPIC-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
59 ; LA64LARGEPIC-NEXT: addi.d $sp, $sp, 16
60 ; LA64LARGEPIC-NEXT: ret
62 ; LA32NOPIC-LABEL: f1:
63 ; LA32NOPIC: # %bb.0: # %entry
64 ; LA32NOPIC-NEXT: pcalau12i $a0, %ie_pc_hi20(unspecified)
65 ; LA32NOPIC-NEXT: ld.w $a0, $a0, %ie_pc_lo12(unspecified)
66 ; LA32NOPIC-NEXT: add.w $a0, $a0, $tp
69 ; LA64NOPIC-LABEL: f1:
70 ; LA64NOPIC: # %bb.0: # %entry
71 ; LA64NOPIC-NEXT: pcalau12i $a0, %ie_pc_hi20(unspecified)
72 ; LA64NOPIC-NEXT: ld.d $a0, $a0, %ie_pc_lo12(unspecified)
73 ; LA64NOPIC-NEXT: add.d $a0, $a0, $tp
76 ; LA64LARGENOPIC-LABEL: f1:
77 ; LA64LARGENOPIC: # %bb.0: # %entry
78 ; LA64LARGENOPIC-NEXT: pcalau12i $a0, %ie_pc_hi20(unspecified)
79 ; LA64LARGENOPIC-NEXT: addi.d $a1, $zero, %ie_pc_lo12(unspecified)
80 ; LA64LARGENOPIC-NEXT: lu32i.d $a1, %ie64_pc_lo20(unspecified)
81 ; LA64LARGENOPIC-NEXT: lu52i.d $a1, $a1, %ie64_pc_hi12(unspecified)
82 ; LA64LARGENOPIC-NEXT: ldx.d $a0, $a1, $a0
83 ; LA64LARGENOPIC-NEXT: add.d $a0, $a0, $tp
84 ; LA64LARGENOPIC-NEXT: ret
89 ;; localdynamic specified
91 define ptr @f2() nounwind {
93 ; LA32PIC: # %bb.0: # %entry
94 ; LA32PIC-NEXT: addi.w $sp, $sp, -16
95 ; LA32PIC-NEXT: st.w $ra, $sp, 12 # 4-byte Folded Spill
96 ; LA32PIC-NEXT: pcalau12i $a0, %ld_pc_hi20(ld)
97 ; LA32PIC-NEXT: addi.w $a0, $a0, %got_pc_lo12(ld)
98 ; LA32PIC-NEXT: bl %plt(__tls_get_addr)
99 ; LA32PIC-NEXT: ld.w $ra, $sp, 12 # 4-byte Folded Reload
100 ; LA32PIC-NEXT: addi.w $sp, $sp, 16
104 ; LA64PIC: # %bb.0: # %entry
105 ; LA64PIC-NEXT: addi.d $sp, $sp, -16
106 ; LA64PIC-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
107 ; LA64PIC-NEXT: pcalau12i $a0, %ld_pc_hi20(ld)
108 ; LA64PIC-NEXT: addi.d $a0, $a0, %got_pc_lo12(ld)
109 ; LA64PIC-NEXT: bl %plt(__tls_get_addr)
110 ; LA64PIC-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
111 ; LA64PIC-NEXT: addi.d $sp, $sp, 16
114 ; LA64LARGEPIC-LABEL: f2:
115 ; LA64LARGEPIC: # %bb.0: # %entry
116 ; LA64LARGEPIC-NEXT: addi.d $sp, $sp, -16
117 ; LA64LARGEPIC-NEXT: st.d $ra, $sp, 8 # 8-byte Folded Spill
118 ; LA64LARGEPIC-NEXT: pcalau12i $a0, %ld_pc_hi20(ld)
119 ; LA64LARGEPIC-NEXT: addi.d $a1, $zero, %got_pc_lo12(ld)
120 ; LA64LARGEPIC-NEXT: lu32i.d $a1, %got64_pc_lo20(ld)
121 ; LA64LARGEPIC-NEXT: lu52i.d $a1, $a1, %got64_pc_hi12(ld)
122 ; LA64LARGEPIC-NEXT: add.d $a0, $a1, $a0
123 ; LA64LARGEPIC-NEXT: pcalau12i $a1, %pc_hi20(__tls_get_addr)
124 ; LA64LARGEPIC-NEXT: addi.d $ra, $zero, %pc_lo12(__tls_get_addr)
125 ; LA64LARGEPIC-NEXT: lu32i.d $ra, %pc64_lo20(__tls_get_addr)
126 ; LA64LARGEPIC-NEXT: lu52i.d $ra, $ra, %pc64_hi12(__tls_get_addr)
127 ; LA64LARGEPIC-NEXT: add.d $ra, $ra, $a1
128 ; LA64LARGEPIC-NEXT: jirl $ra, $ra, 0
129 ; LA64LARGEPIC-NEXT: ld.d $ra, $sp, 8 # 8-byte Folded Reload
130 ; LA64LARGEPIC-NEXT: addi.d $sp, $sp, 16
131 ; LA64LARGEPIC-NEXT: ret
133 ; LA32NOPIC-LABEL: f2:
134 ; LA32NOPIC: # %bb.0: # %entry
135 ; LA32NOPIC-NEXT: pcalau12i $a0, %ie_pc_hi20(ld)
136 ; LA32NOPIC-NEXT: ld.w $a0, $a0, %ie_pc_lo12(ld)
137 ; LA32NOPIC-NEXT: add.w $a0, $a0, $tp
138 ; LA32NOPIC-NEXT: ret
140 ; LA64NOPIC-LABEL: f2:
141 ; LA64NOPIC: # %bb.0: # %entry
142 ; LA64NOPIC-NEXT: pcalau12i $a0, %ie_pc_hi20(ld)
143 ; LA64NOPIC-NEXT: ld.d $a0, $a0, %ie_pc_lo12(ld)
144 ; LA64NOPIC-NEXT: add.d $a0, $a0, $tp
145 ; LA64NOPIC-NEXT: ret
147 ; LA64LARGENOPIC-LABEL: f2:
148 ; LA64LARGENOPIC: # %bb.0: # %entry
149 ; LA64LARGENOPIC-NEXT: pcalau12i $a0, %ie_pc_hi20(ld)
150 ; LA64LARGENOPIC-NEXT: addi.d $a1, $zero, %ie_pc_lo12(ld)
151 ; LA64LARGENOPIC-NEXT: lu32i.d $a1, %ie64_pc_lo20(ld)
152 ; LA64LARGENOPIC-NEXT: lu52i.d $a1, $a1, %ie64_pc_hi12(ld)
153 ; LA64LARGENOPIC-NEXT: ldx.d $a0, $a1, $a0
154 ; LA64LARGENOPIC-NEXT: add.d $a0, $a0, $tp
155 ; LA64LARGENOPIC-NEXT: ret
160 ;; initialexec specified
162 define ptr @f3() nounwind {
164 ; LA32PIC: # %bb.0: # %entry
165 ; LA32PIC-NEXT: pcalau12i $a0, %ie_pc_hi20(ie)
166 ; LA32PIC-NEXT: ld.w $a0, $a0, %ie_pc_lo12(ie)
167 ; LA32PIC-NEXT: add.w $a0, $a0, $tp
171 ; LA64PIC: # %bb.0: # %entry
172 ; LA64PIC-NEXT: pcalau12i $a0, %ie_pc_hi20(ie)
173 ; LA64PIC-NEXT: ld.d $a0, $a0, %ie_pc_lo12(ie)
174 ; LA64PIC-NEXT: add.d $a0, $a0, $tp
177 ; LA64LARGEPIC-LABEL: f3:
178 ; LA64LARGEPIC: # %bb.0: # %entry
179 ; LA64LARGEPIC-NEXT: pcalau12i $a0, %ie_pc_hi20(ie)
180 ; LA64LARGEPIC-NEXT: addi.d $a1, $zero, %ie_pc_lo12(ie)
181 ; LA64LARGEPIC-NEXT: lu32i.d $a1, %ie64_pc_lo20(ie)
182 ; LA64LARGEPIC-NEXT: lu52i.d $a1, $a1, %ie64_pc_hi12(ie)
183 ; LA64LARGEPIC-NEXT: ldx.d $a0, $a1, $a0
184 ; LA64LARGEPIC-NEXT: add.d $a0, $a0, $tp
185 ; LA64LARGEPIC-NEXT: ret
187 ; LA32NOPIC-LABEL: f3:
188 ; LA32NOPIC: # %bb.0: # %entry
189 ; LA32NOPIC-NEXT: pcalau12i $a0, %ie_pc_hi20(ie)
190 ; LA32NOPIC-NEXT: ld.w $a0, $a0, %ie_pc_lo12(ie)
191 ; LA32NOPIC-NEXT: add.w $a0, $a0, $tp
192 ; LA32NOPIC-NEXT: ret
194 ; LA64NOPIC-LABEL: f3:
195 ; LA64NOPIC: # %bb.0: # %entry
196 ; LA64NOPIC-NEXT: pcalau12i $a0, %ie_pc_hi20(ie)
197 ; LA64NOPIC-NEXT: ld.d $a0, $a0, %ie_pc_lo12(ie)
198 ; LA64NOPIC-NEXT: add.d $a0, $a0, $tp
199 ; LA64NOPIC-NEXT: ret
201 ; LA64LARGENOPIC-LABEL: f3:
202 ; LA64LARGENOPIC: # %bb.0: # %entry
203 ; LA64LARGENOPIC-NEXT: pcalau12i $a0, %ie_pc_hi20(ie)
204 ; LA64LARGENOPIC-NEXT: addi.d $a1, $zero, %ie_pc_lo12(ie)
205 ; LA64LARGENOPIC-NEXT: lu32i.d $a1, %ie64_pc_lo20(ie)
206 ; LA64LARGENOPIC-NEXT: lu52i.d $a1, $a1, %ie64_pc_hi12(ie)
207 ; LA64LARGENOPIC-NEXT: ldx.d $a0, $a1, $a0
208 ; LA64LARGENOPIC-NEXT: add.d $a0, $a0, $tp
209 ; LA64LARGENOPIC-NEXT: ret
214 ;; localexec specified
216 define ptr @f4() nounwind {
218 ; LA32PIC: # %bb.0: # %entry
219 ; LA32PIC-NEXT: lu12i.w $a0, %le_hi20(le)
220 ; LA32PIC-NEXT: ori $a0, $a0, %le_lo12(le)
221 ; LA32PIC-NEXT: add.w $a0, $a0, $tp
225 ; LA64PIC: # %bb.0: # %entry
226 ; LA64PIC-NEXT: lu12i.w $a0, %le_hi20(le)
227 ; LA64PIC-NEXT: ori $a0, $a0, %le_lo12(le)
228 ; LA64PIC-NEXT: add.d $a0, $a0, $tp
231 ; LA64LARGEPIC-LABEL: f4:
232 ; LA64LARGEPIC: # %bb.0: # %entry
233 ; LA64LARGEPIC-NEXT: lu12i.w $a0, %le_hi20(le)
234 ; LA64LARGEPIC-NEXT: ori $a0, $a0, %le_lo12(le)
235 ; LA64LARGEPIC-NEXT: lu32i.d $a0, %le64_lo20(le)
236 ; LA64LARGEPIC-NEXT: lu52i.d $a0, $a0, %le64_hi12(le)
237 ; LA64LARGEPIC-NEXT: add.d $a0, $a0, $tp
238 ; LA64LARGEPIC-NEXT: ret
240 ; LA32NOPIC-LABEL: f4:
241 ; LA32NOPIC: # %bb.0: # %entry
242 ; LA32NOPIC-NEXT: lu12i.w $a0, %le_hi20(le)
243 ; LA32NOPIC-NEXT: ori $a0, $a0, %le_lo12(le)
244 ; LA32NOPIC-NEXT: add.w $a0, $a0, $tp
245 ; LA32NOPIC-NEXT: ret
247 ; LA64NOPIC-LABEL: f4:
248 ; LA64NOPIC: # %bb.0: # %entry
249 ; LA64NOPIC-NEXT: lu12i.w $a0, %le_hi20(le)
250 ; LA64NOPIC-NEXT: ori $a0, $a0, %le_lo12(le)
251 ; LA64NOPIC-NEXT: add.d $a0, $a0, $tp
252 ; LA64NOPIC-NEXT: ret
254 ; LA64LARGENOPIC-LABEL: f4:
255 ; LA64LARGENOPIC: # %bb.0: # %entry
256 ; LA64LARGENOPIC-NEXT: lu12i.w $a0, %le_hi20(le)
257 ; LA64LARGENOPIC-NEXT: ori $a0, $a0, %le_lo12(le)
258 ; LA64LARGENOPIC-NEXT: lu32i.d $a0, %le64_lo20(le)
259 ; LA64LARGENOPIC-NEXT: lu52i.d $a0, $a0, %le64_hi12(le)
260 ; LA64LARGENOPIC-NEXT: add.d $a0, $a0, $tp
261 ; LA64LARGENOPIC-NEXT: ret