Skip to content

Commit 525b8e6

Browse files
committed
[SVE] Fix wrong usage of getNumElements() in matchIntrinsicType
I have changed the ScalableVecArgument case in matchIntrinsicType to create a new FixedVectorType. This means that the next case we hit (Vector) will not assert when calling getNumElements(), since we know that it's always a FixedVectorType. This is a temporary measure for now, and it will be fixed properly in another patch that refactors this code. The changes are covered by this existing test: CodeGen/AArch64/sve-intrinsics-fp-converts.ll In addition, I have added a new test to ensure that we correctly reject SVE intrinsics when called with fixed length vector types. Differential Revision: https://reviews.llvm.org/D79416
1 parent 85bb9b7 commit 525b8e6

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Diff for: llvm/lib/IR/Function.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,9 @@ static bool matchIntrinsicType(
11801180
case IITDescriptor::Quad: return !Ty->isFP128Ty();
11811181
case IITDescriptor::Integer: return !Ty->isIntegerTy(D.Integer_Width);
11821182
case IITDescriptor::Vector: {
1183-
VectorType *VT = dyn_cast<VectorType>(Ty);
1183+
// FIXME: We shouldn't be assuming all Vector types are fixed width.
1184+
// This will be fixed soon in another future patch.
1185+
FixedVectorType *VT = dyn_cast<FixedVectorType>(Ty);
11841186
return !VT || VT->getNumElements() != D.Vector_Width ||
11851187
matchIntrinsicType(VT->getElementType(), Infos, ArgTys,
11861188
DeferredChecks, IsDeferredCheck);
@@ -1357,7 +1359,11 @@ static bool matchIntrinsicType(
13571359
case IITDescriptor::ScalableVecArgument: {
13581360
if (!isa<ScalableVectorType>(Ty))
13591361
return true;
1360-
return matchIntrinsicType(Ty, Infos, ArgTys, DeferredChecks,
1362+
ScalableVectorType *STy = cast<ScalableVectorType>(Ty);
1363+
unsigned MinElts = STy->getMinNumElements();
1364+
FixedVectorType *FVTy =
1365+
FixedVectorType::get(STy->getElementType(), MinElts);
1366+
return matchIntrinsicType(FVTy, Infos, ArgTys, DeferredChecks,
13611367
IsDeferredCheck);
13621368
}
13631369
case IITDescriptor::VecOfBitcastsToInt: {

Diff for: llvm/test/CodeGen/AArch64/sve-bad-intrinsics.ll

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; RUN: not llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s 2>%t
2+
; RUN: FileCheck --check-prefix=CHECK-ERROR %s <%t
3+
4+
declare <4 x float> @llvm.arm.neon.vcvthf2fp(<vscale x 4 x i16>)
5+
declare <vscale x 4 x i16> @llvm.arm.neon.vcvtfp2hf(<vscale x 4 x float>)
6+
7+
; CHECK-ERROR: Intrinsic has incorrect return type!
8+
define <vscale x 4 x i16> @bad1() {
9+
%r = call <vscale x 4 x i16> @llvm.arm.neon.vcvtfp2hf(<vscale x 4 x float> zeroinitializer)
10+
ret <vscale x 4 x i16> %r
11+
}
12+
13+
; CHECK-ERROR: Intrinsic has incorrect argument type!
14+
define <4 x float> @bad2() {
15+
%r = call <4 x float> @llvm.arm.neon.vcvthf2fp(<vscale x 4 x i16> zeroinitializer)
16+
ret <4 x float> %r
17+
}

0 commit comments

Comments
 (0)