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
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV64I
7 ; These tests are each targeted at a particular RISC-V ALU instruction. Most
8 ; other files in this folder exercise LLVM IR instructions that don't directly
9 ; match a RISC-V instruction.
11 ; Register-immediate instructions.
13 define i32 @addi(i32 %a) nounwind {
16 ; RV32I-NEXT: addi a0, a0, 1
21 ; RV64I-NEXT: addiw a0, a0, 1
27 define i32 @slti(i32 %a) nounwind {
30 ; RV32I-NEXT: slti a0, a0, 2
35 ; RV64I-NEXT: sext.w a0, a0
36 ; RV64I-NEXT: slti a0, a0, 2
38 %1 = icmp slt i32 %a, 2
39 %2 = zext i1 %1 to i32
43 define i32 @sltiu(i32 %a) nounwind {
46 ; RV32I-NEXT: sltiu a0, a0, 3
51 ; RV64I-NEXT: sext.w a0, a0
52 ; RV64I-NEXT: sltiu a0, a0, 3
54 %1 = icmp ult i32 %a, 3
55 %2 = zext i1 %1 to i32
59 define i32 @xori(i32 %a) nounwind {
62 ; RV32I-NEXT: xori a0, a0, 4
67 ; RV64I-NEXT: xori a0, a0, 4
73 define i32 @ori(i32 %a) nounwind {
76 ; RV32I-NEXT: ori a0, a0, 5
81 ; RV64I-NEXT: ori a0, a0, 5
87 define i32 @andi(i32 %a) nounwind {
90 ; RV32I-NEXT: andi a0, a0, 6
95 ; RV64I-NEXT: andi a0, a0, 6
101 define i32 @slli(i32 %a) nounwind {
104 ; RV32I-NEXT: slli a0, a0, 7
109 ; RV64I-NEXT: slliw a0, a0, 7
115 define i32 @srli(i32 %a) nounwind {
118 ; RV32I-NEXT: srli a0, a0, 8
123 ; RV64I-NEXT: srliw a0, a0, 8
129 ; This makes sure SimplifyDemandedBits doesn't prevent us from matching SRLIW
131 define i32 @srli_demandedbits(i32 %0) {
132 ; RV32I-LABEL: srli_demandedbits:
134 ; RV32I-NEXT: srli a0, a0, 3
135 ; RV32I-NEXT: ori a0, a0, 1
138 ; RV64I-LABEL: srli_demandedbits:
140 ; RV64I-NEXT: srliw a0, a0, 3
141 ; RV64I-NEXT: ori a0, a0, 1
148 define i32 @srai(i32 %a) nounwind {
151 ; RV32I-NEXT: srai a0, a0, 9
156 ; RV64I-NEXT: sraiw a0, a0, 9
162 ; Register-register instructions
164 define i32 @add(i32 %a, i32 %b) nounwind {
167 ; RV32I-NEXT: add a0, a0, a1
172 ; RV64I-NEXT: addw a0, a0, a1
178 define i32 @sub(i32 %a, i32 %b) nounwind {
181 ; RV32I-NEXT: sub a0, a0, a1
186 ; RV64I-NEXT: subw a0, a0, a1
192 define i32 @sub_negative_constant_lhs(i32 %a) nounwind {
193 ; RV32I-LABEL: sub_negative_constant_lhs:
195 ; RV32I-NEXT: li a1, -2
196 ; RV32I-NEXT: sub a0, a1, a0
199 ; RV64I-LABEL: sub_negative_constant_lhs:
201 ; RV64I-NEXT: li a1, -2
202 ; RV64I-NEXT: subw a0, a1, a0
208 define i32 @sll(i32 %a, i32 %b) nounwind {
211 ; RV32I-NEXT: sll a0, a0, a1
216 ; RV64I-NEXT: sllw a0, a0, a1
222 define i32 @sll_negative_constant_lhs(i32 %a) nounwind {
223 ; RV32I-LABEL: sll_negative_constant_lhs:
225 ; RV32I-NEXT: li a1, -1
226 ; RV32I-NEXT: sll a0, a1, a0
229 ; RV64I-LABEL: sll_negative_constant_lhs:
231 ; RV64I-NEXT: li a1, -1
232 ; RV64I-NEXT: sllw a0, a1, a0
238 define i32 @slt(i32 %a, i32 %b) nounwind {
241 ; RV32I-NEXT: slt a0, a0, a1
246 ; RV64I-NEXT: sext.w a1, a1
247 ; RV64I-NEXT: sext.w a0, a0
248 ; RV64I-NEXT: slt a0, a0, a1
250 %1 = icmp slt i32 %a, %b
251 %2 = zext i1 %1 to i32
255 define i32 @sltu(i32 %a, i32 %b) nounwind {
258 ; RV32I-NEXT: sltu a0, a0, a1
263 ; RV64I-NEXT: sext.w a1, a1
264 ; RV64I-NEXT: sext.w a0, a0
265 ; RV64I-NEXT: sltu a0, a0, a1
267 %1 = icmp ult i32 %a, %b
268 %2 = zext i1 %1 to i32
272 define i32 @xor(i32 %a, i32 %b) nounwind {
275 ; RV32I-NEXT: xor a0, a0, a1
280 ; RV64I-NEXT: xor a0, a0, a1
286 define i32 @srl(i32 %a, i32 %b) nounwind {
289 ; RV32I-NEXT: srl a0, a0, a1
294 ; RV64I-NEXT: srlw a0, a0, a1
300 define i32 @srl_negative_constant_lhs(i32 %a) nounwind {
301 ; RV32I-LABEL: srl_negative_constant_lhs:
303 ; RV32I-NEXT: li a1, -1
304 ; RV32I-NEXT: srl a0, a1, a0
307 ; RV64I-LABEL: srl_negative_constant_lhs:
309 ; RV64I-NEXT: li a1, -1
310 ; RV64I-NEXT: srlw a0, a1, a0
316 define i32 @sra(i32 %a, i32 %b) nounwind {
319 ; RV32I-NEXT: sra a0, a0, a1
324 ; RV64I-NEXT: sraw a0, a0, a1
330 define i32 @sra_negative_constant_lhs(i32 %a) nounwind {
331 ; RV32I-LABEL: sra_negative_constant_lhs:
333 ; RV32I-NEXT: lui a1, 524288
334 ; RV32I-NEXT: sra a0, a1, a0
337 ; RV64I-LABEL: sra_negative_constant_lhs:
339 ; RV64I-NEXT: lui a1, 524288
340 ; RV64I-NEXT: sraw a0, a1, a0
342 %1 = ashr i32 2147483648, %a
346 define i32 @or(i32 %a, i32 %b) nounwind {
349 ; RV32I-NEXT: or a0, a0, a1
354 ; RV64I-NEXT: or a0, a0, a1
360 define i32 @and(i32 %a, i32 %b) nounwind {
363 ; RV32I-NEXT: and a0, a0, a1
368 ; RV64I-NEXT: and a0, a0, a1