Skip to content

Commit 3606876

Browse files
authored
[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.
1 parent 0fa0545 commit 3606876

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,12 @@ static void AddNodeIDCustom(FoldingSetNodeID &ID, const SDNode *N) {
954954
ID.AddInteger(M);
955955
break;
956956
}
957+
case ISD::ADDRSPACECAST: {
958+
const AddrSpaceCastSDNode *ASC = cast<AddrSpaceCastSDNode>(N);
959+
ID.AddInteger(ASC->getSrcAddressSpace());
960+
ID.AddInteger(ASC->getDestAddressSpace());
961+
break;
962+
}
957963
case ISD::TargetBlockAddress:
958964
case ISD::BlockAddress: {
959965
const BlockAddressSDNode *BA = cast<BlockAddressSDNode>(N);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llc < %s -O0 -debug-only=isel -o /dev/null 2>&1 | FileCheck %s
2+
3+
; REQUIRES: asserts
4+
5+
target triple = "nvptx64-nvidia-cuda"
6+
7+
;; Selection DAG CSE is hard to test since we run CSE/GVN on the IR before and
8+
;; after selection DAG ISel so most cases will be handled by one of these.
9+
define void @foo(ptr %p) {
10+
; CHECK-LABEL: Initial selection DAG
11+
;
12+
; CHECK: [[ASC:t[0-9]+]]{{.*}} = addrspacecast
13+
; CHECK: store{{.*}} [[ASC]]
14+
; CHECK: store{{.*}} [[ASC]]
15+
;
16+
; CHECK-LABEL: Optimized lowered selection
17+
;
18+
%a1 = addrspacecast ptr %p to ptr addrspace(5)
19+
%a2 = addrspacecast ptr %p to ptr addrspace(5)
20+
store i32 0, ptr addrspace(5) %a1
21+
store i32 0, ptr addrspace(5) %a2
22+
ret void
23+
}

0 commit comments

Comments
 (0)