Skip to content

Commit cdca049

Browse files
authored
DAG: Avoid introducing stack usage in vector->int bitcast int op promotion
(llvm#125636) Avoids stack usage in the v5i32 to i160 case for AMDGPU, which appears in fat pointer lowering.
1 parent 5afb31d commit cdca049

File tree

5 files changed

+868
-706
lines changed

5 files changed

+868
-706
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,29 @@ SDValue DAGTypeLegalizer::PromoteIntRes_BITCAST(SDNode *N) {
566566
}
567567
}
568568

569+
// TODO: Handle big endian
570+
if (!NOutVT.isVector() && InOp.getValueType().isVector() &&
571+
DAG.getDataLayout().isLittleEndian()) {
572+
// Pad the vector operand with undef and cast to a wider integer.
573+
EVT EltVT = InOp.getValueType().getVectorElementType();
574+
TypeSize EltSize = EltVT.getSizeInBits();
575+
TypeSize OutSize = NOutVT.getSizeInBits();
576+
577+
if (OutSize.hasKnownScalarFactor(EltSize)) {
578+
unsigned NumEltsWithPadding = OutSize.getKnownScalarFactor(EltSize);
579+
EVT WideVecVT =
580+
EVT::getVectorVT(*DAG.getContext(), EltVT, NumEltsWithPadding);
581+
582+
if (isTypeLegal(WideVecVT)) {
583+
SDValue Inserted = DAG.getNode(ISD::INSERT_SUBVECTOR, dl, WideVecVT,
584+
DAG.getUNDEF(WideVecVT), InOp,
585+
DAG.getVectorIdxConstant(0, dl));
586+
587+
return DAG.getNode(ISD::BITCAST, dl, NOutVT, Inserted);
588+
}
589+
}
590+
}
591+
569592
return DAG.getNode(ISD::ANY_EXTEND, dl, NOutVT,
570593
CreateStackStoreLoad(InOp, OutVT));
571594
}

0 commit comments

Comments
 (0)