summaryrefslogtreecommitdiffstats
path: root/llvm/test/CodeGen/AMDGPU/hsa-metadata-hostcall-v3.ll
blob: 734ad53e9be0d4485c8c985c78a81186c8f55f29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 --amdhsa-code-object-version=3 -filetype=obj -o - < %s | llvm-readelf --notes - | FileCheck %s
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 --amdhsa-code-object-version=3 < %s | FileCheck --check-prefix=CHECK %s

declare void @function1()

declare void @function2() #0

; Function Attrs: noinline
define void @function3(i8 addrspace(4)* %argptr, i8 addrspace(4)* addrspace(1)* %sink) #4 {
  store i8 addrspace(4)* %argptr, i8 addrspace(4)* addrspace(1)* %sink, align 8
  ret void
}

; Function Attrs: noinline
define void @function4(i64 %arg, i64* %a) #4 {
  store i64 %arg, i64* %a
  ret void
}

; Function Attrs: noinline
define void @function5(i8 addrspace(4)* %ptr, i64* %sink) #4 {
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 8
  %cast = bitcast i8 addrspace(4)* %gep to i64 addrspace(4)*
  %x = load i64, i64 addrspace(4)* %cast
  store i64 %x, i64* %sink
  ret void
}

; Function Attrs: nounwind readnone speculatable willreturn
declare align 4 i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr() #1

; CHECK: amdhsa.kernels:
; CHECK:  - .args:
; CHECK-NOT: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel10
define amdgpu_kernel void @test_kernel10(i8* %a) #2 {
  store i8 3, i8* %a, align 1
  ret void
}

; Call to an extern function

; CHECK:  - .args:
; CHECK: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel20
define amdgpu_kernel void @test_kernel20(i8* %a) #2 {
  call void @function1()
  store i8 3, i8* %a, align 1
  ret void
}

; Explicit attribute on kernel

; CHECK:  - .args:
; CHECK-NOT: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel21
define amdgpu_kernel void @test_kernel21(i8* %a) #3 {
  call void @function1()
  store i8 3, i8* %a, align 1
  ret void
}

; Explicit attribute on extern callee

; CHECK:  - .args:
; CHECK-NOT: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel22
define amdgpu_kernel void @test_kernel22(i8* %a) #2 {
  call void @function2()
  store i8 3, i8* %a, align 1
  ret void
}

; Access more bytes than the pointer size

; CHECK:  - .args:
; CHECK: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel30
define amdgpu_kernel void @test_kernel30(i128* %a) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 16
  %cast = bitcast i8 addrspace(4)* %gep to i128 addrspace(4)*
  %x = load i128, i128 addrspace(4)* %cast
  store i128 %x, i128* %a
  ret void
}

; Typical load of hostcall buffer pointer

; CHECK:  - .args:
; CHECK: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel40
define amdgpu_kernel void @test_kernel40(i64* %a) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 24
  %cast = bitcast i8 addrspace(4)* %gep to i64 addrspace(4)*
  %x = load i64, i64 addrspace(4)* %cast
  store i64 %x, i64* %a
  ret void
}

; Typical usage, overriden by explicit attribute on kernel

; CHECK:  - .args:
; CHECK-NOT: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel41
define amdgpu_kernel void @test_kernel41(i64* %a) #3 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 24
  %cast = bitcast i8 addrspace(4)* %gep to i64 addrspace(4)*
  %x = load i64, i64 addrspace(4)* %cast
  store i64 %x, i64* %a
  ret void
}

; Access to implicit arg before the hostcall pointer

; CHECK:  - .args:
; CHECK-NOT: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel42
define amdgpu_kernel void @test_kernel42(i64* %a) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 16
  %cast = bitcast i8 addrspace(4)* %gep to i64 addrspace(4)*
  %x = load i64, i64 addrspace(4)* %cast
  store i64 %x, i64* %a
  ret void
}

; Access to implicit arg after the hostcall pointer

; CHECK:  - .args:
; CHECK-NOT: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel43
define amdgpu_kernel void @test_kernel43(i64* %a) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 32
  %cast = bitcast i8 addrspace(4)* %gep to i64 addrspace(4)*
  %x = load i64, i64 addrspace(4)* %cast
  store i64 %x, i64* %a
  ret void
}

; Accessing a byte just before the hostcall pointer

; CHECK:  - .args:
; CHECK-NOT: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel44
define amdgpu_kernel void @test_kernel44(i8* %a) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 23
  %x = load i8, i8 addrspace(4)* %gep, align 1
  store i8 %x, i8* %a, align 1
  ret void
}

; Accessing a byte inside the hostcall pointer

; CHECK:  - .args:
; CHECK: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel45
define amdgpu_kernel void @test_kernel45(i8* %a) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 24
  %x = load i8, i8 addrspace(4)* %gep, align 1
  store i8 %x, i8* %a, align 1
  ret void
}

; Accessing a byte inside the hostcall pointer

; CHECK:  - .args:
; CHECK: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel46
define amdgpu_kernel void @test_kernel46(i8* %a) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 31
  %x = load i8, i8 addrspace(4)* %gep, align 1
  store i8 %x, i8* %a, align 1
  ret void
}

; Accessing a byte just after the hostcall pointer

; CHECK:  - .args:
; CHECK-NOT: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel47
define amdgpu_kernel void @test_kernel47(i8* %a) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 32
  %x = load i8, i8 addrspace(4)* %gep, align 1
  store i8 %x, i8* %a, align 1
  ret void
}

; Access with an unknown offset

; CHECK:  - .args:
; CHECK: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel50
define amdgpu_kernel void @test_kernel50(i8* %a, i32 %b) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i32 %b
  %x = load i8, i8 addrspace(4)* %gep, align 1
  store i8 %x, i8* %a, align 1
  ret void
}

; Multiple geps reaching the hostcall pointer argument.

; CHECK:  - .args:
; CHECK: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel51
define amdgpu_kernel void @test_kernel51(i8* %a) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep1 = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 16
  %gep2 = getelementptr inbounds i8, i8 addrspace(4)* %gep1, i64 8
  %x = load i8, i8 addrspace(4)* %gep2, align 1
  store i8 %x, i8* %a, align 1
  ret void
}

; Multiple geps not reaching the hostcall pointer argument.

; CHECK:  - .args:
; CHECK-NOT: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel52
define amdgpu_kernel void @test_kernel52(i8* %a) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep1 = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 16
  %gep2 = getelementptr inbounds i8, i8 addrspace(4)* %gep1, i64 16
  %x = load i8, i8 addrspace(4)* %gep2, align 1
  store i8 %x, i8* %a, align 1
  ret void
}

; Hostcall pointer used inside a function call

; CHECK:  - .args:
; CHECK: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel60
define amdgpu_kernel void @test_kernel60(i64* %a) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 24
  %cast = bitcast i8 addrspace(4)* %gep to i64 addrspace(4)*
  %x = load i64, i64 addrspace(4)* %cast
  call void @function4(i64 %x, i64* %a)
  ret void
}

; Hostcall pointer retrieved inside a function call; chain of geps

; CHECK:  - .args:
; CHECK: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel61
define amdgpu_kernel void @test_kernel61(i64* %a) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i64 16
  call void @function5(i8 addrspace(4)* %gep, i64* %a)
  ret void
}

; Pointer captured

; CHECK:  - .args:
; CHECK: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel70
define amdgpu_kernel void @test_kernel70(i8 addrspace(4)* addrspace(1)* %sink) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i32 42
  store i8 addrspace(4)* %gep, i8 addrspace(4)* addrspace(1)* %sink, align 8
  ret void
}

; Pointer captured inside function call

; CHECK:  - .args:
; CHECK: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel71
define amdgpu_kernel void @test_kernel71(i8 addrspace(4)* addrspace(1)* %sink) #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i32 42
  call void @function3(i8 addrspace(4)* %gep, i8 addrspace(4)* addrspace(1)* %sink)
  ret void
}

; Ineffective pointer capture

; CHECK:  - .args:
; CHECK-NOT: hidden_hostcall_buffer
; CHECK-LABEL:    .name:           test_kernel72
define amdgpu_kernel void @test_kernel72() #2 {
  %ptr = tail call i8 addrspace(4)* @llvm.amdgcn.implicitarg.ptr()
  %gep = getelementptr inbounds i8, i8 addrspace(4)* %ptr, i32 42
  store i8 addrspace(4)* %gep, i8 addrspace(4)* addrspace(1)* undef, align 8
  ret void
}

attributes #0 = { "amdgpu-no-hostcall-ptr" }
attributes #1 = { nounwind readnone speculatable willreturn }
attributes #2 = { "amdgpu-implicitarg-num-bytes"="48" }
attributes #3 = { "amdgpu-implicitarg-num-bytes"="48" "amdgpu-no-hostcall-ptr" }
attributes #4 = { noinline }