@@ -822,7 +822,7 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
822822 // We have some custom DAG combine patterns for these nodes
823823 setTargetDAGCombine ({ISD::ADD, ISD::AND, ISD::EXTRACT_VECTOR_ELT, ISD::FADD,
824824 ISD::MUL, ISD::SHL, ISD::SREM, ISD::UREM, ISD::VSELECT,
825- ISD::BUILD_VECTOR});
825+ ISD::BUILD_VECTOR, ISD::ADDRSPACECAST });
826826
827827 // setcc for f16x2 and bf16x2 needs special handling to prevent
828828 // legalizer's attempt to scalarize it due to v2i1 not being legal.
@@ -5209,6 +5209,26 @@ PerformBUILD_VECTORCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
52095209 return DAG.getNode (ISD::BITCAST, DL, VT, PRMT);
52105210}
52115211
5212+ static SDValue combineADDRSPACECAST (SDNode *N,
5213+ TargetLowering::DAGCombinerInfo &DCI) {
5214+ auto *ASCN1 = cast<AddrSpaceCastSDNode>(N);
5215+
5216+ if (auto *ASCN2 = dyn_cast<AddrSpaceCastSDNode>(ASCN1->getOperand (0 ))) {
5217+ assert (ASCN2->getDestAddressSpace () == ASCN1->getSrcAddressSpace ());
5218+
5219+ // Fold asc[B -> A](asc[A -> B](x)) -> x
5220+ if (ASCN1->getDestAddressSpace () == ASCN2->getSrcAddressSpace ())
5221+ return ASCN2->getOperand (0 );
5222+
5223+ // Fold asc[B -> C](asc[A -> B](x)) -> asc[A -> C](x)
5224+ return DCI.DAG .getAddrSpaceCast (
5225+ SDLoc (N), N->getValueType (0 ), ASCN2->getOperand (0 ),
5226+ ASCN2->getSrcAddressSpace (), ASCN1->getDestAddressSpace ());
5227+ }
5228+
5229+ return SDValue ();
5230+ }
5231+
52125232SDValue NVPTXTargetLowering::PerformDAGCombine (SDNode *N,
52135233 DAGCombinerInfo &DCI) const {
52145234 CodeGenOptLevel OptLevel = getTargetMachine ().getOptLevel ();
@@ -5243,6 +5263,8 @@ SDValue NVPTXTargetLowering::PerformDAGCombine(SDNode *N,
52435263 return PerformVSELECTCombine (N, DCI);
52445264 case ISD::BUILD_VECTOR:
52455265 return PerformBUILD_VECTORCombine (N, DCI);
5266+ case ISD::ADDRSPACECAST:
5267+ return combineADDRSPACECAST (N, DCI);
52465268 }
52475269 return SDValue ();
52485270}
0 commit comments