1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefix=RV32I %s
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefix=RV64I %s
7 ; These test how the immediate in an addition is materialized.
9 define i32 @add_positive_low_bound_reject(i32 %a) nounwind {
10 ; RV32I-LABEL: add_positive_low_bound_reject:
12 ; RV32I-NEXT: addi a0, a0, 2047
15 ; RV64I-LABEL: add_positive_low_bound_reject:
17 ; RV64I-NEXT: addiw a0, a0, 2047
23 define i32 @add_positive_low_bound_accept(i32 %a) nounwind {
24 ; RV32I-LABEL: add_positive_low_bound_accept:
26 ; RV32I-NEXT: addi a0, a0, 2047
27 ; RV32I-NEXT: addi a0, a0, 1
30 ; RV64I-LABEL: add_positive_low_bound_accept:
32 ; RV64I-NEXT: addi a0, a0, 2047
33 ; RV64I-NEXT: addiw a0, a0, 1
39 define i32 @add_positive_high_bound_accept(i32 %a) nounwind {
40 ; RV32I-LABEL: add_positive_high_bound_accept:
42 ; RV32I-NEXT: addi a0, a0, 2047
43 ; RV32I-NEXT: addi a0, a0, 2047
46 ; RV64I-LABEL: add_positive_high_bound_accept:
48 ; RV64I-NEXT: addi a0, a0, 2047
49 ; RV64I-NEXT: addiw a0, a0, 2047
55 define i32 @add_positive_high_bound_reject(i32 %a) nounwind {
56 ; RV32I-LABEL: add_positive_high_bound_reject:
58 ; RV32I-NEXT: lui a1, 1
59 ; RV32I-NEXT: addi a1, a1, -1
60 ; RV32I-NEXT: add a0, a0, a1
63 ; RV64I-LABEL: add_positive_high_bound_reject:
65 ; RV64I-NEXT: lui a1, 1
66 ; RV64I-NEXT: addi a1, a1, -1
67 ; RV64I-NEXT: addw a0, a0, a1
73 define i32 @add_negative_high_bound_reject(i32 %a) nounwind {
74 ; RV32I-LABEL: add_negative_high_bound_reject:
76 ; RV32I-NEXT: addi a0, a0, -2048
79 ; RV64I-LABEL: add_negative_high_bound_reject:
81 ; RV64I-NEXT: addiw a0, a0, -2048
83 %1 = add i32 %a, -2048
87 define i32 @add_negative_high_bound_accept(i32 %a) nounwind {
88 ; RV32I-LABEL: add_negative_high_bound_accept:
90 ; RV32I-NEXT: addi a0, a0, -2048
91 ; RV32I-NEXT: addi a0, a0, -1
94 ; RV64I-LABEL: add_negative_high_bound_accept:
96 ; RV64I-NEXT: addi a0, a0, -2048
97 ; RV64I-NEXT: addiw a0, a0, -1
99 %1 = add i32 %a, -2049
103 define i32 @add_negative_low_bound_accept(i32 %a) nounwind {
104 ; RV32I-LABEL: add_negative_low_bound_accept:
106 ; RV32I-NEXT: addi a0, a0, -2048
107 ; RV32I-NEXT: addi a0, a0, -2048
110 ; RV64I-LABEL: add_negative_low_bound_accept:
112 ; RV64I-NEXT: addi a0, a0, -2048
113 ; RV64I-NEXT: addiw a0, a0, -2048
115 %1 = add i32 %a, -4096
119 define i32 @add_negative_low_bound_reject(i32 %a) nounwind {
120 ; RV32I-LABEL: add_negative_low_bound_reject:
122 ; RV32I-NEXT: lui a1, 1048575
123 ; RV32I-NEXT: addi a1, a1, -1
124 ; RV32I-NEXT: add a0, a0, a1
127 ; RV64I-LABEL: add_negative_low_bound_reject:
129 ; RV64I-NEXT: lui a1, 1048575
130 ; RV64I-NEXT: addi a1, a1, -1
131 ; RV64I-NEXT: addw a0, a0, a1
133 %1 = add i32 %a, -4097
137 define i32 @add32_accept(i32 %a) nounwind {
138 ; RV32I-LABEL: add32_accept:
140 ; RV32I-NEXT: addi a0, a0, 2047
141 ; RV32I-NEXT: addi a0, a0, 952
144 ; RV64I-LABEL: add32_accept:
146 ; RV64I-NEXT: addi a0, a0, 2047
147 ; RV64I-NEXT: addiw a0, a0, 952
149 %1 = add i32 %a, 2999
153 define signext i32 @add32_sext_accept(i32 signext %a) nounwind {
154 ; RV32I-LABEL: add32_sext_accept:
156 ; RV32I-NEXT: addi a0, a0, 2047
157 ; RV32I-NEXT: addi a0, a0, 952
160 ; RV64I-LABEL: add32_sext_accept:
162 ; RV64I-NEXT: addi a0, a0, 2047
163 ; RV64I-NEXT: addiw a0, a0, 952
165 %1 = add i32 %a, 2999
169 @gv0 = global i32 0, align 4
170 define signext i32 @add32_sext_reject_on_rv64(i32 signext %a) nounwind {
171 ; RV32I-LABEL: add32_sext_reject_on_rv64:
173 ; RV32I-NEXT: addi a0, a0, 2047
174 ; RV32I-NEXT: addi a0, a0, 953
175 ; RV32I-NEXT: lui a1, %hi(gv0)
176 ; RV32I-NEXT: sw a0, %lo(gv0)(a1)
179 ; RV64I-LABEL: add32_sext_reject_on_rv64:
181 ; RV64I-NEXT: addi a0, a0, 2047
182 ; RV64I-NEXT: addiw a0, a0, 953
183 ; RV64I-NEXT: lui a1, %hi(gv0)
184 ; RV64I-NEXT: sw a0, %lo(gv0)(a1)
186 %b = add nsw i32 %a, 3000
187 store i32 %b, ptr @gv0, align 4
191 define i64 @add64_accept(i64 %a) nounwind {
192 ; RV32I-LABEL: add64_accept:
194 ; RV32I-NEXT: addi a2, a0, 2047
195 ; RV32I-NEXT: addi a2, a2, 952
196 ; RV32I-NEXT: sltu a0, a2, a0
197 ; RV32I-NEXT: add a1, a1, a0
198 ; RV32I-NEXT: mv a0, a2
201 ; RV64I-LABEL: add64_accept:
203 ; RV64I-NEXT: addi a0, a0, 2047
204 ; RV64I-NEXT: addi a0, a0, 952
206 %1 = add i64 %a, 2999
210 @ga = global i32 0, align 4
211 @gb = global i32 0, align 4
212 define void @add32_reject() nounwind {
213 ; RV32I-LABEL: add32_reject:
215 ; RV32I-NEXT: lui a0, %hi(ga)
216 ; RV32I-NEXT: lw a1, %lo(ga)(a0)
217 ; RV32I-NEXT: lui a2, %hi(gb)
218 ; RV32I-NEXT: lw a3, %lo(gb)(a2)
219 ; RV32I-NEXT: lui a4, 1
220 ; RV32I-NEXT: addi a4, a4, -1096
221 ; RV32I-NEXT: add a1, a1, a4
222 ; RV32I-NEXT: add a3, a3, a4
223 ; RV32I-NEXT: sw a1, %lo(ga)(a0)
224 ; RV32I-NEXT: sw a3, %lo(gb)(a2)
227 ; RV64I-LABEL: add32_reject:
229 ; RV64I-NEXT: lui a0, %hi(ga)
230 ; RV64I-NEXT: lw a1, %lo(ga)(a0)
231 ; RV64I-NEXT: lui a2, %hi(gb)
232 ; RV64I-NEXT: lw a3, %lo(gb)(a2)
233 ; RV64I-NEXT: lui a4, 1
234 ; RV64I-NEXT: addi a4, a4, -1096
235 ; RV64I-NEXT: add a1, a1, a4
236 ; RV64I-NEXT: add a3, a3, a4
237 ; RV64I-NEXT: sw a1, %lo(ga)(a0)
238 ; RV64I-NEXT: sw a3, %lo(gb)(a2)
240 %1 = load i32, ptr @ga, align 4
241 %2 = load i32, ptr @gb, align 4
242 %3 = add i32 %1, 3000
243 %4 = add i32 %2, 3000
244 store i32 %3, ptr @ga, align 4
245 store i32 %4, ptr @gb, align 4