Skip to content

Commit e696379

Browse files
authored
[RISCV][GISel] Falling back to SDISel for scalable vector type values (#70133)
This patch also tests the fallback of unsupported formal arguments.
1 parent cd29e19 commit e696379

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19304,6 +19304,23 @@ unsigned RISCVTargetLowering::getCustomCtpopCost(EVT VT,
1930419304
return isCtpopFast(VT) ? 0 : 1;
1930519305
}
1930619306

19307+
bool RISCVTargetLowering::fallBackToDAGISel(const Instruction &Inst) const {
19308+
// We don't support scalable vectors in GISel.
19309+
if (Inst.getType()->isScalableTy())
19310+
return true;
19311+
19312+
for (unsigned i = 0; i < Inst.getNumOperands(); ++i)
19313+
if (Inst.getOperand(i)->getType()->isScalableTy())
19314+
return true;
19315+
19316+
if (const AllocaInst *AI = dyn_cast<AllocaInst>(&Inst)) {
19317+
if (AI->getAllocatedType()->isScalableTy())
19318+
return true;
19319+
}
19320+
19321+
return false;
19322+
}
19323+
1930719324
namespace llvm::RISCVVIntrinsicsTable {
1930819325

1930919326
#define GET_RISCVVIntrinsicsTable_IMPL

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,8 @@ class RISCVTargetLowering : public TargetLowering {
800800

801801
unsigned getMaxSupportedInterleaveFactor() const override { return 8; }
802802

803+
bool fallBackToDAGISel(const Instruction &Inst) const override;
804+
803805
bool lowerInterleavedLoad(LoadInst *LI,
804806
ArrayRef<ShuffleVectorInst *> Shuffles,
805807
ArrayRef<unsigned> Indices,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; RUN: llc -mtriple=riscv64 -mattr='+v' -O0 -global-isel -global-isel-abort=2 -pass-remarks-missed='gisel*' -verify-machineinstrs %s -o %t.out 2> %t.err
2+
; RUN: FileCheck %s --check-prefix=FALLBACK-WITH-REPORT-OUT < %t.out
3+
; RUN: FileCheck %s --check-prefix=FALLBACK-WITH-REPORT-ERR < %t.err
4+
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: remark: <unknown>:0:0: unable to lower arguments{{.*}}scalable_arg
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{{.*}}scalable_inst
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+
38+
; FALLBACK-WITH-REPORT-ERR: remark: <unknown>:0:0: unable to translate instruction{{.*}}scalable_alloca
39+
; FALLBACK-WITH-REPORT-OUT-LABEL: scalable_alloca
40+
define void @scalable_alloca() #1 {
41+
%local0 = alloca <vscale x 16 x i8>
42+
load volatile <vscale x 16 x i8>, ptr %local0
43+
ret void
44+
}

0 commit comments

Comments
 (0)