1 # RUN: llvm-mc %s -triple=riscv32 \
2 # RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-NOPIC,CHECK-RV32
3 # RUN: llvm-mc %s -triple=riscv64 \
4 # RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-NOPIC,CHECK-RV64
5 # RUN: llvm-mc %s -triple=riscv32 -position-independent \
6 # RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-PIC,CHECK-RV32,CHECK-PIC-RV32
7 # RUN: llvm-mc %s -triple=riscv64 -position-independent \
8 # RUN: | FileCheck %s --check-prefixes=CHECK,CHECK-PIC,CHECK-RV64,CHECK-PIC-RV64
11 # CHECK: auipc a0, %pcrel_hi(a_symbol)
12 # CHECK: addi a0, a0, %pcrel_lo(.Lpcrel_hi0)
16 # CHECK: auipc a1, %pcrel_hi(another_symbol)
17 # CHECK: addi a1, a1, %pcrel_lo(.Lpcrel_hi1)
18 lla a1
, another_symbol
20 # Check that we can load the address of symbols that are spelled like a register
22 # CHECK: auipc a2, %pcrel_hi(zero)
23 # CHECK: addi a2, a2, %pcrel_lo(.Lpcrel_hi2)
27 # CHECK: auipc a3, %pcrel_hi(ra)
28 # CHECK: addi a3, a3, %pcrel_lo(.Lpcrel_hi3)
32 # CHECK: auipc a4, %pcrel_hi(f1)
33 # CHECK: addi a4, a4, %pcrel_lo(.Lpcrel_hi4)
37 # CHECK: auipc a5, %pcrel_hi(a_symbol+2040)
38 # CHECK: addi a5, a5, %pcrel_lo(.Lpcrel_hi5)
39 lla a5
, a_symbol
+ (0xFF << 3)
42 # CHECK: auipc a0, %got_pcrel_hi(a_symbol)
43 # CHECK-RV32: lw a0, %pcrel_lo(.Lpcrel_hi6)(a0)
44 # CHECK-RV64: ld a0, %pcrel_lo(.Lpcrel_hi6)(a0)
48 # CHECK: auipc a1, %got_pcrel_hi(another_symbol)
49 # CHECK-RV32: lw a1, %pcrel_lo(.Lpcrel_hi7)(a1)
50 # CHECK-RV64: ld a1, %pcrel_lo(.Lpcrel_hi7)(a1)
51 lga a1
, another_symbol
54 # CHECK: auipc a2, %got_pcrel_hi(zero)
55 # CHECK-RV32: lw a2, %pcrel_lo(.Lpcrel_hi8)(a2)
56 # CHECK-RV64: ld a2, %pcrel_lo(.Lpcrel_hi8)(a2)
60 # CHECK: auipc a3, %got_pcrel_hi(ra)
61 # CHECK-RV32: lw a3, %pcrel_lo(.Lpcrel_hi9)(a3)
62 # CHECK-RV64: ld a3, %pcrel_lo(.Lpcrel_hi9)(a3)
65 # CHECK: .Lpcrel_hi10:
66 # CHECK: auipc a4, %got_pcrel_hi(f1)
67 # CHECK-RV32: lw a4, %pcrel_lo(.Lpcrel_hi10)(a4)
68 # CHECK-RV64: ld a4, %pcrel_lo(.Lpcrel_hi10)(a4)
71 # CHECK: .Lpcrel_hi11:
72 # CHECK: auipc a5, %got_pcrel_hi(a_symbol+2040)
73 # CHECK-RV32: lw a5, %pcrel_lo(.Lpcrel_hi11)(a5)
74 # CHECK-RV64: ld a5, %pcrel_lo(.Lpcrel_hi11)(a5)
75 lga a5
, a_symbol
+ (0xFF << 3)
77 # CHECK: .Lpcrel_hi12:
78 # CHECK-NOPIC: auipc a0, %pcrel_hi(a_symbol)
79 # CHECK-NOPIC: addi a0, a0, %pcrel_lo(.Lpcrel_hi12)
80 # CHECK-PIC: auipc a0, %got_pcrel_hi(a_symbol)
81 # CHECK-PIC-RV32: lw a0, %pcrel_lo(.Lpcrel_hi12)(a0)
82 # CHECK-PIC-RV64: ld a0, %pcrel_lo(.Lpcrel_hi12)(a0)
85 # CHECK: .Lpcrel_hi13:
86 # CHECK-NOPIC: auipc a1, %pcrel_hi(another_symbol)
87 # CHECK-NOPIC: addi a1, a1, %pcrel_lo(.Lpcrel_hi13)
88 # CHECK-PIC: auipc a1, %got_pcrel_hi(another_symbol)
89 # CHECK-PIC-RV32: lw a1, %pcrel_lo(.Lpcrel_hi13)(a1)
90 # CHECK-PIC-RV64: ld a1, %pcrel_lo(.Lpcrel_hi13)(a1)
93 # Check that we can load the address of symbols that are spelled like a register
94 # CHECK: .Lpcrel_hi14:
95 # CHECK-NOPIC: auipc a2, %pcrel_hi(zero)
96 # CHECK-NOPIC: addi a2, a2, %pcrel_lo(.Lpcrel_hi14)
97 # CHECK-PIC: auipc a2, %got_pcrel_hi(zero)
98 # CHECK-PIC-RV32: lw a2, %pcrel_lo(.Lpcrel_hi14)(a2)
99 # CHECK-PIC-RV64: ld a2, %pcrel_lo(.Lpcrel_hi14)(a2)
102 # CHECK: .Lpcrel_hi15:
103 # CHECK-NOPIC: auipc a3, %pcrel_hi(ra)
104 # CHECK-NOPIC: addi a3, a3, %pcrel_lo(.Lpcrel_hi15)
105 # CHECK-PIC: auipc a3, %got_pcrel_hi(ra)
106 # CHECK-PIC-RV32: lw a3, %pcrel_lo(.Lpcrel_hi15)(a3)
107 # CHECK-PIC-RV64: ld a3, %pcrel_lo(.Lpcrel_hi15)(a3)
110 # CHECK: .Lpcrel_hi16:
111 # CHECK-NOPIC: auipc a4, %pcrel_hi(f1)
112 # CHECK-NOPIC: addi a4, a4, %pcrel_lo(.Lpcrel_hi16)
113 # CHECK-PIC: auipc a4, %got_pcrel_hi(f1)
114 # CHECK-PIC-RV32: lw a4, %pcrel_lo(.Lpcrel_hi16)(a4)
115 # CHECK-PIC-RV64: ld a4, %pcrel_lo(.Lpcrel_hi16)(a4)
118 # CHECK: .Lpcrel_hi17:
119 # CHECK: auipc a0, %tls_ie_pcrel_hi(a_symbol)
120 # CHECK-RV32: lw a0, %pcrel_lo(.Lpcrel_hi17)(a0)
121 # CHECK-RV64: ld a0, %pcrel_lo(.Lpcrel_hi17)(a0)
122 la.tls.ie a0
, a_symbol
124 # CHECK: .Lpcrel_hi18:
125 # CHECK: auipc a1, %tls_ie_pcrel_hi(another_symbol)
126 # CHECK-RV32: lw a1, %pcrel_lo(.Lpcrel_hi18)(a1)
127 # CHECK-RV64: ld a1, %pcrel_lo(.Lpcrel_hi18)(a1)
128 la.tls.ie a1
, another_symbol
130 # Check that we can load the address of symbols that are spelled like a register
131 # CHECK: .Lpcrel_hi19:
132 # CHECK: auipc a2, %tls_ie_pcrel_hi(zero)
133 # CHECK-RV32: lw a2, %pcrel_lo(.Lpcrel_hi19)(a2)
134 # CHECK-RV64: ld a2, %pcrel_lo(.Lpcrel_hi19)(a2)
137 # CHECK: .Lpcrel_hi20:
138 # CHECK: auipc a3, %tls_ie_pcrel_hi(ra)
139 # CHECK-RV32: lw a3, %pcrel_lo(.Lpcrel_hi20)(a3)
140 # CHECK-RV64: ld a3, %pcrel_lo(.Lpcrel_hi20)(a3)
143 # CHECK: .Lpcrel_hi21:
144 # CHECK: auipc a4, %tls_ie_pcrel_hi(f1)
145 # CHECK-RV32: lw a4, %pcrel_lo(.Lpcrel_hi21)(a4)
146 # CHECK-RV64: ld a4, %pcrel_lo(.Lpcrel_hi21)(a4)
149 # CHECK: .Lpcrel_hi22:
150 # CHECK: auipc a0, %tls_gd_pcrel_hi(a_symbol)
151 # CHECK: addi a0, a0, %pcrel_lo(.Lpcrel_hi22)
152 la.tls.gd a0
, a_symbol
154 # CHECK: .Lpcrel_hi23:
155 # CHECK: auipc a1, %tls_gd_pcrel_hi(another_symbol)
156 # CHECK: addi a1, a1, %pcrel_lo(.Lpcrel_hi23)
157 la.tls.gd a1
, another_symbol
159 # Check that we can load the address of symbols that are spelled like a register
160 # CHECK: .Lpcrel_hi24:
161 # CHECK: auipc a2, %tls_gd_pcrel_hi(zero)
162 # CHECK: addi a2, a2, %pcrel_lo(.Lpcrel_hi24)
165 # CHECK: .Lpcrel_hi25:
166 # CHECK: auipc a3, %tls_gd_pcrel_hi(ra)
167 # CHECK: addi a3, a3, %pcrel_lo(.Lpcrel_hi25)
170 # CHECK: .Lpcrel_hi26:
171 # CHECK: auipc a4, %tls_gd_pcrel_hi(f1)
172 # CHECK: addi a4, a4, %pcrel_lo(.Lpcrel_hi26)
175 # CHECK: .Lpcrel_hi27:
176 # CHECK: auipc a0, %pcrel_hi(a_symbol)
177 # CHECK: lb a0, %pcrel_lo(.Lpcrel_hi27)(a0)
180 # CHECK: .Lpcrel_hi28:
181 # CHECK: auipc a1, %pcrel_hi(a_symbol)
182 # CHECK: lh a1, %pcrel_lo(.Lpcrel_hi28)(a1)
185 # CHECK: .Lpcrel_hi29:
186 # CHECK: auipc a2, %pcrel_hi(a_symbol)
187 # CHECK: lhu a2, %pcrel_lo(.Lpcrel_hi29)(a2)
190 # CHECK: .Lpcrel_hi30:
191 # CHECK: auipc a3, %pcrel_hi(a_symbol)
192 # CHECK: lw a3, %pcrel_lo(.Lpcrel_hi30)(a3)
195 # CHECK: .Lpcrel_hi31:
196 # CHECK: auipc a4, %pcrel_hi(a_symbol)
197 # CHECK: sb a3, %pcrel_lo(.Lpcrel_hi31)(a4)
200 # CHECK: .Lpcrel_hi32:
201 # CHECK: auipc a4, %pcrel_hi(a_symbol)
202 # CHECK: sh a3, %pcrel_lo(.Lpcrel_hi32)(a4)
205 # CHECK: .Lpcrel_hi33:
206 # CHECK: auipc a4, %pcrel_hi(a_symbol)
207 # CHECK: sw a3, %pcrel_lo(.Lpcrel_hi33)(a4)
210 # Check that we can load the address of symbols that are spelled like a register
211 # CHECK: .Lpcrel_hi34:
212 # CHECK: auipc a2, %pcrel_hi(zero)
213 # CHECK: lw a2, %pcrel_lo(.Lpcrel_hi34)(a2)
216 # CHECK: .Lpcrel_hi35:
217 # CHECK: auipc a4, %pcrel_hi(zero)
218 # CHECK: sw a3, %pcrel_lo(.Lpcrel_hi35)(a4)
221 ## Check that a complex expression can be simplified and matched.
222 # CHECK: .Lpcrel_hi36:
223 # CHECK: auipc a5, %pcrel_hi((255+a_symbol)-4)
224 # CHECK: addi a5, a5, %pcrel_lo(.Lpcrel_hi36)
225 lla a5
, (0xFF + a_symbol
) - 4
227 ## Check that we don't double-parse a top-level minus.
228 # CHECK: .Lpcrel_hi37:
229 # CHECK: auipc a5, %pcrel_hi(a_symbol-4)
230 # CHECK: addi a5, a5, %pcrel_lo(.Lpcrel_hi37)