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, 0(a0)
11 ; RV64I-NEXT: lb a0, 1(a0)
13 %1 = getelementptr i8, i8* %a, i32 1
15 %3 = sext i8 %2 to i64
16 ; the unused load will produce an anyext for selection
17 %4 = load volatile i8, i8* %a
21 define i64 @lh(i16 *%a) nounwind {
24 ; RV64I-NEXT: lh a1, 0(a0)
25 ; RV64I-NEXT: lh a0, 4(a0)
27 %1 = getelementptr i16, i16* %a, i32 2
28 %2 = load i16, i16* %1
29 %3 = sext i16 %2 to i64
30 ; the unused load will produce an anyext for selection
31 %4 = load volatile i16, i16* %a
35 define i64 @lw(i32 *%a) nounwind {
38 ; RV64I-NEXT: lw a1, 0(a0)
39 ; RV64I-NEXT: lw a0, 12(a0)
41 %1 = getelementptr i32, i32* %a, i32 3
42 %2 = load i32, i32* %1
43 %3 = sext i32 %2 to i64
44 ; the unused load will produce an anyext for selection
45 %4 = load volatile i32, i32* %a
49 define i64 @lbu(i8 *%a) nounwind {
52 ; RV64I-NEXT: lbu a1, 0(a0)
53 ; RV64I-NEXT: lbu a0, 4(a0)
54 ; RV64I-NEXT: add a0, a0, a1
56 %1 = getelementptr i8, i8* %a, i32 4
58 %3 = zext i8 %2 to i64
59 %4 = load volatile i8, i8* %a
60 %5 = zext i8 %4 to i64
65 define i64 @lhu(i16 *%a) nounwind {
68 ; RV64I-NEXT: lhu a1, 0(a0)
69 ; RV64I-NEXT: lhu a0, 10(a0)
70 ; RV64I-NEXT: add a0, a0, a1
72 %1 = getelementptr i16, i16* %a, i32 5
73 %2 = load i16, i16* %1
74 %3 = zext i16 %2 to i64
75 %4 = load volatile i16, i16* %a
76 %5 = zext i16 %4 to i64
81 define i64 @lwu(i32 *%a) nounwind {
84 ; RV64I-NEXT: lwu a1, 0(a0)
85 ; RV64I-NEXT: lwu a0, 24(a0)
86 ; RV64I-NEXT: add a0, a0, a1
88 %1 = getelementptr i32, i32* %a, i32 6
89 %2 = load i32, i32* %1
90 %3 = zext i32 %2 to i64
91 %4 = load volatile i32, i32* %a
92 %5 = zext i32 %4 to i64
97 ; Check indexed and unindexed stores
99 define void @sb(i8 *%a, i8 %b) nounwind {
102 ; RV64I-NEXT: sb a1, 7(a0)
103 ; RV64I-NEXT: sb a1, 0(a0)
106 %1 = getelementptr i8, i8* %a, i32 7
111 define void @sh(i16 *%a, i16 %b) nounwind {
114 ; RV64I-NEXT: sh a1, 16(a0)
115 ; RV64I-NEXT: sh a1, 0(a0)
117 store i16 %b, i16* %a
118 %1 = getelementptr i16, i16* %a, i32 8
119 store i16 %b, i16* %1
123 define void @sw(i32 *%a, i32 %b) nounwind {
126 ; RV64I-NEXT: sw a1, 36(a0)
127 ; RV64I-NEXT: sw a1, 0(a0)
129 store i32 %b, i32* %a
130 %1 = getelementptr i32, i32* %a, i32 9
131 store i32 %b, i32* %1
135 ; 64-bit loads and stores
137 define i64 @ld(i64 *%a) nounwind {
140 ; RV64I-NEXT: ld a1, 0(a0)
141 ; RV64I-NEXT: ld a0, 80(a0)
143 %1 = getelementptr i64, i64* %a, i32 10
144 %2 = load i64, i64* %1
145 %3 = load volatile i64, i64* %a
149 define void @sd(i64 *%a, i64 %b) nounwind {
152 ; RV64I-NEXT: sd a1, 88(a0)
153 ; RV64I-NEXT: sd a1, 0(a0)
155 store i64 %b, i64* %a
156 %1 = getelementptr i64, i64* %a, i32 11
157 store i64 %b, i64* %1
161 ; Check load and store to an i1 location
162 define i64 @load_sext_zext_anyext_i1(i1 *%a) nounwind {
163 ; RV64I-LABEL: load_sext_zext_anyext_i1:
165 ; RV64I-NEXT: lb a1, 0(a0)
166 ; RV64I-NEXT: lbu a1, 1(a0)
167 ; RV64I-NEXT: lbu a0, 2(a0)
168 ; RV64I-NEXT: sub a0, a0, a1
171 %1 = getelementptr i1, i1* %a, i32 1
173 %3 = sext i1 %2 to i64
175 %4 = getelementptr i1, i1* %a, i32 2
177 %6 = zext i1 %5 to i64
179 ; extload i1 (anyext). Produced as the load is unused.
180 %8 = load volatile i1, i1* %a
184 define i16 @load_sext_zext_anyext_i1_i16(i1 *%a) nounwind {
185 ; RV64I-LABEL: load_sext_zext_anyext_i1_i16:
187 ; RV64I-NEXT: lb a1, 0(a0)
188 ; RV64I-NEXT: lbu a1, 1(a0)
189 ; RV64I-NEXT: lbu a0, 2(a0)
190 ; RV64I-NEXT: sub a0, a0, a1
193 %1 = getelementptr i1, i1* %a, i32 1
195 %3 = sext i1 %2 to i16
197 %4 = getelementptr i1, i1* %a, i32 2
199 %6 = zext i1 %5 to i16
201 ; extload i1 (anyext). Produced as the load is unused.
202 %8 = load volatile i1, i1* %a
206 ; Check load and store to a global
209 define i64 @ld_sd_global(i64 %a) nounwind {
210 ; RV64I-LABEL: ld_sd_global:
212 ; RV64I-NEXT: lui a2, %hi(G)
213 ; RV64I-NEXT: ld a1, %lo(G)(a2)
214 ; RV64I-NEXT: sd a0, %lo(G)(a2)
215 ; RV64I-NEXT: addi a2, a2, %lo(G)
216 ; RV64I-NEXT: ld a3, 72(a2)
217 ; RV64I-NEXT: sd a0, 72(a2)
218 ; RV64I-NEXT: mv a0, a1
220 %1 = load volatile i64, i64* @G
221 store i64 %a, i64* @G
222 %2 = getelementptr i64, i64* @G, i64 9
223 %3 = load volatile i64, i64* %2
224 store i64 %a, i64* %2