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 ; Make sure we don't emit instructions to zero extend the shift amount to i64.
136 define i32 @sll_shamt_zext(i32 %a, i32 %b) nounwind {
137 ; RV64I-LABEL: sll_shamt_zext:
139 ; RV64I-NEXT: addi a1, a1, 1
140 ; RV64I-NEXT: sllw a0, a0, a1
142 %shamt = add i32 %b, 1
143 %1 = shl i32 %a, %shamt
147 define i32 @sll_negative_constant_lhs(i32 %a) nounwind {
148 ; RV64I-LABEL: sll_negative_constant_lhs:
150 ; RV64I-NEXT: li a1, -1
151 ; RV64I-NEXT: sllw a0, a1, a0
157 define i32 @slt(i32 %a, i32 %b) nounwind {
160 ; RV64I-NEXT: sext.w a1, a1
161 ; RV64I-NEXT: sext.w a0, a0
162 ; RV64I-NEXT: slt a0, a0, a1
164 %1 = icmp slt i32 %a, %b
165 %2 = zext i1 %1 to i32
169 define i32 @sltu(i32 %a, i32 %b) nounwind {
173 ; RV64I-NEXT: sext.w a1, a1
174 ; RV64I-NEXT: sext.w a0, a0
175 ; RV64I-NEXT: sltu a0, a0, a1
177 %1 = icmp ult i32 %a, %b
178 %2 = zext i1 %1 to i32
182 define i32 @xor(i32 %a, i32 %b) nounwind {
186 ; RV64I-NEXT: xor a0, a0, a1
192 define i32 @srl(i32 %a, i32 %b) nounwind {
196 ; RV64I-NEXT: srlw a0, a0, a1
202 ; Make sure we don't emit instructions to zero extend the shift amount to i64.
203 define i32 @srl_shamt_zext(i32 %a, i32 %b) nounwind {
204 ; RV64I-LABEL: srl_shamt_zext:
206 ; RV64I-NEXT: addi a1, a1, 1
207 ; RV64I-NEXT: srlw a0, a0, a1
209 %shamt = add i32 %b, 1
210 %1 = lshr i32 %a, %shamt
214 define i32 @srl_negative_constant_lhs(i32 %a) nounwind {
216 ; RV64I-LABEL: srl_negative_constant_lhs:
218 ; RV64I-NEXT: li a1, -1
219 ; RV64I-NEXT: srlw a0, a1, a0
225 define i32 @sra(i32 %a, i32 %b) nounwind {
229 ; RV64I-NEXT: sraw a0, a0, a1
235 ; Make sure we don't emit instructions to zero extend the shift amount to i64.
236 define i32 @sra_shamt_zext(i32 %a, i32 %b) nounwind {
237 ; RV64I-LABEL: sra_shamt_zext:
239 ; RV64I-NEXT: addi a1, a1, 1
240 ; RV64I-NEXT: sraw a0, a0, a1
242 %shamt = add i32 %b, 1
243 %1 = ashr i32 %a, %shamt
247 define i32 @sra_negative_constant_lhs(i32 %a) nounwind {
249 ; RV64I-LABEL: sra_negative_constant_lhs:
251 ; RV64I-NEXT: lui a1, 524288
252 ; RV64I-NEXT: sraw a0, a1, a0
254 %1 = ashr i32 2147483648, %a
258 define i32 @or(i32 %a, i32 %b) nounwind {
262 ; RV64I-NEXT: or a0, a0, a1
268 define i32 @and(i32 %a, i32 %b) nounwind {
272 ; RV64I-NEXT: and a0, a0, a1