Skip to content

Commit 58e7e95

Browse files
committed
DAG: Use modf vector libcalls through RuntimeLibcalls
Copy new process from sincos/sincospi
1 parent b66f444 commit 58e7e95

File tree

3 files changed

+24
-40
lines changed

3 files changed

+24
-40
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -313,33 +313,17 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
313313
Type *Ty = getContainedTypes(RetTy).front();
314314
EVT VT = getTLI()->getValueType(DL, Ty);
315315

316-
EVT ScalarVT = VT.getScalarType();
317316
RTLIB::Libcall LC = RTLIB::UNKNOWN_LIBCALL;
318317

319-
/// Migration flag. IsVectorCall cases directly know about the vector
320-
/// libcall in RuntimeLibcallsInfo and shouldn't try to use
321-
/// LibInfo->getVectorMappingInfo.
322-
bool IsVectorCall = false;
323-
324318
switch (ICA.getID()) {
325319
case Intrinsic::modf:
326-
LC = RTLIB::getMODF(ScalarVT);
320+
LC = RTLIB::getMODF(VT);
327321
break;
328322
case Intrinsic::sincospi:
329323
LC = RTLIB::getSINCOSPI(VT);
330-
if (LC == RTLIB::UNKNOWN_LIBCALL)
331-
LC = RTLIB::getSINCOSPI(ScalarVT);
332-
else if (VT.isVector())
333-
IsVectorCall = true;
334-
335324
break;
336325
case Intrinsic::sincos:
337326
LC = RTLIB::getSINCOS(VT);
338-
if (LC == RTLIB::UNKNOWN_LIBCALL)
339-
LC = RTLIB::getSINCOS(ScalarVT);
340-
else if (VT.isVector())
341-
IsVectorCall = true;
342-
343327
break;
344328
default:
345329
return std::nullopt;
@@ -350,33 +334,14 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
350334
if (LibcallImpl == RTLIB::Unsupported)
351335
return std::nullopt;
352336

353-
StringRef LCName =
354-
RTLIB::RuntimeLibcallsInfo::getLibcallImplName(LibcallImpl);
355-
356-
// Search for a corresponding vector variant.
357-
//
358-
// FIXME: Should use RuntimeLibcallsInfo, not TargetLibraryInfo to get the
359-
// vector mapping.
360337
LLVMContext &Ctx = RetTy->getContext();
361-
ElementCount VF = getVectorizedTypeVF(RetTy);
362-
VecDesc const *VD = nullptr;
363-
364-
if (!IsVectorCall) {
365-
for (bool Masked : {false, true}) {
366-
if ((VD = LibInfo->getVectorMappingInfo(LCName, VF, Masked)))
367-
break;
368-
}
369-
if (!VD)
370-
return std::nullopt;
371-
}
372338

373339
// Cost the call + mask.
374340
auto Cost =
375341
thisT()->getCallInstrCost(nullptr, RetTy, ICA.getArgTypes(), CostKind);
376342

377-
if ((VD && VD->isMasked()) ||
378-
(IsVectorCall &&
379-
RTLIB::RuntimeLibcallsInfo::hasVectorMaskArgument(LibcallImpl))) {
343+
if (RTLIB::RuntimeLibcallsInfo::hasVectorMaskArgument(LibcallImpl)) {
344+
ElementCount VF = getVectorizedTypeVF(RetTy);
380345
auto VecTy = VectorType::get(IntegerType::getInt1Ty(Ctx), VF);
381346
Cost += thisT()->getShuffleCost(TargetTransformInfo::SK_Broadcast, VecTy,
382347
VecTy, {}, CostKind, 0, nullptr, {});

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,9 +1283,10 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
12831283
break;
12841284
}
12851285
case ISD::FMODF: {
1286-
EVT VT = Node->getValueType(0).getVectorElementType();
1286+
EVT VT = Node->getValueType(0);
12871287
RTLIB::Libcall LC = RTLIB::getMODF(VT);
1288-
if (DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT,
1288+
if (LC != RTLIB::UNKNOWN_LIBCALL &&
1289+
DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT,
12891290
/*CallRetResNo=*/0))
12901291
return;
12911292
break;

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,24 @@ RTLIB::Libcall RTLIB::getSINCOS_STRET(EVT RetVT) {
476476
}
477477

478478
RTLIB::Libcall RTLIB::getMODF(EVT RetVT) {
479+
// TODO: Tablegen should generate this function
480+
if (RetVT.isVector()) {
481+
if (!RetVT.isSimple())
482+
return RTLIB::UNKNOWN_LIBCALL;
483+
switch (RetVT.getSimpleVT().SimpleTy) {
484+
case MVT::v4f32:
485+
return RTLIB::MODF_V4F32;
486+
case MVT::v2f64:
487+
return RTLIB::MODF_V2F64;
488+
case MVT::nxv4f32:
489+
return RTLIB::MODF_NXV4F32;
490+
case MVT::nxv2f64:
491+
return RTLIB::MODF_NXV2F64;
492+
default:
493+
return RTLIB::UNKNOWN_LIBCALL;
494+
}
495+
}
496+
479497
return getFPLibCall(RetVT, MODF_F32, MODF_F64, MODF_F80, MODF_F128,
480498
MODF_PPCF128);
481499
}

0 commit comments

Comments
 (0)