Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions llvm/include/llvm/Analysis/VectorUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ LLVM_ABI bool
isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID, int OpdIdx,
const TargetTransformInfo *TTI);

/// Identifies if the vector form of the intrinsic that returns a struct has
/// a scalar element at the struct element index \p RetIdx.
LLVM_ABI bool isVectorIntrinsicWithStructReturnScalarAtField(Intrinsic::ID ID,
int RetIdx);

/// Identifies if the vector form of the intrinsic that returns a struct is
/// overloaded at the struct element index \p RetIdx. /// \p TTI is used to
/// consider target specific intrinsics, if no target specific intrinsics
Expand Down
14 changes: 14 additions & 0 deletions llvm/lib/Analysis/VectorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,27 @@ bool llvm::isVectorIntrinsicWithOverloadTypeAtArg(
}
}

bool llvm::isVectorIntrinsicWithStructReturnScalarAtField(Intrinsic::ID ID,
int RetIdx) {
switch (ID) {
case Intrinsic::vp_load_ff:
return RetIdx == 1;
default:
return false;
}
}

bool llvm::isVectorIntrinsicWithStructReturnOverloadAtField(
Intrinsic::ID ID, int RetIdx, const TargetTransformInfo *TTI) {

if (TTI && Intrinsic::isTargetIntrinsic(ID))
return TTI->isTargetIntrinsicWithStructReturnOverloadAtField(ID, RetIdx);

switch (ID) {
case Intrinsic::modf:
case Intrinsic::sincos:
case Intrinsic::sincospi:
return false;
case Intrinsic::frexp:
return RetIdx == 0 || RetIdx == 1;
default:
Expand Down
17 changes: 16 additions & 1 deletion llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4100,7 +4100,22 @@ static bool willGenerateVectors(VPlan &Plan, ElementCount VF,
Type *ScalarTy = TypeInfo.inferScalarType(ToCheck);
if (!Visited.insert({ScalarTy}).second)
continue;
Type *WideTy = toVectorizedTy(ScalarTy, VF);
Type *WideTy;
if (auto *WI = dyn_cast<VPWidenIntrinsicRecipe>(&R);
WI && ScalarTy->isStructTy()) {
auto *StructTy = cast<StructType>(ScalarTy);
SmallVector<Type *, 2> Tys;
for (unsigned I = 0, E = StructTy->getNumElements(); I != E; ++I) {
Type *ElementTy = StructTy->getStructElementType(I);
if (!isVectorIntrinsicWithStructReturnScalarAtField(
WI->getVectorIntrinsicID(), I))
ElementTy = toVectorizedTy(ElementTy, VF);
Tys.push_back(ElementTy);
}
WideTy = StructType::create(Tys);
} else
WideTy = toVectorizedTy(ScalarTy, VF);

if (any_of(getContainedTypes(WideTy), WillGenerateTargetVectors))
return true;
}
Expand Down
27 changes: 24 additions & 3 deletions llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,7 +1738,16 @@ void VPWidenIntrinsicRecipe::execute(VPTransformState &State) {

SmallVector<Type *, 2> TysForDecl;
// Add return type if intrinsic is overloaded on it.
if (isVectorIntrinsicWithOverloadTypeAtArg(VectorIntrinsicID, -1, State.TTI))
if (ResultTy->isStructTy()) {
auto *StructTy = cast<StructType>(ResultTy);
for (unsigned I = 0, E = StructTy->getNumElements(); I != E; ++I) {
if (isVectorIntrinsicWithStructReturnOverloadAtField(VectorIntrinsicID, I,
State.TTI))
TysForDecl.push_back(
toVectorizedTy(StructTy->getStructElementType(I), State.VF));
}
} else if (isVectorIntrinsicWithOverloadTypeAtArg(VectorIntrinsicID, -1,
State.TTI))
TysForDecl.push_back(VectorType::get(getResultType(), State.VF));
SmallVector<Value *, 4> Args;
for (const auto &I : enumerate(operands())) {
Expand Down Expand Up @@ -1802,8 +1811,20 @@ static InstructionCost getCostForIntrinsics(Intrinsic::ID ID,
Arguments.push_back(V);
}

Type *ScalarRetTy = Ctx.Types.inferScalarType(&R);
Type *RetTy = VF.isVector() ? toVectorizedTy(ScalarRetTy, VF) : ScalarRetTy;
Type *RetTy = Ctx.Types.inferScalarType(&R);

if (VF.isVector() && RetTy->isStructTy()) {
auto *StructTy = cast<StructType>(RetTy);
SmallVector<Type *> Tys;
for (unsigned I = 0, E = StructTy->getNumElements(); I != E; ++I) {
Type *ElementTy = StructTy->getStructElementType(I);
if (!isVectorIntrinsicWithStructReturnScalarAtField(ID, I))
ElementTy = toVectorizedTy(ElementTy, VF);
Tys.push_back(ElementTy);
}
RetTy = StructType::get(StructTy->getContext(), Tys);
} else if (VF.isVector())
RetTy = toVectorizedTy(RetTy, VF);
SmallVector<Type *> ParamTys;
for (const VPValue *Op : Operands) {
ParamTys.push_back(VF.isVector()
Expand Down