From f87226eb708152eba7616d194e9c6ae41f0f5e2d Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Wed, 23 Jan 2019 16:00:22 +0000 Subject: [IR] Match intrinsic parameter by scalar/vectorwidth This patch replaces the existing LLVMVectorSameWidth matcher with LLVMScalarOrSameVectorWidth. The matching args must be either scalars or vectors with the same number of elements, but in either case the scalar/element type can differ, specified by LLVMScalarOrSameVectorWidth. I've updated the _overflow intrinsics to demonstrate this - allowing it to return a i1 or overflow result, matching the scalar/vectorwidth of the other (add/sub/mul) result type. The masked load/store/gather/scatter intrinsics have also been updated to use this, although as we specify the reference type to be llvm_anyvector_ty we guarantee the mask will be so no change in behaviour Differential Revision: https://reviews.llvm.org/D57090 llvm-svn: 351957 --- llvm/lib/IR/Function.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'llvm/lib/IR') diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index 8601ec015a5..3ec421fe881 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -948,10 +948,9 @@ static Type *DecodeFixedType(ArrayRef &Infos, case IITDescriptor::SameVecWidthArgument: { Type *EltTy = DecodeFixedType(Infos, Tys, Context); Type *Ty = Tys[D.getArgumentNumber()]; - if (VectorType *VTy = dyn_cast(Ty)) { + if (auto *VTy = dyn_cast(Ty)) return VectorType::get(EltTy, VTy->getNumElements()); - } - llvm_unreachable("unhandled"); + return EltTy; } case IITDescriptor::PtrToArgument: { Type *Ty = Tys[D.getArgumentNumber()]; @@ -1135,15 +1134,19 @@ bool Intrinsic::matchIntrinsicType(Type *Ty, ArrayRef case IITDescriptor::SameVecWidthArgument: { if (D.getArgumentNumber() >= ArgTys.size()) return true; - VectorType * ReferenceType = - dyn_cast(ArgTys[D.getArgumentNumber()]); - VectorType *ThisArgType = dyn_cast(Ty); - if (!ThisArgType || !ReferenceType || - (ReferenceType->getVectorNumElements() != - ThisArgType->getVectorNumElements())) + auto *ReferenceType = dyn_cast(ArgTys[D.getArgumentNumber()]); + auto *ThisArgType = dyn_cast(Ty); + // Both must be vectors of the same number of elements or neither. + if ((ReferenceType != nullptr) != (ThisArgType != nullptr)) return true; - return matchIntrinsicType(ThisArgType->getVectorElementType(), - Infos, ArgTys); + Type *EltTy = Ty; + if (ThisArgType) { + if (ReferenceType->getVectorNumElements() != + ThisArgType->getVectorNumElements()) + return true; + EltTy = ThisArgType->getVectorElementType(); + } + return matchIntrinsicType(EltTy, Infos, ArgTys); } case IITDescriptor::PtrToArgument: { if (D.getArgumentNumber() >= ArgTys.size()) -- cgit v1.2.3