[llvm] [NVPTX] Add some basic folds for ADDRSPACECAST (PR #129157)

Alex MacLean via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 27 16:25:39 PST 2025


================
@@ -5209,6 +5209,26 @@ PerformBUILD_VECTORCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) {
   return DAG.getNode(ISD::BITCAST, DL, VT, PRMT);
 }
 
+static SDValue combineADDRSPACECAST(SDNode *N,
+                                    TargetLowering::DAGCombinerInfo &DCI) {
+  auto *ASCN1 = cast<AddrSpaceCastSDNode>(N);
+
+  if (auto *ASCN2 = dyn_cast<AddrSpaceCastSDNode>(ASCN1->getOperand(0))) {
+    assert(ASCN2->getDestAddressSpace() == ASCN1->getSrcAddressSpace());
+
+    // Fold asc[B -> A](asc[A -> B](x)) -> x
+    if (ASCN1->getDestAddressSpace() == ASCN2->getSrcAddressSpace())
+      return ASCN2->getOperand(0);
----------------
AlexMaclean wrote:

We do insert these casts, but they really only serve as a hint to InferAddressSpaces, by the time we get to SelectionDAG there won't be any future passes that would use this hint. 

https://github.com/llvm/llvm-project/pull/129157


More information about the llvm-commits mailing list