1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
3 ; RUN: -riscv-experimental-rv64-legal-i32 | FileCheck %s -check-prefix=RV64I
5 ; These tests are each targeted at a particular RISC-V ALU instruction. Most
6 ; other files in this folder exercise LLVM IR instructions that don't directly
7 ; match a RISC-V instruction.
9 ; Register-immediate instructions.
11 define i32 @addi(i32 %a) nounwind {
14 ; RV64I-NEXT: addiw a0, a0, 1
20 define i32 @slti(i32 %a) nounwind {
23 ; RV64I-NEXT: sext.w a0, a0
24 ; RV64I-NEXT: slti a0, a0, 2
26 %1 = icmp slt i32 %a, 2
27 %2 = zext i1 %1 to i32
31 define i32 @sltiu(i32 %a) nounwind {
34 ; RV64I-NEXT: sext.w a0, a0
35 ; RV64I-NEXT: sltiu a0, a0, 3
37 %1 = icmp ult i32 %a, 3
38 %2 = zext i1 %1 to i32
42 define i32 @xori(i32 %a) nounwind {
45 ; RV64I-NEXT: xori a0, a0, 4
51 define i32 @ori(i32 %a) nounwind {
54 ; RV64I-NEXT: ori a0, a0, 5
60 define i32 @andi(i32 %a) nounwind {
63 ; RV64I-NEXT: andi a0, a0, 6
69 define i32 @slli(i32 %a) nounwind {
72 ; RV64I-NEXT: slliw a0, a0, 7
78 define i32 @srli(i32 %a) nounwind {
81 ; RV64I-NEXT: srliw a0, a0, 8
87 define i32 @srai(i32 %a) nounwind {
90 ; RV64I-NEXT: sraiw a0, a0, 9
96 ; Register-register instructions
98 define i32 @add(i32 %a, i32 %b) nounwind {
101 ; RV64I-NEXT: addw a0, a0, a1
107 define i32 @sub(i32 %a, i32 %b) nounwind {
110 ; RV64I-NEXT: subw a0, a0, a1
116 define i32 @sub_negative_constant_lhs(i32 %a) nounwind {
117 ; RV64I-LABEL: sub_negative_constant_lhs:
119 ; RV64I-NEXT: li a1, -2
120 ; RV64I-NEXT: subw a0, a1, a0
126 define i32 @sll(i32 %a, i32 %b) nounwind {
129 ; RV64I-NEXT: sllw a0, a0, a1
135 define i32 @sll_negative_constant_lhs(i32 %a) nounwind {
136 ; RV64I-LABEL: sll_negative_constant_lhs:
138 ; RV64I-NEXT: li a1, -1
139 ; RV64I-NEXT: sllw a0, a1, a0
145 define i32 @slt(i32 %a, i32 %b) nounwind {
148 ; RV64I-NEXT: sext.w a1, a1
149 ; RV64I-NEXT: sext.w a0, a0
150 ; RV64I-NEXT: slt a0, a0, a1
152 %1 = icmp slt i32 %a, %b
153 %2 = zext i1 %1 to i32
157 define i32 @sltu(i32 %a, i32 %b) nounwind {
161 ; RV64I-NEXT: sext.w a1, a1
162 ; RV64I-NEXT: sext.w a0, a0
163 ; RV64I-NEXT: sltu a0, a0, a1
165 %1 = icmp ult i32 %a, %b
166 %2 = zext i1 %1 to i32
170 define i32 @xor(i32 %a, i32 %b) nounwind {
174 ; RV64I-NEXT: xor a0, a0, a1
180 define i32 @srl(i32 %a, i32 %b) nounwind {
184 ; RV64I-NEXT: srlw a0, a0, a1
190 define i32 @srl_negative_constant_lhs(i32 %a) nounwind {
192 ; RV64I-LABEL: srl_negative_constant_lhs:
194 ; RV64I-NEXT: li a1, -1
195 ; RV64I-NEXT: srlw a0, a1, a0
201 define i32 @sra(i32 %a, i32 %b) nounwind {
205 ; RV64I-NEXT: sraw a0, a0, a1
211 define i32 @sra_negative_constant_lhs(i32 %a) nounwind {
213 ; RV64I-LABEL: sra_negative_constant_lhs:
215 ; RV64I-NEXT: lui a1, 524288
216 ; RV64I-NEXT: sraw a0, a1, a0
218 %1 = ashr i32 2147483648, %a
222 define i32 @or(i32 %a, i32 %b) nounwind {
226 ; RV64I-NEXT: or a0, a0, a1
232 define i32 @and(i32 %a, i32 %b) nounwind {
236 ; RV64I-NEXT: and a0, a0, a1