1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefix=RV64I %s
5 ; Check indexed and unindexed, sext, zext and anyext loads
7 define i64 @lb(i8 *%a) nounwind {
10 ; RV64I-NEXT: lb a1, 1(a0)
11 ; RV64I-NEXT: lb a0, 0(a0)
12 ; RV64I-NEXT: mv a0, a1
14 %1 = getelementptr i8, i8* %a, i32 1
16 %3 = sext i8 %2 to i64
17 ; the unused load will produce an anyext for selection
18 %4 = load volatile i8, i8* %a
22 define i64 @lh(i16 *%a) nounwind {
25 ; RV64I-NEXT: lh a1, 4(a0)
26 ; RV64I-NEXT: lh a0, 0(a0)
27 ; RV64I-NEXT: mv a0, a1
29 %1 = getelementptr i16, i16* %a, i32 2
30 %2 = load i16, i16* %1
31 %3 = sext i16 %2 to i64
32 ; the unused load will produce an anyext for selection
33 %4 = load volatile i16, i16* %a
37 define i64 @lw(i32 *%a) nounwind {
40 ; RV64I-NEXT: lw a1, 12(a0)
41 ; RV64I-NEXT: lw a0, 0(a0)
42 ; RV64I-NEXT: mv a0, a1
44 %1 = getelementptr i32, i32* %a, i32 3
45 %2 = load i32, i32* %1
46 %3 = sext i32 %2 to i64
47 ; the unused load will produce an anyext for selection
48 %4 = load volatile i32, i32* %a
52 define i64 @lbu(i8 *%a) nounwind {
55 ; RV64I-NEXT: lbu a1, 4(a0)
56 ; RV64I-NEXT: lbu a0, 0(a0)
57 ; RV64I-NEXT: add a0, a1, a0
59 %1 = getelementptr i8, i8* %a, i32 4
61 %3 = zext i8 %2 to i64
62 %4 = load volatile i8, i8* %a
63 %5 = zext i8 %4 to i64
68 define i64 @lhu(i16 *%a) nounwind {
71 ; RV64I-NEXT: lhu a1, 10(a0)
72 ; RV64I-NEXT: lhu a0, 0(a0)
73 ; RV64I-NEXT: add a0, a1, a0
75 %1 = getelementptr i16, i16* %a, i32 5
76 %2 = load i16, i16* %1
77 %3 = zext i16 %2 to i64
78 %4 = load volatile i16, i16* %a
79 %5 = zext i16 %4 to i64
84 define i64 @lwu(i32 *%a) nounwind {
87 ; RV64I-NEXT: lwu a1, 24(a0)
88 ; RV64I-NEXT: lwu a0, 0(a0)
89 ; RV64I-NEXT: add a0, a1, a0
91 %1 = getelementptr i32, i32* %a, i32 6
92 %2 = load i32, i32* %1
93 %3 = zext i32 %2 to i64
94 %4 = load volatile i32, i32* %a
95 %5 = zext i32 %4 to i64
100 ; Check indexed and unindexed stores
102 define void @sb(i8 *%a, i8 %b) nounwind {
105 ; RV64I-NEXT: sb a1, 0(a0)
106 ; RV64I-NEXT: sb a1, 7(a0)
109 %1 = getelementptr i8, i8* %a, i32 7
114 define void @sh(i16 *%a, i16 %b) nounwind {
117 ; RV64I-NEXT: sh a1, 0(a0)
118 ; RV64I-NEXT: sh a1, 16(a0)
120 store i16 %b, i16* %a
121 %1 = getelementptr i16, i16* %a, i32 8
122 store i16 %b, i16* %1
126 define void @sw(i32 *%a, i32 %b) nounwind {
129 ; RV64I-NEXT: sw a1, 0(a0)
130 ; RV64I-NEXT: sw a1, 36(a0)
132 store i32 %b, i32* %a
133 %1 = getelementptr i32, i32* %a, i32 9
134 store i32 %b, i32* %1
138 ; 64-bit loads and stores
140 define i64 @ld(i64 *%a) nounwind {
143 ; RV64I-NEXT: ld a1, 80(a0)
144 ; RV64I-NEXT: ld a0, 0(a0)
145 ; RV64I-NEXT: mv a0, a1
147 %1 = getelementptr i64, i64* %a, i32 10
148 %2 = load i64, i64* %1
149 %3 = load volatile i64, i64* %a
153 define void @sd(i64 *%a, i64 %b) nounwind {
156 ; RV64I-NEXT: sd a1, 0(a0)
157 ; RV64I-NEXT: sd a1, 88(a0)
159 store i64 %b, i64* %a
160 %1 = getelementptr i64, i64* %a, i32 11
161 store i64 %b, i64* %1
165 ; Check load and store to an i1 location
166 define i64 @load_sext_zext_anyext_i1(i1 *%a) nounwind {
167 ; RV64I-LABEL: load_sext_zext_anyext_i1:
169 ; RV64I-NEXT: lbu a1, 1(a0)
170 ; RV64I-NEXT: lbu a2, 2(a0)
171 ; RV64I-NEXT: lb a0, 0(a0)
172 ; RV64I-NEXT: sub a0, a2, a1
175 %1 = getelementptr i1, i1* %a, i32 1
177 %3 = sext i1 %2 to i64
179 %4 = getelementptr i1, i1* %a, i32 2
181 %6 = zext i1 %5 to i64
183 ; extload i1 (anyext). Produced as the load is unused.
184 %8 = load volatile i1, i1* %a
188 define i16 @load_sext_zext_anyext_i1_i16(i1 *%a) nounwind {
189 ; RV64I-LABEL: load_sext_zext_anyext_i1_i16:
191 ; RV64I-NEXT: lbu a1, 1(a0)
192 ; RV64I-NEXT: lbu a2, 2(a0)
193 ; RV64I-NEXT: lb a0, 0(a0)
194 ; RV64I-NEXT: sub a0, a2, a1
197 %1 = getelementptr i1, i1* %a, i32 1
199 %3 = sext i1 %2 to i16
201 %4 = getelementptr i1, i1* %a, i32 2
203 %6 = zext i1 %5 to i16
205 ; extload i1 (anyext). Produced as the load is unused.
206 %8 = load volatile i1, i1* %a
210 ; Check load and store to a global
213 define i64 @ld_sd_global(i64 %a) nounwind {
214 ; RV64I-LABEL: ld_sd_global:
216 ; RV64I-NEXT: lui a2, %hi(G)
217 ; RV64I-NEXT: ld a1, %lo(G)(a2)
218 ; RV64I-NEXT: sd a0, %lo(G)(a2)
219 ; RV64I-NEXT: addi a2, a2, %lo(G)
220 ; RV64I-NEXT: ld a3, 72(a2)
221 ; RV64I-NEXT: sd a0, 72(a2)
222 ; RV64I-NEXT: mv a0, a1
224 %1 = load volatile i64, i64* @G
225 store i64 %a, i64* @G
226 %2 = getelementptr i64, i64* @G, i64 9
227 %3 = load volatile i64, i64* %2
228 store i64 %a, i64* %2