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
9
10# CHECK: .Lpcrel_hi0:
11# CHECK: auipc a0, %pcrel_hi(a_symbol)
12# CHECK: addi  a0, a0, %pcrel_lo(.Lpcrel_hi0)
13lla a0, a_symbol
14
15# CHECK: .Lpcrel_hi1:
16# CHECK: auipc a1, %pcrel_hi(another_symbol)
17# CHECK: addi  a1, a1, %pcrel_lo(.Lpcrel_hi1)
18lla a1, another_symbol
19
20# Check that we can load the address of symbols that are spelled like a register
21# CHECK: .Lpcrel_hi2:
22# CHECK: auipc a2, %pcrel_hi(zero)
23# CHECK: addi  a2, a2, %pcrel_lo(.Lpcrel_hi2)
24lla a2, zero
25
26# CHECK: .Lpcrel_hi3:
27# CHECK: auipc a3, %pcrel_hi(ra)
28# CHECK: addi  a3, a3, %pcrel_lo(.Lpcrel_hi3)
29lla a3, ra
30
31# CHECK: .Lpcrel_hi4:
32# CHECK: auipc a4, %pcrel_hi(f1)
33# CHECK: addi  a4, a4, %pcrel_lo(.Lpcrel_hi4)
34lla a4, f1
35
36# CHECK: .Lpcrel_hi5:
37# CHECK: auipc a5, %pcrel_hi(a_symbol+2040)
38# CHECK: addi  a5, a5, %pcrel_lo(.Lpcrel_hi5)
39lla a5, a_symbol + (0xFF << 3)
40
41# CHECK: .Lpcrel_hi6:
42# CHECK-NOPIC: auipc a0, %pcrel_hi(a_symbol)
43# CHECK-NOPIC: addi  a0, a0, %pcrel_lo(.Lpcrel_hi6)
44# CHECK-PIC:      auipc a0, %got_pcrel_hi(a_symbol)
45# CHECK-PIC-RV32: lw    a0, %pcrel_lo(.Lpcrel_hi6)(a0)
46# CHECK-PIC-RV64: ld    a0, %pcrel_lo(.Lpcrel_hi6)(a0)
47la a0, a_symbol
48
49# CHECK: .Lpcrel_hi7:
50# CHECK-NOPIC: auipc a1, %pcrel_hi(another_symbol)
51# CHECK-NOPIC: addi  a1, a1, %pcrel_lo(.Lpcrel_hi7)
52# CHECK-PIC:      auipc a1, %got_pcrel_hi(another_symbol)
53# CHECK-PIC-RV32: lw    a1, %pcrel_lo(.Lpcrel_hi7)(a1)
54# CHECK-PIC-RV64: ld    a1, %pcrel_lo(.Lpcrel_hi7)(a1)
55la a1, another_symbol
56
57# Check that we can load the address of symbols that are spelled like a register
58# CHECK: .Lpcrel_hi8:
59# CHECK-NOPIC: auipc a2, %pcrel_hi(zero)
60# CHECK-NOPIC: addi  a2, a2, %pcrel_lo(.Lpcrel_hi8)
61# CHECK-PIC:      auipc a2, %got_pcrel_hi(zero)
62# CHECK-PIC-RV32: lw    a2, %pcrel_lo(.Lpcrel_hi8)(a2)
63# CHECK-PIC-RV64: ld    a2, %pcrel_lo(.Lpcrel_hi8)(a2)
64la a2, zero
65
66# CHECK: .Lpcrel_hi9:
67# CHECK-NOPIC: auipc a3, %pcrel_hi(ra)
68# CHECK-NOPIC: addi  a3, a3, %pcrel_lo(.Lpcrel_hi9)
69# CHECK-PIC:      auipc a3, %got_pcrel_hi(ra)
70# CHECK-PIC-RV32: lw    a3, %pcrel_lo(.Lpcrel_hi9)(a3)
71# CHECK-PIC-RV64: ld    a3, %pcrel_lo(.Lpcrel_hi9)(a3)
72la a3, ra
73
74# CHECK: .Lpcrel_hi10:
75# CHECK-NOPIC: auipc a4, %pcrel_hi(f1)
76# CHECK-NOPIC: addi  a4, a4, %pcrel_lo(.Lpcrel_hi10)
77# CHECK-PIC:      auipc a4, %got_pcrel_hi(f1)
78# CHECK-PIC-RV32: lw    a4, %pcrel_lo(.Lpcrel_hi10)(a4)
79# CHECK-PIC-RV64: ld    a4, %pcrel_lo(.Lpcrel_hi10)(a4)
80la a4, f1
81
82# CHECK: .Lpcrel_hi11:
83# CHECK: auipc a0, %tls_ie_pcrel_hi(a_symbol)
84# CHECK-RV32: lw    a0, %pcrel_lo(.Lpcrel_hi11)(a0)
85# CHECK-RV64: ld    a0, %pcrel_lo(.Lpcrel_hi11)(a0)
86la.tls.ie a0, a_symbol
87
88# CHECK: .Lpcrel_hi12:
89# CHECK: auipc a1, %tls_ie_pcrel_hi(another_symbol)
90# CHECK-RV32: lw    a1, %pcrel_lo(.Lpcrel_hi12)(a1)
91# CHECK-RV64: ld    a1, %pcrel_lo(.Lpcrel_hi12)(a1)
92la.tls.ie a1, another_symbol
93
94# Check that we can load the address of symbols that are spelled like a register
95# CHECK: .Lpcrel_hi13:
96# CHECK: auipc a2, %tls_ie_pcrel_hi(zero)
97# CHECK-RV32: lw    a2, %pcrel_lo(.Lpcrel_hi13)(a2)
98# CHECK-RV64: ld    a2, %pcrel_lo(.Lpcrel_hi13)(a2)
99la.tls.ie a2, zero
100
101# CHECK: .Lpcrel_hi14:
102# CHECK: auipc a3, %tls_ie_pcrel_hi(ra)
103# CHECK-RV32: lw    a3, %pcrel_lo(.Lpcrel_hi14)(a3)
104# CHECK-RV64: ld    a3, %pcrel_lo(.Lpcrel_hi14)(a3)
105la.tls.ie a3, ra
106
107# CHECK: .Lpcrel_hi15:
108# CHECK: auipc a4, %tls_ie_pcrel_hi(f1)
109# CHECK-RV32: lw    a4, %pcrel_lo(.Lpcrel_hi15)(a4)
110# CHECK-RV64: ld    a4, %pcrel_lo(.Lpcrel_hi15)(a4)
111la.tls.ie a4, f1
112
113# CHECK: .Lpcrel_hi16:
114# CHECK: auipc a0, %tls_gd_pcrel_hi(a_symbol)
115# CHECK: addi  a0, a0, %pcrel_lo(.Lpcrel_hi16)
116la.tls.gd a0, a_symbol
117
118# CHECK: .Lpcrel_hi17:
119# CHECK: auipc a1, %tls_gd_pcrel_hi(another_symbol)
120# CHECK: addi  a1, a1, %pcrel_lo(.Lpcrel_hi17)
121la.tls.gd a1, another_symbol
122
123# Check that we can load the address of symbols that are spelled like a register
124# CHECK: .Lpcrel_hi18:
125# CHECK: auipc a2, %tls_gd_pcrel_hi(zero)
126# CHECK: addi  a2, a2, %pcrel_lo(.Lpcrel_hi18)
127la.tls.gd a2, zero
128
129# CHECK: .Lpcrel_hi19:
130# CHECK: auipc a3, %tls_gd_pcrel_hi(ra)
131# CHECK: addi  a3, a3, %pcrel_lo(.Lpcrel_hi19)
132la.tls.gd a3, ra
133
134# CHECK: .Lpcrel_hi20:
135# CHECK: auipc a4, %tls_gd_pcrel_hi(f1)
136# CHECK: addi  a4, a4, %pcrel_lo(.Lpcrel_hi20)
137la.tls.gd a4, f1
138
139# CHECK: .Lpcrel_hi21:
140# CHECK: auipc a0, %pcrel_hi(a_symbol)
141# CHECK: lb  a0, %pcrel_lo(.Lpcrel_hi21)(a0)
142lb a0, a_symbol
143
144# CHECK: .Lpcrel_hi22:
145# CHECK: auipc a1, %pcrel_hi(a_symbol)
146# CHECK: lh  a1, %pcrel_lo(.Lpcrel_hi22)(a1)
147lh a1, a_symbol
148
149# CHECK: .Lpcrel_hi23:
150# CHECK: auipc a2, %pcrel_hi(a_symbol)
151# CHECK: lhu  a2, %pcrel_lo(.Lpcrel_hi23)(a2)
152lhu a2, a_symbol
153
154# CHECK: .Lpcrel_hi24:
155# CHECK: auipc a3, %pcrel_hi(a_symbol)
156# CHECK: lw  a3, %pcrel_lo(.Lpcrel_hi24)(a3)
157lw a3, a_symbol
158
159# CHECK: .Lpcrel_hi25:
160# CHECK: auipc a4, %pcrel_hi(a_symbol)
161# CHECK: sb  a3, %pcrel_lo(.Lpcrel_hi25)(a4)
162sb a3, a_symbol, a4
163
164# CHECK: .Lpcrel_hi26:
165# CHECK: auipc a4, %pcrel_hi(a_symbol)
166# CHECK: sh  a3, %pcrel_lo(.Lpcrel_hi26)(a4)
167sh a3, a_symbol, a4
168
169# CHECK: .Lpcrel_hi27:
170# CHECK: auipc a4, %pcrel_hi(a_symbol)
171# CHECK: sw  a3, %pcrel_lo(.Lpcrel_hi27)(a4)
172sw a3, a_symbol, a4
173
174# Check that we can load the address of symbols that are spelled like a register
175# CHECK: .Lpcrel_hi28:
176# CHECK: auipc a2, %pcrel_hi(zero)
177# CHECK: lw  a2, %pcrel_lo(.Lpcrel_hi28)(a2)
178lw a2, zero
179
180# CHECK: .Lpcrel_hi29:
181# CHECK: auipc a4, %pcrel_hi(zero)
182# CHECK: sw  a3, %pcrel_lo(.Lpcrel_hi29)(a4)
183sw a3, zero, a4
184
185## Check that a complex expression can be simplified and matched.
186# CHECK: .Lpcrel_hi30:
187# CHECK: auipc a5, %pcrel_hi((255+a_symbol)-4)
188# CHECK: addi  a5, a5, %pcrel_lo(.Lpcrel_hi30)
189lla a5, (0xFF + a_symbol) - 4
190