Skip to content

Commit a629b50

Browse files
authored
Port NVPTXTargetLowering::LowerCONCAT_VECTORS to SelectionDAG (#120030)
Ports `NVPTXTargetLowering::LowerCONCAT_VECTORS` to `llvm/lib/CodeGen/SelectionDAG` as requested in #116695.
1 parent f1dad0b commit a629b50

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ class SelectionDAGLegalize {
191191
SDValue ExpandExtractFromVectorThroughStack(SDValue Op);
192192
SDValue ExpandInsertToVectorThroughStack(SDValue Op);
193193
SDValue ExpandVectorBuildThroughStack(SDNode* Node);
194+
SDValue ExpandConcatVectors(SDNode *Node);
194195

195196
SDValue ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP);
196197
SDValue ExpandConstant(ConstantSDNode *CP);
@@ -1525,6 +1526,27 @@ SDValue SelectionDAGLegalize::ExpandInsertToVectorThroughStack(SDValue Op) {
15251526
BaseVecAlignment);
15261527
}
15271528

1529+
SDValue SelectionDAGLegalize::ExpandConcatVectors(SDNode *Node) {
1530+
assert(Node->getOpcode() == ISD::CONCAT_VECTORS && "Unexpected opcode!");
1531+
SDLoc DL(Node);
1532+
SmallVector<SDValue, 16> Ops;
1533+
unsigned NumOperands = Node->getNumOperands();
1534+
MVT VectorIdxType = TLI.getVectorIdxTy(DAG.getDataLayout());
1535+
EVT VectorValueType = Node->getOperand(0).getValueType();
1536+
unsigned NumSubElem = VectorValueType.getVectorNumElements();
1537+
EVT ElementValueType = TLI.getTypeToTransformTo(
1538+
*DAG.getContext(), VectorValueType.getVectorElementType());
1539+
for (unsigned I = 0; I < NumOperands; ++I) {
1540+
SDValue SubOp = Node->getOperand(I);
1541+
for (unsigned Idx = 0; Idx < NumSubElem; ++Idx) {
1542+
Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ElementValueType,
1543+
SubOp,
1544+
DAG.getConstant(Idx, DL, VectorIdxType)));
1545+
}
1546+
}
1547+
return DAG.getBuildVector(Node->getValueType(0), DL, Ops);
1548+
}
1549+
15281550
SDValue SelectionDAGLegalize::ExpandVectorBuildThroughStack(SDNode* Node) {
15291551
assert((Node->getOpcode() == ISD::BUILD_VECTOR ||
15301552
Node->getOpcode() == ISD::CONCAT_VECTORS) &&
@@ -3383,7 +3405,12 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
33833405
Results.push_back(ExpandInsertToVectorThroughStack(SDValue(Node, 0)));
33843406
break;
33853407
case ISD::CONCAT_VECTORS:
3386-
Results.push_back(ExpandVectorBuildThroughStack(Node));
3408+
if (EVT VectorValueType = Node->getOperand(0).getValueType();
3409+
VectorValueType.isScalableVector() ||
3410+
TLI.isOperationExpand(ISD::EXTRACT_VECTOR_ELT, VectorValueType))
3411+
Results.push_back(ExpandVectorBuildThroughStack(Node));
3412+
else
3413+
Results.push_back(ExpandConcatVectors(Node));
33873414
break;
33883415
case ISD::SCALAR_TO_VECTOR:
33893416
Results.push_back(ExpandSCALAR_TO_VECTOR(Node));

0 commit comments

Comments
 (0)