Skip to content

Commit f36580f

Browse files
authored
[LegalizeVectorOps] Remove calls to DAG.UnrollVectorsOps from some expansion handlers. NFC (#108930)
Instead, return SDValue() to tell the caller to do the unrolling. This is consistent with how some other handler work. Especially the handlers that live in TLI. ExpandBITREVERSE was rewritten to not take the Results vector an argument.
1 parent 78f7aae commit f36580f

File tree

1 file changed

+56
-45
lines changed

1 file changed

+56
-45
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class VectorLegalizer {
146146
SDValue ExpandFCOPYSIGN(SDNode *Node);
147147
void ExpandFSUB(SDNode *Node, SmallVectorImpl<SDValue> &Results);
148148
void ExpandSETCC(SDNode *Node, SmallVectorImpl<SDValue> &Results);
149-
void ExpandBITREVERSE(SDNode *Node, SmallVectorImpl<SDValue> &Results);
149+
SDValue ExpandBITREVERSE(SDNode *Node);
150150
void ExpandUADDSUBO(SDNode *Node, SmallVectorImpl<SDValue> &Results);
151151
void ExpandSADDSUBO(SDNode *Node, SmallVectorImpl<SDValue> &Results);
152152
void ExpandMULO(SDNode *Node, SmallVectorImpl<SDValue> &Results);
@@ -867,8 +867,11 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
867867
Results.push_back(Node->getOperand(i));
868868
return;
869869
case ISD::SIGN_EXTEND_INREG:
870-
Results.push_back(ExpandSEXTINREG(Node));
871-
return;
870+
if (SDValue Expanded = ExpandSEXTINREG(Node)) {
871+
Results.push_back(Expanded);
872+
return;
873+
}
874+
break;
872875
case ISD::ANY_EXTEND_VECTOR_INREG:
873876
Results.push_back(ExpandANY_EXTEND_VECTOR_INREG(Node));
874877
return;
@@ -879,17 +882,26 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
879882
Results.push_back(ExpandZERO_EXTEND_VECTOR_INREG(Node));
880883
return;
881884
case ISD::BSWAP:
882-
Results.push_back(ExpandBSWAP(Node));
883-
return;
885+
if (SDValue Expanded = ExpandBSWAP(Node)) {
886+
Results.push_back(Expanded);
887+
return;
888+
}
889+
break;
884890
case ISD::VP_BSWAP:
885891
Results.push_back(TLI.expandVPBSWAP(Node, DAG));
886892
return;
887893
case ISD::VSELECT:
888-
Results.push_back(ExpandVSELECT(Node));
889-
return;
894+
if (SDValue Expanded = ExpandVSELECT(Node)) {
895+
Results.push_back(Expanded);
896+
return;
897+
}
898+
break;
890899
case ISD::VP_SELECT:
891-
Results.push_back(ExpandVP_SELECT(Node));
892-
return;
900+
if (SDValue Expanded = ExpandVP_SELECT(Node)) {
901+
Results.push_back(Expanded);
902+
return;
903+
}
904+
break;
893905
case ISD::VP_SREM:
894906
case ISD::VP_UREM:
895907
if (SDValue Expanded = ExpandVP_REM(Node)) {
@@ -916,8 +928,11 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
916928
}
917929
break;
918930
case ISD::SELECT:
919-
Results.push_back(ExpandSELECT(Node));
920-
return;
931+
if (SDValue Expanded = ExpandSELECT(Node)) {
932+
Results.push_back(Expanded);
933+
return;
934+
}
935+
break;
921936
case ISD::SELECT_CC: {
922937
if (Node->getValueType(0).isScalableVector()) {
923938
EVT CondVT = TLI.getSetCCResultType(
@@ -986,8 +1001,11 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
9861001
}
9871002
break;
9881003
case ISD::BITREVERSE:
989-
ExpandBITREVERSE(Node, Results);
990-
return;
1004+
if (SDValue Expanded = ExpandBITREVERSE(Node)) {
1005+
Results.push_back(Expanded);
1006+
return;
1007+
}
1008+
break;
9911009
case ISD::VP_BITREVERSE:
9921010
if (SDValue Expanded = TLI.expandVPBITREVERSE(Node, DAG)) {
9931011
Results.push_back(Expanded);
@@ -1160,8 +1178,11 @@ void VectorLegalizer::Expand(SDNode *Node, SmallVectorImpl<SDValue> &Results) {
11601178
ExpandREM(Node, Results);
11611179
return;
11621180
case ISD::VP_MERGE:
1163-
Results.push_back(ExpandVP_MERGE(Node));
1164-
return;
1181+
if (SDValue Expanded = ExpandVP_MERGE(Node)) {
1182+
Results.push_back(Expanded);
1183+
return;
1184+
}
1185+
break;
11651186
case ISD::FREM:
11661187
if (tryExpandVecMathCall(Node, RTLIB::REM_F32, RTLIB::REM_F64,
11671188
RTLIB::REM_F80, RTLIB::REM_F128,
@@ -1217,7 +1238,7 @@ SDValue VectorLegalizer::ExpandSELECT(SDNode *Node) {
12171238
TLI.getOperationAction(VT.isFixedLengthVector() ? ISD::BUILD_VECTOR
12181239
: ISD::SPLAT_VECTOR,
12191240
VT) == TargetLowering::Expand)
1220-
return DAG.UnrollVectorOp(Node);
1241+
return SDValue();
12211242

12221243
// Generate a mask operand.
12231244
EVT MaskTy = VT.changeVectorElementTypeToInteger();
@@ -1251,7 +1272,7 @@ SDValue VectorLegalizer::ExpandSEXTINREG(SDNode *Node) {
12511272
// Make sure that the SRA and SHL instructions are available.
12521273
if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Expand ||
12531274
TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Expand)
1254-
return DAG.UnrollVectorOp(Node);
1275+
return SDValue();
12551276

12561277
SDLoc DL(Node);
12571278
EVT OrigTy = cast<VTSDNode>(Node->getOperand(1))->getVT();
@@ -1396,26 +1417,20 @@ SDValue VectorLegalizer::ExpandBSWAP(SDNode *Node) {
13961417
TLI.isOperationLegalOrCustomOrPromote(ISD::OR, VT))
13971418
return TLI.expandBSWAP(Node, DAG);
13981419

1399-
// Otherwise unroll.
1400-
return DAG.UnrollVectorOp(Node);
1420+
// Otherwise let the caller unroll.
1421+
return SDValue();
14011422
}
14021423

1403-
void VectorLegalizer::ExpandBITREVERSE(SDNode *Node,
1404-
SmallVectorImpl<SDValue> &Results) {
1424+
SDValue VectorLegalizer::ExpandBITREVERSE(SDNode *Node) {
14051425
EVT VT = Node->getValueType(0);
14061426

14071427
// We can't unroll or use shuffles for scalable vectors.
1408-
if (VT.isScalableVector()) {
1409-
Results.push_back(TLI.expandBITREVERSE(Node, DAG));
1410-
return;
1411-
}
1428+
if (VT.isScalableVector())
1429+
return TLI.expandBITREVERSE(Node, DAG);
14121430

14131431
// If we have the scalar operation, it's probably cheaper to unroll it.
1414-
if (TLI.isOperationLegalOrCustom(ISD::BITREVERSE, VT.getScalarType())) {
1415-
SDValue Tmp = DAG.UnrollVectorOp(Node);
1416-
Results.push_back(Tmp);
1417-
return;
1418-
}
1432+
if (TLI.isOperationLegalOrCustom(ISD::BITREVERSE, VT.getScalarType()))
1433+
return SDValue();
14191434

14201435
// If the vector element width is a whole number of bytes, test if its legal
14211436
// to BSWAP shuffle the bytes and then perform the BITREVERSE on the byte
@@ -1438,8 +1453,7 @@ void VectorLegalizer::ExpandBITREVERSE(SDNode *Node,
14381453
BSWAPMask);
14391454
Op = DAG.getNode(ISD::BITREVERSE, DL, ByteVT, Op);
14401455
Op = DAG.getNode(ISD::BITCAST, DL, VT, Op);
1441-
Results.push_back(Op);
1442-
return;
1456+
return Op;
14431457
}
14441458
}
14451459

@@ -1448,14 +1462,11 @@ void VectorLegalizer::ExpandBITREVERSE(SDNode *Node,
14481462
if (TLI.isOperationLegalOrCustom(ISD::SHL, VT) &&
14491463
TLI.isOperationLegalOrCustom(ISD::SRL, VT) &&
14501464
TLI.isOperationLegalOrCustomOrPromote(ISD::AND, VT) &&
1451-
TLI.isOperationLegalOrCustomOrPromote(ISD::OR, VT)) {
1452-
Results.push_back(TLI.expandBITREVERSE(Node, DAG));
1453-
return;
1454-
}
1465+
TLI.isOperationLegalOrCustomOrPromote(ISD::OR, VT))
1466+
return TLI.expandBITREVERSE(Node, DAG);
14551467

14561468
// Otherwise unroll.
1457-
SDValue Tmp = DAG.UnrollVectorOp(Node);
1458-
Results.push_back(Tmp);
1469+
return SDValue();
14591470
}
14601471

14611472
SDValue VectorLegalizer::ExpandVSELECT(SDNode *Node) {
@@ -1476,7 +1487,7 @@ SDValue VectorLegalizer::ExpandVSELECT(SDNode *Node) {
14761487
if (TLI.getOperationAction(ISD::AND, VT) == TargetLowering::Expand ||
14771488
TLI.getOperationAction(ISD::XOR, VT) == TargetLowering::Expand ||
14781489
TLI.getOperationAction(ISD::OR, VT) == TargetLowering::Expand)
1479-
return DAG.UnrollVectorOp(Node);
1490+
return SDValue();
14801491

14811492
// This operation also isn't safe with AND, OR, XOR when the boolean type is
14821493
// 0/1 and the select operands aren't also booleans, as we need an all-ones
@@ -1486,13 +1497,13 @@ SDValue VectorLegalizer::ExpandVSELECT(SDNode *Node) {
14861497
if (BoolContents != TargetLowering::ZeroOrNegativeOneBooleanContent &&
14871498
!(BoolContents == TargetLowering::ZeroOrOneBooleanContent &&
14881499
Op1.getValueType().getVectorElementType() == MVT::i1))
1489-
return DAG.UnrollVectorOp(Node);
1500+
return SDValue();
14901501

14911502
// If the mask and the type are different sizes, unroll the vector op. This
14921503
// can occur when getSetCCResultType returns something that is different in
14931504
// size from the operand types. For example, v4i8 = select v4i32, v4i8, v4i8.
14941505
if (VT.getSizeInBits() != Op1.getValueSizeInBits())
1495-
return DAG.UnrollVectorOp(Node);
1506+
return SDValue();
14961507

14971508
// Bitcast the operands to be the same type as the mask.
14981509
// This is needed when we select between FP types because
@@ -1525,11 +1536,11 @@ SDValue VectorLegalizer::ExpandVP_SELECT(SDNode *Node) {
15251536
if (TLI.getOperationAction(ISD::VP_AND, VT) == TargetLowering::Expand ||
15261537
TLI.getOperationAction(ISD::VP_XOR, VT) == TargetLowering::Expand ||
15271538
TLI.getOperationAction(ISD::VP_OR, VT) == TargetLowering::Expand)
1528-
return DAG.UnrollVectorOp(Node);
1539+
return SDValue();
15291540

15301541
// This operation also isn't safe when the operands aren't also booleans.
15311542
if (Op1.getValueType().getVectorElementType() != MVT::i1)
1532-
return DAG.UnrollVectorOp(Node);
1543+
return SDValue();
15331544

15341545
SDValue Ones = DAG.getAllOnesConstant(DL, VT);
15351546
SDValue NotMask = DAG.getNode(ISD::VP_XOR, DL, VT, Mask, Ones, Ones, EVL);
@@ -1563,13 +1574,13 @@ SDValue VectorLegalizer::ExpandVP_MERGE(SDNode *Node) {
15631574
(!IsFixedLen &&
15641575
(!TLI.isOperationLegalOrCustom(ISD::STEP_VECTOR, EVLVecVT) ||
15651576
!TLI.isOperationLegalOrCustom(ISD::SPLAT_VECTOR, EVLVecVT))))
1566-
return DAG.UnrollVectorOp(Node);
1577+
return SDValue();
15671578

15681579
// If using a SETCC would result in a different type than the mask type,
15691580
// unroll.
15701581
if (TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
15711582
EVLVecVT) != MaskVT)
1572-
return DAG.UnrollVectorOp(Node);
1583+
return SDValue();
15731584

15741585
SDValue StepVec = DAG.getStepVector(DL, EVLVecVT);
15751586
SDValue SplatEVL = DAG.getSplat(EVLVecVT, DL, EVL);

0 commit comments

Comments
 (0)