[llvm] 3606876 - [SDAG] Fix CSE for ADDRSPACECAST nodes (#122912)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 20 09:09:26 PST 2025


Author: Alex MacLean
Date: 2025-01-20T09:09:22-08:00
New Revision: 3606876b67bbd42d6ee0e04548611834467af806

URL: https://github.com/llvm/llvm-project/commit/3606876b67bbd42d6ee0e04548611834467af806
DIFF: https://github.com/llvm/llvm-project/commit/3606876b67bbd42d6ee0e04548611834467af806.diff

LOG: [SDAG] Fix CSE for ADDRSPACECAST nodes (#122912)

Correct CSE in SelectionDAG can make DAG combining more effective and
reduces the size of the DAG and thus should improve compile time.

Added: 
    llvm/test/CodeGen/NVPTX/addrspacecast-cse.ll

Modified: 
    llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 0dfd0302ae5438..743ae4895a1b1c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -954,6 +954,12 @@ static void AddNodeIDCustom(FoldingSetNodeID &ID, const SDNode *N) {
       ID.AddInteger(M);
     break;
   }
+  case ISD::ADDRSPACECAST: {
+    const AddrSpaceCastSDNode *ASC = cast<AddrSpaceCastSDNode>(N);
+    ID.AddInteger(ASC->getSrcAddressSpace());
+    ID.AddInteger(ASC->getDestAddressSpace());
+    break;
+  }
   case ISD::TargetBlockAddress:
   case ISD::BlockAddress: {
     const BlockAddressSDNode *BA = cast<BlockAddressSDNode>(N);

diff  --git a/llvm/test/CodeGen/NVPTX/addrspacecast-cse.ll b/llvm/test/CodeGen/NVPTX/addrspacecast-cse.ll
new file mode 100644
index 00000000000000..a26434bf8f1944
--- /dev/null
+++ b/llvm/test/CodeGen/NVPTX/addrspacecast-cse.ll
@@ -0,0 +1,23 @@
+; RUN: llc < %s -O0 -debug-only=isel -o /dev/null 2>&1 | FileCheck %s
+
+; REQUIRES: asserts
+
+target triple = "nvptx64-nvidia-cuda"
+
+;; Selection DAG CSE is hard to test since we run CSE/GVN on the IR before and
+;; after selection DAG ISel so most cases will be handled by one of these.
+define void @foo(ptr %p) {
+; CHECK-LABEL: Initial selection DAG
+;
+; CHECK:  [[ASC:t[0-9]+]]{{.*}} = addrspacecast
+; CHECK:                          store{{.*}} [[ASC]]
+; CHECK:                          store{{.*}} [[ASC]]
+;
+; CHECK-LABEL: Optimized lowered selection
+;
+   %a1 = addrspacecast ptr %p to ptr addrspace(5)
+   %a2 = addrspacecast ptr %p to ptr addrspace(5)
+   store i32 0, ptr addrspace(5) %a1
+   store i32 0, ptr addrspace(5) %a2
+   ret void
+}


        


More information about the llvm-commits mailing list