1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 4
2 ; RUN: opt < %s -passes=amdgpu-sw-lower-lds -S -mtriple=amdgcn-amd-amdhsa | FileCheck %s
4 ; Test to check if static and dynamic LDS accesses are lowered correctly in kernel.
5 @lds_1 = internal addrspace(3) global [1 x i8] poison, align 4
6 @lds_2 = internal addrspace(3) global [1 x i32] poison, align 8
7 @lds_3 = external addrspace(3) global [0 x i8], align 4
8 @lds_4 = external addrspace(3) global [0 x i8], align 8
11 ; CHECK: @llvm.amdgcn.sw.lds.k0 = internal addrspace(3) global ptr poison, no_sanitize_address, align 8, !absolute_symbol [[META0:![0-9]+]]
12 ; CHECK: @llvm.amdgcn.k0.dynlds = external addrspace(3) global [0 x i8], no_sanitize_address, align 8, !absolute_symbol [[META1:![0-9]+]]
13 ; CHECK: @llvm.amdgcn.sw.lds.k0.md = internal addrspace(1) global %llvm.amdgcn.sw.lds.k0.md.type { %llvm.amdgcn.sw.lds.k0.md.item { i32 0, i32 8, i32 32 }, %llvm.amdgcn.sw.lds.k0.md.item { i32 32, i32 1, i32 32 }, %llvm.amdgcn.sw.lds.k0.md.item { i32 64, i32 4, i32 32 }, %llvm.amdgcn.sw.lds.k0.md.item { i32 96, i32 0, i32 32 }, %llvm.amdgcn.sw.lds.k0.md.item { i32 128, i32 0, i32 32 } }, no_sanitize_address
15 define amdgpu_kernel void @k0() sanitize_address {
16 ; CHECK-LABEL: define amdgpu_kernel void @k0(
17 ; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
19 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @llvm.amdgcn.workitem.id.x()
20 ; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.amdgcn.workitem.id.y()
21 ; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.amdgcn.workitem.id.z()
22 ; CHECK-NEXT: [[TMP3:%.*]] = or i32 [[TMP0]], [[TMP1]]
23 ; CHECK-NEXT: [[TMP4:%.*]] = or i32 [[TMP3]], [[TMP2]]
24 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[TMP4]], 0
25 ; CHECK-NEXT: br i1 [[TMP5]], label [[MALLOC:%.*]], label [[TMP21:%.*]]
27 ; CHECK-NEXT: [[TMP9:%.*]] = load i32, ptr addrspace(1) getelementptr inbounds ([[LLVM_AMDGCN_SW_LDS_K0_MD_TYPE:%.*]], ptr addrspace(1) @llvm.amdgcn.sw.lds.k0.md, i32 0, i32 2, i32 0), align 4
28 ; CHECK-NEXT: [[TMP7:%.*]] = load i32, ptr addrspace(1) getelementptr inbounds ([[LLVM_AMDGCN_SW_LDS_K0_MD_TYPE]], ptr addrspace(1) @llvm.amdgcn.sw.lds.k0.md, i32 0, i32 2, i32 2), align 4
29 ; CHECK-NEXT: [[TMP8:%.*]] = add i32 [[TMP9]], [[TMP7]]
30 ; CHECK-NEXT: [[TMP6:%.*]] = call ptr addrspace(4) @llvm.amdgcn.implicitarg.ptr()
31 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds ptr addrspace(4), ptr addrspace(4) [[TMP6]], i64 15
32 ; CHECK-NEXT: store i32 [[TMP8]], ptr addrspace(1) getelementptr inbounds ([[LLVM_AMDGCN_SW_LDS_K0_MD_TYPE]], ptr addrspace(1) @llvm.amdgcn.sw.lds.k0.md, i32 0, i32 3, i32 0), align 4
33 ; CHECK-NEXT: [[TMP11:%.*]] = load i32, ptr addrspace(4) [[TMP10]], align 4
34 ; CHECK-NEXT: store i32 [[TMP11]], ptr addrspace(1) getelementptr inbounds ([[LLVM_AMDGCN_SW_LDS_K0_MD_TYPE]], ptr addrspace(1) @llvm.amdgcn.sw.lds.k0.md, i32 0, i32 3, i32 1), align 4
35 ; CHECK-NEXT: [[TMP12:%.*]] = add i32 [[TMP11]], 7
36 ; CHECK-NEXT: [[TMP13:%.*]] = udiv i32 [[TMP12]], 8
37 ; CHECK-NEXT: [[TMP14:%.*]] = mul i32 [[TMP13]], 8
38 ; CHECK-NEXT: store i32 [[TMP14]], ptr addrspace(1) getelementptr inbounds ([[LLVM_AMDGCN_SW_LDS_K0_MD_TYPE]], ptr addrspace(1) @llvm.amdgcn.sw.lds.k0.md, i32 0, i32 3, i32 2), align 4
39 ; CHECK-NEXT: [[TMP15:%.*]] = add i32 [[TMP8]], [[TMP14]]
40 ; CHECK-NEXT: store i32 [[TMP15]], ptr addrspace(1) getelementptr inbounds ([[LLVM_AMDGCN_SW_LDS_K0_MD_TYPE]], ptr addrspace(1) @llvm.amdgcn.sw.lds.k0.md, i32 0, i32 4, i32 0), align 4
41 ; CHECK-NEXT: [[TMP31:%.*]] = load i32, ptr addrspace(4) [[TMP10]], align 4
42 ; CHECK-NEXT: store i32 [[TMP31]], ptr addrspace(1) getelementptr inbounds ([[LLVM_AMDGCN_SW_LDS_K0_MD_TYPE]], ptr addrspace(1) @llvm.amdgcn.sw.lds.k0.md, i32 0, i32 4, i32 1), align 4
43 ; CHECK-NEXT: [[TMP17:%.*]] = add i32 [[TMP31]], 7
44 ; CHECK-NEXT: [[TMP18:%.*]] = udiv i32 [[TMP17]], 8
45 ; CHECK-NEXT: [[TMP19:%.*]] = mul i32 [[TMP18]], 8
46 ; CHECK-NEXT: store i32 [[TMP19]], ptr addrspace(1) getelementptr inbounds ([[LLVM_AMDGCN_SW_LDS_K0_MD_TYPE]], ptr addrspace(1) @llvm.amdgcn.sw.lds.k0.md, i32 0, i32 4, i32 2), align 4
47 ; CHECK-NEXT: [[TMP32:%.*]] = add i32 [[TMP15]], [[TMP19]]
48 ; CHECK-NEXT: [[TMP30:%.*]] = zext i32 [[TMP32]] to i64
49 ; CHECK-NEXT: [[TMP22:%.*]] = call ptr @llvm.returnaddress(i32 0)
50 ; CHECK-NEXT: [[TMP23:%.*]] = ptrtoint ptr [[TMP22]] to i64
51 ; CHECK-NEXT: [[TMP39:%.*]] = call i64 @__asan_malloc_impl(i64 [[TMP30]], i64 [[TMP23]])
52 ; CHECK-NEXT: [[TMP20:%.*]] = inttoptr i64 [[TMP39]] to ptr addrspace(1)
53 ; CHECK-NEXT: store ptr addrspace(1) [[TMP20]], ptr addrspace(3) @llvm.amdgcn.sw.lds.k0, align 8
54 ; CHECK-NEXT: [[TMP40:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[TMP20]], i64 8
55 ; CHECK-NEXT: [[TMP41:%.*]] = ptrtoint ptr addrspace(1) [[TMP40]] to i64
56 ; CHECK-NEXT: call void @__asan_poison_region(i64 [[TMP41]], i64 24)
57 ; CHECK-NEXT: [[TMP57:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[TMP20]], i64 33
58 ; CHECK-NEXT: [[TMP111:%.*]] = ptrtoint ptr addrspace(1) [[TMP57]] to i64
59 ; CHECK-NEXT: call void @__asan_poison_region(i64 [[TMP111]], i64 31)
60 ; CHECK-NEXT: [[TMP112:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[TMP20]], i64 68
61 ; CHECK-NEXT: [[TMP113:%.*]] = ptrtoint ptr addrspace(1) [[TMP112]] to i64
62 ; CHECK-NEXT: call void @__asan_poison_region(i64 [[TMP113]], i64 28)
63 ; CHECK-NEXT: br label [[TMP21]]
65 ; CHECK-NEXT: [[XYZCOND:%.*]] = phi i1 [ false, [[WID:%.*]] ], [ true, [[MALLOC]] ]
66 ; CHECK-NEXT: call void @llvm.amdgcn.s.barrier()
67 ; CHECK-NEXT: [[TMP35:%.*]] = load ptr addrspace(1), ptr addrspace(3) @llvm.amdgcn.sw.lds.k0, align 8
68 ; CHECK-NEXT: [[TMP24:%.*]] = load i32, ptr addrspace(1) getelementptr inbounds ([[LLVM_AMDGCN_SW_LDS_K0_MD_TYPE]], ptr addrspace(1) @llvm.amdgcn.sw.lds.k0.md, i32 0, i32 1, i32 0), align 4
69 ; CHECK-NEXT: [[TMP25:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @llvm.amdgcn.sw.lds.k0, i32 [[TMP24]]
70 ; CHECK-NEXT: [[TMP26:%.*]] = load i32, ptr addrspace(1) getelementptr inbounds ([[LLVM_AMDGCN_SW_LDS_K0_MD_TYPE]], ptr addrspace(1) @llvm.amdgcn.sw.lds.k0.md, i32 0, i32 2, i32 0), align 4
71 ; CHECK-NEXT: [[TMP27:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @llvm.amdgcn.sw.lds.k0, i32 [[TMP26]]
72 ; CHECK-NEXT: [[TMP28:%.*]] = load i32, ptr addrspace(1) getelementptr inbounds ([[LLVM_AMDGCN_SW_LDS_K0_MD_TYPE]], ptr addrspace(1) @llvm.amdgcn.sw.lds.k0.md, i32 0, i32 3, i32 0), align 4
73 ; CHECK-NEXT: [[TMP29:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @llvm.amdgcn.sw.lds.k0, i32 [[TMP28]]
74 ; CHECK-NEXT: [[TMP33:%.*]] = load i32, ptr addrspace(1) getelementptr inbounds ([[LLVM_AMDGCN_SW_LDS_K0_MD_TYPE]], ptr addrspace(1) @llvm.amdgcn.sw.lds.k0.md, i32 0, i32 4, i32 0), align 4
75 ; CHECK-NEXT: [[TMP34:%.*]] = getelementptr inbounds i8, ptr addrspace(3) @llvm.amdgcn.sw.lds.k0, i32 [[TMP33]]
76 ; CHECK-NEXT: call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.k0.dynlds) ]
77 ; CHECK-NEXT: [[TMP42:%.*]] = ptrtoint ptr addrspace(3) [[TMP25]] to i32
78 ; CHECK-NEXT: [[TMP43:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[TMP35]], i32 [[TMP42]]
79 ; CHECK-NEXT: [[TMP44:%.*]] = ptrtoint ptr addrspace(1) [[TMP43]] to i64
80 ; CHECK-NEXT: [[TMP45:%.*]] = lshr i64 [[TMP44]], 3
81 ; CHECK-NEXT: [[TMP46:%.*]] = add i64 [[TMP45]], 2147450880
82 ; CHECK-NEXT: [[TMP47:%.*]] = inttoptr i64 [[TMP46]] to ptr
83 ; CHECK-NEXT: [[TMP48:%.*]] = load i8, ptr [[TMP47]], align 1
84 ; CHECK-NEXT: [[TMP49:%.*]] = icmp ne i8 [[TMP48]], 0
85 ; CHECK-NEXT: [[TMP50:%.*]] = and i64 [[TMP44]], 7
86 ; CHECK-NEXT: [[TMP51:%.*]] = trunc i64 [[TMP50]] to i8
87 ; CHECK-NEXT: [[TMP52:%.*]] = icmp sge i8 [[TMP51]], [[TMP48]]
88 ; CHECK-NEXT: [[TMP53:%.*]] = and i1 [[TMP49]], [[TMP52]]
89 ; CHECK-NEXT: [[TMP54:%.*]] = call i64 @llvm.amdgcn.ballot.i64(i1 [[TMP53]])
90 ; CHECK-NEXT: [[TMP55:%.*]] = icmp ne i64 [[TMP54]], 0
91 ; CHECK-NEXT: br i1 [[TMP55]], label [[ASAN_REPORT:%.*]], label [[TMP58:%.*]], !prof [[PROF2:![0-9]+]]
93 ; CHECK-NEXT: br i1 [[TMP53]], label [[TMP56:%.*]], label [[CONDFREE:%.*]]
95 ; CHECK-NEXT: call void @__asan_report_store1(i64 [[TMP44]]) #[[ATTR6:[0-9]+]]
96 ; CHECK-NEXT: call void @llvm.amdgcn.unreachable()
97 ; CHECK-NEXT: br label [[CONDFREE]]
99 ; CHECK-NEXT: br label [[TMP58]]
101 ; CHECK-NEXT: store i8 7, ptr addrspace(1) [[TMP43]], align 4
102 ; CHECK-NEXT: [[TMP59:%.*]] = ptrtoint ptr addrspace(3) [[TMP27]] to i32
103 ; CHECK-NEXT: [[TMP60:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[TMP35]], i32 [[TMP59]]
104 ; CHECK-NEXT: [[TMP61:%.*]] = ptrtoint ptr addrspace(1) [[TMP60]] to i64
105 ; CHECK-NEXT: [[TMP62:%.*]] = lshr i64 [[TMP61]], 3
106 ; CHECK-NEXT: [[TMP63:%.*]] = add i64 [[TMP62]], 2147450880
107 ; CHECK-NEXT: [[TMP64:%.*]] = inttoptr i64 [[TMP63]] to ptr
108 ; CHECK-NEXT: [[TMP65:%.*]] = load i8, ptr [[TMP64]], align 1
109 ; CHECK-NEXT: [[TMP66:%.*]] = icmp ne i8 [[TMP65]], 0
110 ; CHECK-NEXT: [[TMP67:%.*]] = and i64 [[TMP61]], 7
111 ; CHECK-NEXT: [[TMP68:%.*]] = add i64 [[TMP67]], 3
112 ; CHECK-NEXT: [[TMP69:%.*]] = trunc i64 [[TMP68]] to i8
113 ; CHECK-NEXT: [[TMP70:%.*]] = icmp sge i8 [[TMP69]], [[TMP65]]
114 ; CHECK-NEXT: [[TMP71:%.*]] = and i1 [[TMP66]], [[TMP70]]
115 ; CHECK-NEXT: [[TMP72:%.*]] = call i64 @llvm.amdgcn.ballot.i64(i1 [[TMP71]])
116 ; CHECK-NEXT: [[TMP73:%.*]] = icmp ne i64 [[TMP72]], 0
117 ; CHECK-NEXT: br i1 [[TMP73]], label [[ASAN_REPORT1:%.*]], label [[TMP76:%.*]], !prof [[PROF2]]
118 ; CHECK: asan.report1:
119 ; CHECK-NEXT: br i1 [[TMP71]], label [[TMP74:%.*]], label [[TMP75:%.*]]
121 ; CHECK-NEXT: call void @__asan_report_store4(i64 [[TMP61]]) #[[ATTR6]]
122 ; CHECK-NEXT: call void @llvm.amdgcn.unreachable()
123 ; CHECK-NEXT: br label [[TMP75]]
125 ; CHECK-NEXT: br label [[TMP76]]
127 ; CHECK-NEXT: store i32 8, ptr addrspace(1) [[TMP60]], align 8
128 ; CHECK-NEXT: [[TMP77:%.*]] = ptrtoint ptr addrspace(3) [[TMP29]] to i32
129 ; CHECK-NEXT: [[TMP78:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[TMP35]], i32 [[TMP77]]
130 ; CHECK-NEXT: [[TMP79:%.*]] = ptrtoint ptr addrspace(1) [[TMP78]] to i64
131 ; CHECK-NEXT: [[TMP80:%.*]] = lshr i64 [[TMP79]], 3
132 ; CHECK-NEXT: [[TMP81:%.*]] = add i64 [[TMP80]], 2147450880
133 ; CHECK-NEXT: [[TMP82:%.*]] = inttoptr i64 [[TMP81]] to ptr
134 ; CHECK-NEXT: [[TMP83:%.*]] = load i8, ptr [[TMP82]], align 1
135 ; CHECK-NEXT: [[TMP84:%.*]] = icmp ne i8 [[TMP83]], 0
136 ; CHECK-NEXT: [[TMP85:%.*]] = and i64 [[TMP79]], 7
137 ; CHECK-NEXT: [[TMP86:%.*]] = trunc i64 [[TMP85]] to i8
138 ; CHECK-NEXT: [[TMP87:%.*]] = icmp sge i8 [[TMP86]], [[TMP83]]
139 ; CHECK-NEXT: [[TMP88:%.*]] = and i1 [[TMP84]], [[TMP87]]
140 ; CHECK-NEXT: [[TMP89:%.*]] = call i64 @llvm.amdgcn.ballot.i64(i1 [[TMP88]])
141 ; CHECK-NEXT: [[TMP90:%.*]] = icmp ne i64 [[TMP89]], 0
142 ; CHECK-NEXT: br i1 [[TMP90]], label [[ASAN_REPORT2:%.*]], label [[TMP93:%.*]], !prof [[PROF2]]
143 ; CHECK: asan.report2:
144 ; CHECK-NEXT: br i1 [[TMP88]], label [[TMP91:%.*]], label [[TMP92:%.*]]
146 ; CHECK-NEXT: call void @__asan_report_store1(i64 [[TMP79]]) #[[ATTR6]]
147 ; CHECK-NEXT: call void @llvm.amdgcn.unreachable()
148 ; CHECK-NEXT: br label [[TMP92]]
150 ; CHECK-NEXT: br label [[TMP93]]
152 ; CHECK-NEXT: store i8 7, ptr addrspace(1) [[TMP78]], align 4
153 ; CHECK-NEXT: [[TMP94:%.*]] = ptrtoint ptr addrspace(3) [[TMP34]] to i32
154 ; CHECK-NEXT: [[TMP95:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[TMP35]], i32 [[TMP94]]
155 ; CHECK-NEXT: [[TMP96:%.*]] = ptrtoint ptr addrspace(1) [[TMP95]] to i64
156 ; CHECK-NEXT: [[TMP97:%.*]] = lshr i64 [[TMP96]], 3
157 ; CHECK-NEXT: [[TMP98:%.*]] = add i64 [[TMP97]], 2147450880
158 ; CHECK-NEXT: [[TMP99:%.*]] = inttoptr i64 [[TMP98]] to ptr
159 ; CHECK-NEXT: [[TMP100:%.*]] = load i8, ptr [[TMP99]], align 1
160 ; CHECK-NEXT: [[TMP101:%.*]] = icmp ne i8 [[TMP100]], 0
161 ; CHECK-NEXT: [[TMP102:%.*]] = and i64 [[TMP96]], 7
162 ; CHECK-NEXT: [[TMP103:%.*]] = trunc i64 [[TMP102]] to i8
163 ; CHECK-NEXT: [[TMP104:%.*]] = icmp sge i8 [[TMP103]], [[TMP100]]
164 ; CHECK-NEXT: [[TMP105:%.*]] = and i1 [[TMP101]], [[TMP104]]
165 ; CHECK-NEXT: [[TMP106:%.*]] = call i64 @llvm.amdgcn.ballot.i64(i1 [[TMP105]])
166 ; CHECK-NEXT: [[TMP107:%.*]] = icmp ne i64 [[TMP106]], 0
167 ; CHECK-NEXT: br i1 [[TMP107]], label [[ASAN_REPORT3:%.*]], label [[TMP110:%.*]], !prof [[PROF2]]
168 ; CHECK: asan.report3:
169 ; CHECK-NEXT: br i1 [[TMP105]], label [[TMP108:%.*]], label [[TMP109:%.*]]
171 ; CHECK-NEXT: call void @__asan_report_store1(i64 [[TMP96]]) #[[ATTR6]]
172 ; CHECK-NEXT: call void @llvm.amdgcn.unreachable()
173 ; CHECK-NEXT: br label [[TMP109]]
175 ; CHECK-NEXT: br label [[TMP110]]
177 ; CHECK-NEXT: store i8 8, ptr addrspace(1) [[TMP95]], align 8
178 ; CHECK-NEXT: br label [[CONDFREE1:%.*]]
180 ; CHECK-NEXT: call void @llvm.amdgcn.s.barrier()
181 ; CHECK-NEXT: br i1 [[XYZCOND]], label [[FREE:%.*]], label [[END:%.*]]
183 ; CHECK-NEXT: [[TMP36:%.*]] = call ptr @llvm.returnaddress(i32 0)
184 ; CHECK-NEXT: [[TMP37:%.*]] = ptrtoint ptr [[TMP36]] to i64
185 ; CHECK-NEXT: [[TMP38:%.*]] = ptrtoint ptr addrspace(1) [[TMP35]] to i64
186 ; CHECK-NEXT: call void @__asan_free_impl(i64 [[TMP38]], i64 [[TMP37]])
187 ; CHECK-NEXT: br label [[END]]
189 ; CHECK-NEXT: ret void
191 store i8 7, ptr addrspace(3) @lds_1, align 4
192 store i32 8, ptr addrspace(3) @lds_2, align 8
193 store i8 7, ptr addrspace(3) @lds_3, align 4
194 store i8 8, ptr addrspace(3) @lds_4, align 8
198 !llvm.module.flags = !{!0}
199 !0 = !{i32 4, !"nosanitize_address", i32 1}
202 ; CHECK: attributes #[[ATTR0]] = { sanitize_address "amdgpu-lds-size"="8,8" }
203 ; CHECK: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(none) }
204 ; CHECK: attributes #[[ATTR2:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
205 ; CHECK: attributes #[[ATTR3:[0-9]+]] = { convergent nocallback nofree nounwind willreturn }
206 ; CHECK: attributes #[[ATTR4:[0-9]+]] = { convergent nocallback nofree nounwind willreturn memory(none) }
207 ; CHECK: attributes #[[ATTR5:[0-9]+]] = { convergent nocallback nofree nounwind }
208 ; CHECK: attributes #[[ATTR6]] = { nomerge }
210 ; CHECK: [[META0]] = !{i32 0, i32 1}
211 ; CHECK: [[META1]] = !{i32 8, i32 9}
212 ; CHECK: [[PROF2]] = !{!"branch_weights", i32 1, i32 1048575}