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 ; TODO: Sign-extension would also work when promoting the operands of
14 ; sltu/sltiu on RV64 and is cheaper than zero-extension (1 instruction vs 2).
16 define i32 @addi(i32 %a) nounwind {
19 ; RV32I-NEXT: addi a0, a0, 1
24 ; RV64I-NEXT: addi a0, a0, 1
30 define i32 @slti(i32 %a) nounwind {
33 ; RV32I-NEXT: slti a0, a0, 2
38 ; RV64I-NEXT: sext.w a0, a0
39 ; RV64I-NEXT: slti a0, a0, 2
41 %1 = icmp slt i32 %a, 2
42 %2 = zext i1 %1 to i32
46 define i32 @sltiu(i32 %a) nounwind {
49 ; RV32I-NEXT: sltiu a0, a0, 3
54 ; RV64I-NEXT: sext.w a0, a0
55 ; RV64I-NEXT: sltiu a0, a0, 3
57 %1 = icmp ult i32 %a, 3
58 %2 = zext i1 %1 to i32
62 define i32 @xori(i32 %a) nounwind {
65 ; RV32I-NEXT: xori a0, a0, 4
70 ; RV64I-NEXT: xori a0, a0, 4
76 define i32 @ori(i32 %a) nounwind {
79 ; RV32I-NEXT: ori a0, a0, 5
84 ; RV64I-NEXT: ori a0, a0, 5
90 define i32 @andi(i32 %a) nounwind {
93 ; RV32I-NEXT: andi a0, a0, 6
98 ; RV64I-NEXT: andi a0, a0, 6
104 define i32 @slli(i32 %a) nounwind {
107 ; RV32I-NEXT: slli a0, a0, 7
112 ; RV64I-NEXT: slli a0, a0, 7
118 define i32 @srli(i32 %a) nounwind {
121 ; RV32I-NEXT: srli a0, a0, 8
126 ; RV64I-NEXT: srliw a0, a0, 8
132 define i32 @srai(i32 %a) nounwind {
135 ; RV32I-NEXT: srai a0, a0, 9
140 ; RV64I-NEXT: sraiw a0, a0, 9
146 ; Register-register instructions
148 define i32 @add(i32 %a, i32 %b) nounwind {
151 ; RV32I-NEXT: add a0, a0, a1
156 ; RV64I-NEXT: addw a0, a0, a1
162 define i32 @sub(i32 %a, i32 %b) nounwind {
165 ; RV32I-NEXT: sub a0, a0, a1
170 ; RV64I-NEXT: subw a0, a0, a1
176 define i32 @sll(i32 %a, i32 %b) nounwind {
179 ; RV32I-NEXT: sll a0, a0, a1
184 ; RV64I-NEXT: sllw a0, a0, a1
190 define i32 @slt(i32 %a, i32 %b) nounwind {
193 ; RV32I-NEXT: slt a0, a0, a1
198 ; RV64I-NEXT: sext.w a1, a1
199 ; RV64I-NEXT: sext.w a0, a0
200 ; RV64I-NEXT: slt a0, a0, a1
202 %1 = icmp slt i32 %a, %b
203 %2 = zext i1 %1 to i32
207 define i32 @sltu(i32 %a, i32 %b) nounwind {
210 ; RV32I-NEXT: sltu a0, a0, a1
215 ; RV64I-NEXT: sext.w a1, a1
216 ; RV64I-NEXT: sext.w a0, a0
217 ; RV64I-NEXT: sltu a0, a0, a1
219 %1 = icmp ult i32 %a, %b
220 %2 = zext i1 %1 to i32
224 define i32 @xor(i32 %a, i32 %b) nounwind {
227 ; RV32I-NEXT: xor a0, a0, a1
232 ; RV64I-NEXT: xor a0, a0, a1
238 define i32 @srl(i32 %a, i32 %b) nounwind {
241 ; RV32I-NEXT: srl a0, a0, a1
246 ; RV64I-NEXT: srlw a0, a0, a1
252 define i32 @sra(i32 %a, i32 %b) nounwind {
255 ; RV32I-NEXT: sra a0, a0, a1
260 ; RV64I-NEXT: sraw a0, a0, a1
266 define i32 @or(i32 %a, i32 %b) nounwind {
269 ; RV32I-NEXT: or a0, a0, a1
274 ; RV64I-NEXT: or a0, a0, a1
280 define i32 @and(i32 %a, i32 %b) nounwind {
283 ; RV32I-NEXT: and a0, a0, a1
288 ; RV64I-NEXT: and a0, a0, a1