Skip to content

Commit c31f3e3

Browse files
check legal rvv types
1 parent a9e65fd commit c31f3e3

File tree

4 files changed

+114
-377
lines changed

4 files changed

+114
-377
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,34 @@ struct RISCVCallReturnHandler : public RISCVIncomingValueHandler {
297297
RISCVCallLowering::RISCVCallLowering(const RISCVTargetLowering &TLI)
298298
: CallLowering(&TLI) {}
299299

300+
/// Return true if scalable vector with ScalarTy is legal for lowering.
301+
static bool isLegalElementTypeForRVV(EVT ScalarTy,
302+
const RISCVSubtarget &Subtarget) {
303+
if (!ScalarTy.isSimple())
304+
return false;
305+
switch (ScalarTy.getSimpleVT().SimpleTy) {
306+
case MVT::iPTR:
307+
return Subtarget.is64Bit() ? Subtarget.hasVInstructionsI64() : true;
308+
case MVT::i1:
309+
case MVT::i8:
310+
case MVT::i16:
311+
case MVT::i32:
312+
return true;
313+
case MVT::i64:
314+
return Subtarget.hasVInstructionsI64();
315+
case MVT::f16:
316+
return Subtarget.hasVInstructionsF16();
317+
case MVT::bf16:
318+
return Subtarget.hasVInstructionsBF16();
319+
case MVT::f32:
320+
return Subtarget.hasVInstructionsF32();
321+
case MVT::f64:
322+
return Subtarget.hasVInstructionsF64();
323+
default:
324+
return false;
325+
}
326+
}
327+
300328
// TODO: Support all argument types.
301329
// TODO: Remove IsLowerArgs argument by adding support for vectors in lowerCall.
302330
static bool isSupportedArgumentType(Type *T, const RISCVSubtarget &Subtarget,
@@ -311,7 +339,8 @@ static bool isSupportedArgumentType(Type *T, const RISCVSubtarget &Subtarget,
311339
return true;
312340
// TODO: Support fixed vector types.
313341
if (IsLowerArgs && T->isVectorTy() && Subtarget.hasVInstructions() &&
314-
T->isScalableTy())
342+
T->isScalableTy() &&
343+
isLegalElementTypeForRVV(EVT::getEVT(T->getScalarType()), Subtarget))
315344
return true;
316345
return false;
317346
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: not --crash llc -mtriple=riscv32 -mattr=+v -global-isel -stop-after=irtranslator \
2+
; RUN: -verify-machineinstrs < %s 2>&1 | FileCheck %s
3+
; RUN: not --crash llc -mtriple=riscv64 -mattr=+v -global-isel -stop-after=irtranslator \
4+
; RUN: -verify-machineinstrs < %s 2>&1 | FileCheck %s
5+
6+
; The purpose of this test is to show that the compiler throws an error when
7+
; there is no support for bf16 vectors. If the compiler did not throw an error,
8+
; then it will try to scalarize the argument to an s32, which may drop elements.
9+
define void @test_args_nxv1bf16(<vscale x 1 x bfloat> %a) {
10+
entry:
11+
ret void
12+
}
13+
14+
; CHECK: LLVM ERROR: unable to lower arguments: ptr (in function: test_args_nxv1bf16)
15+
16+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: not --crash llc -mtriple=riscv32 -mattr=+v -global-isel -stop-after=irtranslator \
2+
; RUN: -verify-machineinstrs < %s 2>&1 | FileCheck %s
3+
; RUN: not --crash llc -mtriple=riscv64 -mattr=+v -global-isel -stop-after=irtranslator \
4+
; RUN: -verify-machineinstrs < %s 2>&1 | FileCheck %s
5+
6+
; The purpose of this test is to show that the compiler throws an error when
7+
; there is no support for f16 vectors. If the compiler did not throw an error,
8+
; then it will try to scalarize the argument to an s32, which may drop elements.
9+
define void @test_args_nxv1f16(<vscale x 1 x half> %a) {
10+
entry:
11+
ret void
12+
}
13+
14+
; CHECK: LLVM ERROR: unable to lower arguments: ptr (in function: test_args_nxv1f16)
15+
16+

0 commit comments

Comments
 (0)