@@ -989,6 +989,8 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
989989 setOperationAction (ISD::FLOG2, {MVT::v2f16, MVT::v2bf16}, Expand);
990990 }
991991
992+ setOperationAction (ISD::ADDRSPACECAST, {MVT::i32 , MVT::i64 }, Custom);
993+
992994 // No FPOW or FREM in PTX.
993995
994996 // Now deduce the information based on the above mentioned
@@ -2652,6 +2654,8 @@ NVPTXTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
26522654 return SDValue ();
26532655 case ISD::FRAMEADDR:
26542656 return SDValue ();
2657+ case ISD::ADDRSPACECAST:
2658+ return LowerADDRSPACECAST (Op, DAG);
26552659 case ISD::GlobalAddress:
26562660 return LowerGlobalAddress (Op, DAG);
26572661 case ISD::INTRINSIC_W_CHAIN:
@@ -2726,7 +2730,6 @@ NVPTXTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
27262730 case ISD::FMUL:
27272731 // Used only for bf16 on SM80, where we select fma for non-ftz operation
27282732 return PromoteBinOpIfF32FTZ (Op, DAG);
2729-
27302733 default :
27312734 llvm_unreachable (" Custom lowering not defined for operation" );
27322735 }
@@ -2767,6 +2770,22 @@ unsigned NVPTXTargetLowering::getJumpTableEncoding() const {
27672770 return MachineJumpTableInfo::EK_Inline;
27682771}
27692772
2773+ SDValue NVPTXTargetLowering::LowerADDRSPACECAST (SDValue Op, SelectionDAG &DAG) const {
2774+ SDLoc DL (Op);
2775+ AddrSpaceCastSDNode *N = cast<AddrSpaceCastSDNode>(Op.getNode ());
2776+
2777+ EVT OperandVT = Op.getOperand (0 ).getValueType ();
2778+ unsigned SrcAS = N->getSrcAddressSpace ();
2779+ EVT ResultVT = Op.getValueType ();
2780+ unsigned DestAS = N->getDestAddressSpace ();
2781+
2782+ if (SrcAS == llvm::ADDRESS_SPACE_GENERIC || DestAS == llvm::ADDRESS_SPACE_GENERIC)
2783+ return Op;
2784+
2785+ SDValue ToGeneric = DAG.getAddrSpaceCast (DL, OperandVT, Op.getOperand (0 ), SrcAS, llvm::ADDRESS_SPACE_GENERIC);
2786+ return DAG.getAddrSpaceCast (DL, ResultVT, ToGeneric, llvm::ADDRESS_SPACE_GENERIC, DestAS);
2787+ }
2788+
27702789// This function is almost a copy of SelectionDAG::expandVAArg().
27712790// The only diff is that this one produces loads from local address space.
27722791SDValue NVPTXTargetLowering::LowerVAARG (SDValue Op, SelectionDAG &DAG) const {
0 commit comments