Skip to content

Commit 48661a4

Browse files
authored
[RISCV][GISel] Add initial support for rvv intrinsics (#156415)
This pr removes the falling back to SDISel of rvv intrinsics and marks them legalized in the legalize pass. Another pr would be created for regbankselect pass to make vf form intriniscs have the right scalar register bank.
1 parent c52cb96 commit 48661a4

File tree

4 files changed

+775
-33
lines changed

4 files changed

+775
-33
lines changed

llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
722722
bool RISCVLegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper,
723723
MachineInstr &MI) const {
724724
Intrinsic::ID IntrinsicID = cast<GIntrinsic>(MI).getIntrinsicID();
725+
726+
if (RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IntrinsicID))
727+
return true;
728+
725729
switch (IntrinsicID) {
726730
default:
727731
return false;

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "llvm/IR/DiagnosticPrinter.h"
3939
#include "llvm/IR/IRBuilder.h"
4040
#include "llvm/IR/Instructions.h"
41+
#include "llvm/IR/IntrinsicInst.h"
4142
#include "llvm/IR/IntrinsicsRISCV.h"
4243
#include "llvm/MC/MCCodeEmitter.h"
4344
#include "llvm/MC/MCInstBuilder.h"
@@ -24894,6 +24895,12 @@ bool RISCVTargetLowering::fallBackToDAGISel(const Instruction &Inst) const {
2489424895
Op == Instruction::Freeze || Op == Instruction::Store)
2489524896
return false;
2489624897

24898+
if (auto *II = dyn_cast<IntrinsicInst>(&Inst)) {
24899+
// Mark RVV intrinsic as supported.
24900+
if (RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(II->getIntrinsicID()))
24901+
return false;
24902+
}
24903+
2489724904
if (Inst.getType()->isScalableTy())
2489824905
return true;
2489924906

llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/fallback.ll

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,6 @@
22
; RUN: FileCheck %s --check-prefix=FALLBACK-WITH-REPORT-OUT < %t.out
33
; RUN: FileCheck %s --check-prefix=FALLBACK-WITH-REPORT-ERR < %t.err
44

5-
6-
declare <vscale x 1 x i8> @llvm.riscv.vadd.nxv1i8.nxv1i8(
7-
<vscale x 1 x i8>,
8-
<vscale x 1 x i8>,
9-
<vscale x 1 x i8>,
10-
i64)
11-
12-
; FALLBACK_WITH_REPORT_ERR: <unknown>:0:0: unable to translate instruction: call
13-
; FALLBACK-WITH-REPORT-OUT-LABEL: scalable_arg
14-
define <vscale x 1 x i8> @scalable_arg(<vscale x 1 x i8> %0, <vscale x 1 x i8> %1, i64 %2) nounwind {
15-
entry:
16-
%a = call <vscale x 1 x i8> @llvm.riscv.vadd.nxv1i8.nxv1i8(
17-
<vscale x 1 x i8> undef,
18-
<vscale x 1 x i8> %0,
19-
<vscale x 1 x i8> %1,
20-
i64 %2)
21-
22-
ret <vscale x 1 x i8> %a
23-
}
24-
25-
; FALLBACK-WITH-REPORT-ERR: remark: <unknown>:0:0: unable to translate instruction: call
26-
; FALLBACK-WITH-REPORT-OUT-LABEL: scalable_inst
27-
define <vscale x 1 x i8> @scalable_inst(i64 %0) nounwind {
28-
entry:
29-
%a = call <vscale x 1 x i8> @llvm.riscv.vadd.nxv1i8.nxv1i8(
30-
<vscale x 1 x i8> undef,
31-
<vscale x 1 x i8> undef,
32-
<vscale x 1 x i8> undef,
33-
i64 %0)
34-
35-
ret <vscale x 1 x i8> %a
36-
}
37-
385
; FALLBACK-WITH-REPORT-ERR: remark: <unknown>:0:0: unable to translate instruction: alloca:
396
; FALLBACK-WITH-REPORT-OUT-LABEL: scalable_alloca
407
define void @scalable_alloca() #1 {

0 commit comments

Comments
 (0)