1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV32I
5 ; Check indexed and unindexed, sext, zext and anyext loads
7 define i32 @lb(i8 *%a) nounwind {
10 ; RV32I-NEXT: lb a1, 0(a0)
11 ; RV32I-NEXT: lb a0, 1(a0)
13 %1 = getelementptr i8, i8* %a, i32 1
15 %3 = sext i8 %2 to i32
16 ; the unused load will produce an anyext for selection
17 %4 = load volatile i8, i8* %a
21 define i32 @lh(i16 *%a) nounwind {
24 ; RV32I-NEXT: lh a1, 0(a0)
25 ; RV32I-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 i32
30 ; the unused load will produce an anyext for selection
31 %4 = load volatile i16, i16* %a
35 define i32 @lw(i32 *%a) nounwind {
38 ; RV32I-NEXT: lw a1, 0(a0)
39 ; RV32I-NEXT: lw a0, 12(a0)
41 %1 = getelementptr i32, i32* %a, i32 3
42 %2 = load i32, i32* %1
43 %3 = load volatile i32, i32* %a
47 define i32 @lbu(i8 *%a) nounwind {
50 ; RV32I-NEXT: lbu a1, 0(a0)
51 ; RV32I-NEXT: lbu a0, 4(a0)
52 ; RV32I-NEXT: add a0, a0, a1
54 %1 = getelementptr i8, i8* %a, i32 4
56 %3 = zext i8 %2 to i32
57 %4 = load volatile i8, i8* %a
58 %5 = zext i8 %4 to i32
63 define i32 @lhu(i16 *%a) nounwind {
66 ; RV32I-NEXT: lhu a1, 0(a0)
67 ; RV32I-NEXT: lhu a0, 10(a0)
68 ; RV32I-NEXT: add a0, a0, a1
70 %1 = getelementptr i16, i16* %a, i32 5
71 %2 = load i16, i16* %1
72 %3 = zext i16 %2 to i32
73 %4 = load volatile i16, i16* %a
74 %5 = zext i16 %4 to i32
79 ; Check indexed and unindexed stores
81 define void @sb(i8 *%a, i8 %b) nounwind {
84 ; RV32I-NEXT: sb a1, 6(a0)
85 ; RV32I-NEXT: sb a1, 0(a0)
88 %1 = getelementptr i8, i8* %a, i32 6
93 define void @sh(i16 *%a, i16 %b) nounwind {
96 ; RV32I-NEXT: sh a1, 14(a0)
97 ; RV32I-NEXT: sh a1, 0(a0)
100 %1 = getelementptr i16, i16* %a, i32 7
101 store i16 %b, i16* %1
105 define void @sw(i32 *%a, i32 %b) nounwind {
108 ; RV32I-NEXT: sw a1, 32(a0)
109 ; RV32I-NEXT: sw a1, 0(a0)
111 store i32 %b, i32* %a
112 %1 = getelementptr i32, i32* %a, i32 8
113 store i32 %b, i32* %1
117 ; Check load and store to an i1 location
118 define i32 @load_sext_zext_anyext_i1(i1 *%a) nounwind {
119 ; RV32I-LABEL: load_sext_zext_anyext_i1:
121 ; RV32I-NEXT: lb a1, 0(a0)
122 ; RV32I-NEXT: lbu a1, 1(a0)
123 ; RV32I-NEXT: lbu a0, 2(a0)
124 ; RV32I-NEXT: sub a0, a0, a1
127 %1 = getelementptr i1, i1* %a, i32 1
129 %3 = sext i1 %2 to i32
131 %4 = getelementptr i1, i1* %a, i32 2
133 %6 = zext i1 %5 to i32
135 ; extload i1 (anyext). Produced as the load is unused.
136 %8 = load volatile i1, i1* %a
140 define i16 @load_sext_zext_anyext_i1_i16(i1 *%a) nounwind {
141 ; RV32I-LABEL: load_sext_zext_anyext_i1_i16:
143 ; RV32I-NEXT: lb a1, 0(a0)
144 ; RV32I-NEXT: lbu a1, 1(a0)
145 ; RV32I-NEXT: lbu a0, 2(a0)
146 ; RV32I-NEXT: sub a0, a0, a1
149 %1 = getelementptr i1, i1* %a, i32 1
151 %3 = sext i1 %2 to i16
153 %4 = getelementptr i1, i1* %a, i32 2
155 %6 = zext i1 %5 to i16
157 ; extload i1 (anyext). Produced as the load is unused.
158 %8 = load volatile i1, i1* %a
162 ; Check load and store to a global
165 define i32 @lw_sw_global(i32 %a) nounwind {
166 ; RV32I-LABEL: lw_sw_global:
168 ; RV32I-NEXT: lui a2, %hi(G)
169 ; RV32I-NEXT: lw a1, %lo(G)(a2)
170 ; RV32I-NEXT: sw a0, %lo(G)(a2)
171 ; RV32I-NEXT: addi a2, a2, %lo(G)
172 ; RV32I-NEXT: lw a3, 36(a2)
173 ; RV32I-NEXT: sw a0, 36(a2)
174 ; RV32I-NEXT: mv a0, a1
176 %1 = load volatile i32, i32* @G
177 store i32 %a, i32* @G
178 %2 = getelementptr i32, i32* @G, i32 9
179 %3 = load volatile i32, i32* %2
180 store i32 %a, i32* %2
184 ; Ensure that 1 is added to the high 20 bits if bit 11 of the low part is 1
185 define i32 @lw_sw_constant(i32 %a) nounwind {
186 ; RV32I-LABEL: lw_sw_constant:
188 ; RV32I-NEXT: lui a2, 912092
189 ; RV32I-NEXT: lw a1, -273(a2)
190 ; RV32I-NEXT: sw a0, -273(a2)
191 ; RV32I-NEXT: mv a0, a1
193 %1 = inttoptr i32 3735928559 to i32*
194 %2 = load volatile i32, i32* %1
195 store i32 %a, i32* %1