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, 1(a0)
11 ; RV32I-NEXT: lb a0, 0(a0)
12 ; RV32I-NEXT: mv a0, a1
14 %1 = getelementptr i8, i8* %a, i32 1
16 %3 = sext i8 %2 to i32
17 ; the unused load will produce an anyext for selection
18 %4 = load volatile i8, i8* %a
22 define i32 @lh(i16 *%a) nounwind {
25 ; RV32I-NEXT: lh a1, 4(a0)
26 ; RV32I-NEXT: lh a0, 0(a0)
27 ; RV32I-NEXT: mv a0, a1
29 %1 = getelementptr i16, i16* %a, i32 2
30 %2 = load i16, i16* %1
31 %3 = sext i16 %2 to i32
32 ; the unused load will produce an anyext for selection
33 %4 = load volatile i16, i16* %a
37 define i32 @lw(i32 *%a) nounwind {
40 ; RV32I-NEXT: lw a1, 12(a0)
41 ; RV32I-NEXT: lw a0, 0(a0)
42 ; RV32I-NEXT: mv a0, a1
44 %1 = getelementptr i32, i32* %a, i32 3
45 %2 = load i32, i32* %1
46 %3 = load volatile i32, i32* %a
50 define i32 @lbu(i8 *%a) nounwind {
53 ; RV32I-NEXT: lbu a1, 4(a0)
54 ; RV32I-NEXT: lbu a0, 0(a0)
55 ; RV32I-NEXT: add a0, a1, a0
57 %1 = getelementptr i8, i8* %a, i32 4
59 %3 = zext i8 %2 to i32
60 %4 = load volatile i8, i8* %a
61 %5 = zext i8 %4 to i32
66 define i32 @lhu(i16 *%a) nounwind {
69 ; RV32I-NEXT: lhu a1, 10(a0)
70 ; RV32I-NEXT: lhu a0, 0(a0)
71 ; RV32I-NEXT: add a0, a1, a0
73 %1 = getelementptr i16, i16* %a, i32 5
74 %2 = load i16, i16* %1
75 %3 = zext i16 %2 to i32
76 %4 = load volatile i16, i16* %a
77 %5 = zext i16 %4 to i32
82 ; Check indexed and unindexed stores
84 define void @sb(i8 *%a, i8 %b) nounwind {
87 ; RV32I-NEXT: sb a1, 0(a0)
88 ; RV32I-NEXT: sb a1, 6(a0)
91 %1 = getelementptr i8, i8* %a, i32 6
96 define void @sh(i16 *%a, i16 %b) nounwind {
99 ; RV32I-NEXT: sh a1, 0(a0)
100 ; RV32I-NEXT: sh a1, 14(a0)
102 store i16 %b, i16* %a
103 %1 = getelementptr i16, i16* %a, i32 7
104 store i16 %b, i16* %1
108 define void @sw(i32 *%a, i32 %b) nounwind {
111 ; RV32I-NEXT: sw a1, 0(a0)
112 ; RV32I-NEXT: sw a1, 32(a0)
114 store i32 %b, i32* %a
115 %1 = getelementptr i32, i32* %a, i32 8
116 store i32 %b, i32* %1
120 ; Check load and store to an i1 location
121 define i32 @load_sext_zext_anyext_i1(i1 *%a) nounwind {
122 ; RV32I-LABEL: load_sext_zext_anyext_i1:
124 ; RV32I-NEXT: lbu a1, 1(a0)
125 ; RV32I-NEXT: lbu a2, 2(a0)
126 ; RV32I-NEXT: lb a0, 0(a0)
127 ; RV32I-NEXT: sub a0, a2, a1
130 %1 = getelementptr i1, i1* %a, i32 1
132 %3 = sext i1 %2 to i32
134 %4 = getelementptr i1, i1* %a, i32 2
136 %6 = zext i1 %5 to i32
138 ; extload i1 (anyext). Produced as the load is unused.
139 %8 = load volatile i1, i1* %a
143 define i16 @load_sext_zext_anyext_i1_i16(i1 *%a) nounwind {
144 ; RV32I-LABEL: load_sext_zext_anyext_i1_i16:
146 ; RV32I-NEXT: lbu a1, 1(a0)
147 ; RV32I-NEXT: lbu a2, 2(a0)
148 ; RV32I-NEXT: lb a0, 0(a0)
149 ; RV32I-NEXT: sub a0, a2, a1
152 %1 = getelementptr i1, i1* %a, i32 1
154 %3 = sext i1 %2 to i16
156 %4 = getelementptr i1, i1* %a, i32 2
158 %6 = zext i1 %5 to i16
160 ; extload i1 (anyext). Produced as the load is unused.
161 %8 = load volatile i1, i1* %a
165 ; Check load and store to a global
168 define i32 @lw_sw_global(i32 %a) nounwind {
169 ; RV32I-LABEL: lw_sw_global:
171 ; RV32I-NEXT: lui a2, %hi(G)
172 ; RV32I-NEXT: lw a1, %lo(G)(a2)
173 ; RV32I-NEXT: sw a0, %lo(G)(a2)
174 ; RV32I-NEXT: addi a2, a2, %lo(G)
175 ; RV32I-NEXT: lw a3, 36(a2)
176 ; RV32I-NEXT: sw a0, 36(a2)
177 ; RV32I-NEXT: mv a0, a1
179 %1 = load volatile i32, i32* @G
180 store i32 %a, i32* @G
181 %2 = getelementptr i32, i32* @G, i32 9
182 %3 = load volatile i32, i32* %2
183 store i32 %a, i32* %2
187 ; Ensure that 1 is added to the high 20 bits if bit 11 of the low part is 1
188 define i32 @lw_sw_constant(i32 %a) nounwind {
189 ; RV32I-LABEL: lw_sw_constant:
191 ; RV32I-NEXT: lui a2, 912092
192 ; RV32I-NEXT: lw a1, -273(a2)
193 ; RV32I-NEXT: sw a0, -273(a2)
194 ; RV32I-NEXT: mv a0, a1
196 %1 = inttoptr i32 3735928559 to i32*
197 %2 = load volatile i32, i32* %1
198 store i32 %a, i32* %1