Skip to content

[LV] Teach the vectorizer to cost and vectorize modf and sincospi intrinsics #129064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2025
Merged
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
29 changes: 25 additions & 4 deletions llvm/include/llvm/CodeGen/BasicTTIImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2056,12 +2056,33 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
}
case Intrinsic::experimental_vector_match:
return thisT()->getTypeBasedIntrinsicInstrCost(ICA, CostKind);
case Intrinsic::sincos: {
case Intrinsic::modf:
case Intrinsic::sincos:
case Intrinsic::sincospi: {
Type *Ty = getContainedTypes(RetTy).front();
EVT VT = getTLI()->getValueType(DL, Ty);
RTLIB::Libcall LC = RTLIB::getSINCOS(VT.getScalarType());
if (auto Cost =
getMultipleResultIntrinsicVectorLibCallCost(ICA, CostKind, LC))

RTLIB::Libcall LC = [&] {
switch (ICA.getID()) {
case Intrinsic::modf:
return RTLIB::getMODF;
case Intrinsic::sincos:
return RTLIB::getSINCOS;
case Intrinsic::sincospi:
return RTLIB::getSINCOSPI;
default:
llvm_unreachable("unexpected intrinsic");
}
}()(VT.getScalarType());

std::optional<unsigned> CallRetElementIndex;
// The first element of the modf result is returned by value in the
// libcall.
if (ICA.getID() == Intrinsic::modf)
CallRetElementIndex = 0;

if (auto Cost = getMultipleResultIntrinsicVectorLibCallCost(
ICA, CostKind, LC, CallRetElementIndex))
return *Cost;
// Otherwise, fallback to default scalarization cost.
break;
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Analysis/VectorUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ bool llvm::isTriviallyVectorizable(Intrinsic::ID ID) {
case Intrinsic::sin:
case Intrinsic::cos:
case Intrinsic::sincos:
case Intrinsic::sincospi:
case Intrinsic::tan:
case Intrinsic::sinh:
case Intrinsic::cosh:
Expand All @@ -88,6 +89,7 @@ bool llvm::isTriviallyVectorizable(Intrinsic::ID ID) {
case Intrinsic::maxnum:
case Intrinsic::minimum:
case Intrinsic::maximum:
case Intrinsic::modf:
case Intrinsic::copysign:
case Intrinsic::floor:
case Intrinsic::ceil:
Expand Down Expand Up @@ -186,7 +188,9 @@ bool llvm::isVectorIntrinsicWithOverloadTypeAtArg(
case Intrinsic::ucmp:
case Intrinsic::scmp:
return OpdIdx == -1 || OpdIdx == 0;
case Intrinsic::modf:
case Intrinsic::sincos:
case Intrinsic::sincospi:
case Intrinsic::is_fpclass:
case Intrinsic::vp_is_fpclass:
return OpdIdx == 0;
Expand Down
Loading