diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 0dfd0302ae543..743ae4895a1b1 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(N); + ID.AddInteger(ASC->getSrcAddressSpace()); + ID.AddInteger(ASC->getDestAddressSpace()); + break; + } case ISD::TargetBlockAddress: case ISD::BlockAddress: { const BlockAddressSDNode *BA = cast(N); diff --git a/llvm/test/CodeGen/NVPTX/addrspacecast-cse.ll b/llvm/test/CodeGen/NVPTX/addrspacecast-cse.ll new file mode 100644 index 0000000000000..a26434bf8f194 --- /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 +}