Skip to content

Commit 69b0a47

Browse files
[AMDGPU] Precommit test for 160181
1 parent 4e404d0 commit 69b0a47

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals
2+
; RUN: opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds --amdgpu-lower-module-lds-strategy=module < %s | FileCheck %s
3+
4+
; Regression test for issue 160181
5+
; One variable is chosen to be assigned at zero. Here, that's @both
6+
; Then other variables should be allocated at fixed offsets from that provided
7+
; they are allocated by all the other kernels that presently allocate the
8+
; variable at address zero.
9+
; The failure mode was in that second check - variables could be added to
10+
; the module scope zero address struct even when some of the kernels allocating
11+
; that struct do not need the additional variable.
12+
13+
; With current llvm, all three of these integers are put in the module scope struct, when
14+
; neither kern_one or kern_two access all three.
15+
16+
@both = addrspace(3) global i32 poison
17+
@both_second = addrspace(3) global i16 poison ; a second field in the module struct
18+
@one = addrspace(3) global i32 poison
19+
@two = addrspace(3) global i32 poison
20+
21+
22+
;.
23+
; CHECK: @llvm.amdgcn.module.lds = internal addrspace(3) global %llvm.amdgcn.module.lds.t poison, align 4, !absolute_symbol [[META0:![0-9]+]]
24+
; CHECK: @llvm.compiler.used = appending addrspace(1) global [1 x ptr] [ptr addrspacecast (ptr addrspace(3) @llvm.amdgcn.module.lds to ptr)], section "llvm.metadata"
25+
;.
26+
define void @func_one() {
27+
; CHECK-LABEL: define {{[^@]+}}@func_one() {
28+
; CHECK-NEXT: [[VAL0:%.*]] = load i32, ptr addrspace(3) @llvm.amdgcn.module.lds, align 4, !noalias [[META1:![0-9]+]]
29+
; CHECK-NEXT: store i32 [[VAL0]], ptr addrspace(3) getelementptr inbounds ([[LLVM_AMDGCN_MODULE_LDS_T:%.*]], ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 1), align 4, !noalias [[META18:![0-9]+]]
30+
; CHECK-NEXT: store i16 10, ptr addrspace(3) getelementptr inbounds ([[LLVM_AMDGCN_MODULE_LDS_T]], ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 3), align 4, !noalias [[META23:![0-9]+]]
31+
; CHECK-NEXT: ret void
32+
;
33+
%val0 = load i32, ptr addrspace(3) @both
34+
store i32 %val0, ptr addrspace(3) @one
35+
store i16 10, ptr addrspace(3) @both_second
36+
ret void
37+
}
38+
39+
define amdgpu_kernel void @kern_one() {
40+
; CHECK-LABEL: define {{[^@]+}}@kern_one
41+
; CHECK-SAME: () #[[ATTR0:[0-9]+]] {
42+
; CHECK-NEXT: entry:
43+
; CHECK-NEXT: call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.module.lds) ], !noalias [[META24:![0-9]+]]
44+
; CHECK-NEXT: call void @func_one()
45+
; CHECK-NEXT: ret void
46+
;
47+
entry:
48+
call void @func_one()
49+
ret void
50+
}
51+
52+
define void @func_two() {
53+
; CHECK-LABEL: define {{[^@]+}}@func_two() {
54+
; CHECK-NEXT: [[VAL0:%.*]] = load i32, ptr addrspace(3) @llvm.amdgcn.module.lds, align 4, !noalias [[META1]]
55+
; CHECK-NEXT: store i32 [[VAL0]], ptr addrspace(3) getelementptr inbounds ([[LLVM_AMDGCN_MODULE_LDS_T:%.*]], ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 2), align 4, !noalias [[META25:![0-9]+]]
56+
; CHECK-NEXT: store i16 20, ptr addrspace(3) getelementptr inbounds ([[LLVM_AMDGCN_MODULE_LDS_T]], ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 3), align 4, !noalias [[META23]]
57+
; CHECK-NEXT: ret void
58+
;
59+
%val0 = load i32, ptr addrspace(3) @both
60+
store i32 %val0, ptr addrspace(3) @two
61+
store i16 20, ptr addrspace(3) @both_second
62+
ret void
63+
}
64+
65+
define amdgpu_kernel void @kern_two() {
66+
; CHECK-LABEL: define {{[^@]+}}@kern_two
67+
; CHECK-SAME: () #[[ATTR0]] {
68+
; CHECK-NEXT: entry:
69+
; CHECK-NEXT: call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.module.lds) ], !alias.scope [[META26:![0-9]+]], !noalias [[META27:![0-9]+]]
70+
; CHECK-NEXT: call void @func_two()
71+
; CHECK-NEXT: ret void
72+
;
73+
entry:
74+
call void @func_two()
75+
ret void
76+
}
77+
78+
; Unrelated to the bug at hand, but if a variable is only
79+
; reachable from a single kernel, it gets allocated to a fixed
80+
; address independent of the module scope struct. This kernel
81+
; means the key variables miss that optimisation while @both
82+
; remains the best candidate for address zero allocation.
83+
define void @func_block_direct_allocation() {
84+
; CHECK-LABEL: define {{[^@]+}}@func_block_direct_allocation() {
85+
; CHECK-NEXT: [[VAL1:%.*]] = load i32, ptr addrspace(3) getelementptr inbounds ([[LLVM_AMDGCN_MODULE_LDS_T:%.*]], ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 1), align 4, !noalias [[META18]]
86+
; CHECK-NEXT: [[VAL2:%.*]] = load i32, ptr addrspace(3) getelementptr inbounds ([[LLVM_AMDGCN_MODULE_LDS_T]], ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 2), align 4, !noalias [[META25]]
87+
; CHECK-NEXT: [[SUM:%.*]] = add i32 [[VAL1]], [[VAL2]]
88+
; CHECK-NEXT: store i32 [[SUM]], ptr addrspace(3) @llvm.amdgcn.module.lds, align 4, !noalias [[META1]]
89+
; CHECK-NEXT: store i16 30, ptr addrspace(3) getelementptr inbounds ([[LLVM_AMDGCN_MODULE_LDS_T]], ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 3), align 4, !noalias [[META23]]
90+
; CHECK-NEXT: ret void
91+
;
92+
%val1 = load i32, ptr addrspace(3) @one
93+
%val2 = load i32, ptr addrspace(3) @two
94+
%sum = add i32 %val1, %val2
95+
store i32 %sum, ptr addrspace(3) @both
96+
store i16 30, ptr addrspace(3) @both_second
97+
ret void
98+
}
99+
100+
define amdgpu_kernel void @kern_block_direct_allocation() {
101+
; CHECK-LABEL: define {{[^@]+}}@kern_block_direct_allocation
102+
; CHECK-SAME: () #[[ATTR0]] {
103+
; CHECK-NEXT: call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.module.lds) ]
104+
; CHECK-NEXT: call void @func_block_direct_allocation()
105+
; CHECK-NEXT: call void @func_one()
106+
; CHECK-NEXT: call void @func_two()
107+
; CHECK-NEXT: ret void
108+
;
109+
call void @func_block_direct_allocation()
110+
call void @func_one()
111+
call void @func_two()
112+
ret void
113+
}
114+
;.
115+
; CHECK: attributes #[[ATTR0]] = { "amdgpu-lds-size"="16" }
116+
; CHECK: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(none) }
117+
;.
118+
; CHECK: [[META0]] = !{i32 0, i32 1}
119+
; CHECK: [[META1]] = !{[[META2:![0-9]+]], [[META4:![0-9]+]], [[META5:![0-9]+]], [[META6:![0-9]+]], [[META8:![0-9]+]], [[META9:![0-9]+]], [[META10:![0-9]+]], [[META12:![0-9]+]], [[META13:![0-9]+]], [[META14:![0-9]+]], [[META16:![0-9]+]], [[META17:![0-9]+]]}
120+
; CHECK: [[META2]] = distinct !{[[META2]], [[META3:![0-9]+]]}
121+
; CHECK: [[META3]] = distinct !{[[META3]]}
122+
; CHECK: [[META4]] = distinct !{[[META4]], [[META3]]}
123+
; CHECK: [[META5]] = distinct !{[[META5]], [[META3]]}
124+
; CHECK: [[META6]] = distinct !{[[META6]], [[META7:![0-9]+]]}
125+
; CHECK: [[META7]] = distinct !{[[META7]]}
126+
; CHECK: [[META8]] = distinct !{[[META8]], [[META7]]}
127+
; CHECK: [[META9]] = distinct !{[[META9]], [[META7]]}
128+
; CHECK: [[META10]] = distinct !{[[META10]], [[META11:![0-9]+]]}
129+
; CHECK: [[META11]] = distinct !{[[META11]]}
130+
; CHECK: [[META12]] = distinct !{[[META12]], [[META11]]}
131+
; CHECK: [[META13]] = distinct !{[[META13]], [[META11]]}
132+
; CHECK: [[META14]] = distinct !{[[META14]], [[META15:![0-9]+]]}
133+
; CHECK: [[META15]] = distinct !{[[META15]]}
134+
; CHECK: [[META16]] = distinct !{[[META16]], [[META15]]}
135+
; CHECK: [[META17]] = distinct !{[[META17]], [[META15]]}
136+
; CHECK: [[META18]] = !{[[META19:![0-9]+]], [[META2]], [[META5]], [[META20:![0-9]+]], [[META6]], [[META9]], [[META21:![0-9]+]], [[META10]], [[META13]], [[META22:![0-9]+]], [[META14]], [[META17]]}
137+
; CHECK: [[META19]] = distinct !{[[META19]], [[META3]]}
138+
; CHECK: [[META20]] = distinct !{[[META20]], [[META7]]}
139+
; CHECK: [[META21]] = distinct !{[[META21]], [[META11]]}
140+
; CHECK: [[META22]] = distinct !{[[META22]], [[META15]]}
141+
; CHECK: [[META23]] = !{[[META19]], [[META4]], [[META5]], [[META20]], [[META8]], [[META9]], [[META21]], [[META12]], [[META13]], [[META22]], [[META16]], [[META17]]}
142+
; CHECK: [[META24]] = !{[[META10]], [[META12]], [[META13]], [[META14]], [[META16]], [[META17]]}
143+
; CHECK: [[META25]] = !{[[META19]], [[META2]], [[META4]], [[META20]], [[META6]], [[META8]], [[META21]], [[META10]], [[META12]], [[META22]], [[META14]], [[META16]]}
144+
; CHECK: [[META26]] = !{[[META22]]}
145+
; CHECK: [[META27]] = !{[[META14]], [[META16]], [[META17]]}
146+
;.

0 commit comments

Comments
 (0)