[llvm] Nvptx port LowerBITCAST to SelectionDAG (PR #120903)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 23 09:32:39 PST 2024
================
@@ -910,6 +910,35 @@ SDValue DAGTypeLegalizer::CreateStackStoreLoad(SDValue Op,
return DAG.getLoad(DestVT, dl, Store, StackPtr, MachinePointerInfo(), Align);
}
+SDValue DAGTypeLegalizer::LowerBitcast(SDNode *Node) const {
+ assert(Node->getOpcode() == ISD::BITCAST && "Unexpected opcode!");
+ // Handle bitcasting from v2i8 without hitting the default promotion
+ // strategy which goes through stack memory.
+ EVT FromVT = Node->getOperand(0)->getValueType(0);
+ if (FromVT != MVT::v2i8)
+ return SDValue();
+
+ // Pack vector elements into i16 and bitcast to final type
+ SDLoc DL(Node);
+ SDValue Vec0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8,
+ Node->getOperand(0), DAG.getIntPtrConstant(0, DL));
+ SDValue Vec1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8,
+ Node->getOperand(0), DAG.getIntPtrConstant(1, DL));
+
+ SDValue Extend0 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec0);
+ SDValue Extend1 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec1);
+
+ EVT ShiftAmtTy =
+ TLI.getShiftAmountTy(Extend1.getValueType(), DAG.getDataLayout());
+ SDValue ShiftConst = DAG.getShiftAmountConstant(8, ShiftAmtTy, DL);
----------------
GrumpyPigSkin wrote:
Thanks :) I have updated the code
https://github.com/llvm/llvm-project/pull/120903
More information about the llvm-commits
mailing list