Skip to content

Commit 89e7f4d

Browse files
authored
[LV] Teach the vectorizer to cost and vectorize modf and sincospi intrinsics (#129064)
Follow on to #128035. It is a small extension to support vectorizing `llvm.modf.*` and `llvm.sincospi.*` too. This renames the test files from `sincos.ll` -> `multiple-result-intrinsics.ll` to group together the similar tests (which make up most of this PR).
1 parent a199791 commit 89e7f4d

File tree

6 files changed

+938
-412
lines changed

6 files changed

+938
-412
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,12 +2056,33 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
20562056
}
20572057
case Intrinsic::experimental_vector_match:
20582058
return thisT()->getTypeBasedIntrinsicInstrCost(ICA, CostKind);
2059-
case Intrinsic::sincos: {
2059+
case Intrinsic::modf:
2060+
case Intrinsic::sincos:
2061+
case Intrinsic::sincospi: {
20602062
Type *Ty = getContainedTypes(RetTy).front();
20612063
EVT VT = getTLI()->getValueType(DL, Ty);
2062-
RTLIB::Libcall LC = RTLIB::getSINCOS(VT.getScalarType());
2063-
if (auto Cost =
2064-
getMultipleResultIntrinsicVectorLibCallCost(ICA, CostKind, LC))
2064+
2065+
RTLIB::Libcall LC = [&] {
2066+
switch (ICA.getID()) {
2067+
case Intrinsic::modf:
2068+
return RTLIB::getMODF;
2069+
case Intrinsic::sincos:
2070+
return RTLIB::getSINCOS;
2071+
case Intrinsic::sincospi:
2072+
return RTLIB::getSINCOSPI;
2073+
default:
2074+
llvm_unreachable("unexpected intrinsic");
2075+
}
2076+
}()(VT.getScalarType());
2077+
2078+
std::optional<unsigned> CallRetElementIndex;
2079+
// The first element of the modf result is returned by value in the
2080+
// libcall.
2081+
if (ICA.getID() == Intrinsic::modf)
2082+
CallRetElementIndex = 0;
2083+
2084+
if (auto Cost = getMultipleResultIntrinsicVectorLibCallCost(
2085+
ICA, CostKind, LC, CallRetElementIndex))
20652086
return *Cost;
20662087
// Otherwise, fallback to default scalarization cost.
20672088
break;

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ bool llvm::isTriviallyVectorizable(Intrinsic::ID ID) {
7373
case Intrinsic::sin:
7474
case Intrinsic::cos:
7575
case Intrinsic::sincos:
76+
case Intrinsic::sincospi:
7677
case Intrinsic::tan:
7778
case Intrinsic::sinh:
7879
case Intrinsic::cosh:
@@ -88,6 +89,7 @@ bool llvm::isTriviallyVectorizable(Intrinsic::ID ID) {
8889
case Intrinsic::maxnum:
8990
case Intrinsic::minimum:
9091
case Intrinsic::maximum:
92+
case Intrinsic::modf:
9193
case Intrinsic::copysign:
9294
case Intrinsic::floor:
9395
case Intrinsic::ceil:
@@ -186,7 +188,9 @@ bool llvm::isVectorIntrinsicWithOverloadTypeAtArg(
186188
case Intrinsic::ucmp:
187189
case Intrinsic::scmp:
188190
return OpdIdx == -1 || OpdIdx == 0;
191+
case Intrinsic::modf:
189192
case Intrinsic::sincos:
193+
case Intrinsic::sincospi:
190194
case Intrinsic::is_fpclass:
191195
case Intrinsic::vp_is_fpclass:
192196
return OpdIdx == 0;

0 commit comments

Comments
 (0)