Skip to content

Commit 17bfcbe

Browse files
committed
DAG: Use sincos vector libcalls through RuntimeLibcalls
Copy new process from sincospi.
1 parent 414d93b commit 17bfcbe

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
@@ -425,6 +425,24 @@ RTLIB::Libcall RTLIB::getCOS(EVT RetVT) {
425425
}
426426

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

0 commit comments

Comments
 (0)