Index: test/CodeGen/RISCV/alu64.ll =================================================================== --- /dev/null +++ test/CodeGen/RISCV/alu64.ll @@ -0,0 +1,186 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \ +; RUN: | FileCheck %s -check-prefix=RV64I + +; These tests are each targeted at a particular RISC-V ALU instruction. Other +; files in this folder exercise LLVM IR instructions that don't directly match a +; RISC-V instruction + +; Register-immediate instructions + +define i64 @addi(i64 %a) nounwind { +; RV64I-LABEL: addi: +; RV64I: # %bb.0: +; RV64I-NEXT: addi a0, a0, 1 +; RV64I-NEXT: ret + %1 = add i64 %a, 1 + ret i64 %1 +} + +define i64 @slti(i64 %a) nounwind { +; RV64I-LABEL: slti: +; RV64I: # %bb.0: +; RV64I-NEXT: slti a0, a0, 2 +; RV64I-NEXT: ret + %1 = icmp slt i64 %a, 2 + %2 = zext i1 %1 to i64 + ret i64 %2 +} + +define i64 @sltiu(i64 %a) nounwind { +; RV64I-LABEL: sltiu: +; RV64I: # %bb.0: +; RV64I-NEXT: sltiu a0, a0, 3 +; RV64I-NEXT: ret + %1 = icmp ult i64 %a, 3 + %2 = zext i1 %1 to i64 + ret i64 %2 +} + +define i64 @xori(i64 %a) nounwind { +; RV64I-LABEL: xori: +; RV64I: # %bb.0: +; RV64I-NEXT: xori a0, a0, 4 +; RV64I-NEXT: ret + %1 = xor i64 %a, 4 + ret i64 %1 +} + +define i64 @ori(i64 %a) nounwind { +; RV64I-LABEL: ori: +; RV64I: # %bb.0: +; RV64I-NEXT: ori a0, a0, 5 +; RV64I-NEXT: ret + %1 = or i64 %a, 5 + ret i64 %1 +} + +define i64 @andi(i64 %a) nounwind { +; RV64I-LABEL: andi: +; RV64I: # %bb.0: +; RV64I-NEXT: andi a0, a0, 6 +; RV64I-NEXT: ret + %1 = and i64 %a, 6 + ret i64 %1 +} + +define i64 @slli(i64 %a) nounwind { +; RV64I-LABEL: slli: +; RV64I: # %bb.0: +; RV64I-NEXT: slli a0, a0, 7 +; RV64I-NEXT: ret + %1 = shl i64 %a, 7 + ret i64 %1 +} + +define i64 @srli(i64 %a) nounwind { +; RV64I-LABEL: srli: +; RV64I: # %bb.0: +; RV64I-NEXT: srli a0, a0, 8 +; RV64I-NEXT: ret + %1 = lshr i64 %a, 8 + ret i64 %1 +} + +define i64 @srai(i64 %a) nounwind { +; RV64I-LABEL: srai: +; RV64I: # %bb.0: +; RV64I-NEXT: srai a0, a0, 9 +; RV64I-NEXT: ret + %1 = ashr i64 %a, 9 + ret i64 %1 +} + +; Register-register instructions + +define i64 @add(i64 %a, i64 %b) nounwind { +; RV64I-LABEL: add: +; RV64I: # %bb.0: +; RV64I-NEXT: add a0, a0, a1 +; RV64I-NEXT: ret + %1 = add i64 %a, %b + ret i64 %1 +} + +define i64 @sub(i64 %a, i64 %b) nounwind { +; RV64I-LABEL: sub: +; RV64I: # %bb.0: +; RV64I-NEXT: sub a0, a0, a1 +; RV64I-NEXT: ret + %1 = sub i64 %a, %b + ret i64 %1 +} + +define i64 @sll(i64 %a, i64 %b) nounwind { +; RV64I-LABEL: sll: +; RV64I: # %bb.0: +; RV64I-NEXT: sll a0, a0, a1 +; RV64I-NEXT: ret + %1 = shl i64 %a, %b + ret i64 %1 +} + +define i64 @slt(i64 %a, i64 %b) nounwind { +; RV64I-LABEL: slt: +; RV64I: # %bb.0: +; RV64I-NEXT: slt a0, a0, a1 +; RV64I-NEXT: ret + %1 = icmp slt i64 %a, %b + %2 = zext i1 %1 to i64 + ret i64 %2 +} + +define i64 @sltu(i64 %a, i64 %b) nounwind { +; RV64I-LABEL: sltu: +; RV64I: # %bb.0: +; RV64I-NEXT: sltu a0, a0, a1 +; RV64I-NEXT: ret + %1 = icmp ult i64 %a, %b + %2 = zext i1 %1 to i64 + ret i64 %2 +} + +define i64 @xor(i64 %a, i64 %b) nounwind { +; RV64I-LABEL: xor: +; RV64I: # %bb.0: +; RV64I-NEXT: xor a0, a0, a1 +; RV64I-NEXT: ret + %1 = xor i64 %a, %b + ret i64 %1 +} + +define i64 @srl(i64 %a, i64 %b) nounwind { +; RV64I-LABEL: srl: +; RV64I: # %bb.0: +; RV64I-NEXT: srl a0, a0, a1 +; RV64I-NEXT: ret + %1 = lshr i64 %a, %b + ret i64 %1 +} + +define i64 @sra(i64 %a, i64 %b) nounwind { +; RV64I-LABEL: sra: +; RV64I: # %bb.0: +; RV64I-NEXT: sra a0, a0, a1 +; RV64I-NEXT: ret + %1 = ashr i64 %a, %b + ret i64 %1 +} + +define i64 @or(i64 %a, i64 %b) nounwind { +; RV64I-LABEL: or: +; RV64I: # %bb.0: +; RV64I-NEXT: or a0, a0, a1 +; RV64I-NEXT: ret + %1 = or i64 %a, %b + ret i64 %1 +} + +define i64 @and(i64 %a, i64 %b) nounwind { +; RV64I-LABEL: and: +; RV64I: # %bb.0: +; RV64I-NEXT: and a0, a0, a1 +; RV64I-NEXT: ret + %1 = and i64 %a, %b + ret i64 %1 +}