Skip to content

Commit de68181

Browse files
authored
DAG: Use sincos vector libcalls through RuntimeLibcalls (#166984)
Copy new process from sincospi.
1 parent 843f122 commit de68181

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,12 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
334334

335335
break;
336336
case Intrinsic::sincos:
337-
LC = RTLIB::getSINCOS(ScalarVT);
337+
LC = RTLIB::getSINCOS(VT);
338+
if (LC == RTLIB::UNKNOWN_LIBCALL)
339+
LC = RTLIB::getSINCOS(ScalarVT);
340+
else if (VT.isVector())
341+
IsVectorCall = true;
342+
338343
break;
339344
default:
340345
return std::nullopt;

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,10 +1268,12 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
12681268
return;
12691269

12701270
break;
1271-
1271+
case ISD::FSINCOS:
12721272
case ISD::FSINCOSPI: {
12731273
EVT VT = Node->getValueType(0);
1274-
RTLIB::Libcall LC = RTLIB::getSINCOSPI(VT);
1274+
RTLIB::Libcall LC = Node->getOpcode() == ISD::FSINCOS
1275+
? RTLIB::getSINCOS(VT)
1276+
: RTLIB::getSINCOSPI(VT);
12751277
if (LC != RTLIB::UNKNOWN_LIBCALL &&
12761278
DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT))
12771279
return;
@@ -1280,14 +1282,6 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
12801282
// scalarizing.
12811283
break;
12821284
}
1283-
case ISD::FSINCOS: {
1284-
// FIXME: Try to directly match vector case like fsincospi
1285-
EVT VT = Node->getValueType(0).getVectorElementType();
1286-
RTLIB::Libcall LC = RTLIB::getSINCOS(VT);
1287-
if (DAG.expandMultipleResultFPLibCall(LC, Node, Results, VT))
1288-
return;
1289-
break;
1290-
}
12911285
case ISD::FMODF: {
12921286
EVT VT = Node->getValueType(0).getVectorElementType();
12931287
RTLIB::Libcall LC = RTLIB::getMODF(VT);

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,24 @@ RTLIB::Libcall RTLIB::getCOS(EVT RetVT) {
424424
}
425425

426426
RTLIB::Libcall RTLIB::getSINCOS(EVT RetVT) {
427+
// TODO: Tablegen should generate this function
428+
if (RetVT.isVector()) {
429+
if (!RetVT.isSimple())
430+
return RTLIB::UNKNOWN_LIBCALL;
431+
switch (RetVT.getSimpleVT().SimpleTy) {
432+
case MVT::v4f32:
433+
return RTLIB::SINCOS_V4F32;
434+
case MVT::v2f64:
435+
return RTLIB::SINCOS_V2F64;
436+
case MVT::nxv4f32:
437+
return RTLIB::SINCOS_NXV4F32;
438+
case MVT::nxv2f64:
439+
return RTLIB::SINCOS_NXV2F64;
440+
default:
441+
return RTLIB::UNKNOWN_LIBCALL;
442+
}
443+
}
444+
427445
return getFPLibCall(RetVT, SINCOS_F32, SINCOS_F64, SINCOS_F80, SINCOS_F128,
428446
SINCOS_PPCF128);
429447
}

0 commit comments

Comments
 (0)