Debian Codegraph @

llvm/test/CodeGen/SPIRV/transcoding/OpenCL/atomic_legacy.ll

raw
1 ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
2 ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3
4 ;; This test checks that the backend is capable to correctly translate
5 ;; legacy atomic OpenCL C 1.2 built-in functions [1] into corresponding SPIR-V
6 ;; instruction.
7
8 ;; __kernel void test_legacy_atomics(__global int *p, int val) {
9 ;; atom_add(p, val); // from cl_khr_global_int32_base_atomics
10 ;; atomic_add(p, val); // from OpenCL C 1.1
11 ;; }
12
13 ; CHECK-SPIRV: OpName %[[#TEST:]] "test_legacy_atomics"
14 ; CHECK-SPIRV-DAG: %[[#UINT:]] = OpTypeInt 32 0
15 ; CHECK-SPIRV-DAG: %[[#UINT_PTR:]] = OpTypePointer CrossWorkgroup %[[#UINT]]
16
17 ;; In SPIR-V, atomic_add is represented as OpAtomicIAdd [2], which also includes
18 ;; memory scope and memory semantic arguments. The backend applies a default
19 ;; memory scope and memory order for it and therefore, constants below include
20 ;; a bit more information than original source
21
22 ;; 0x2 Workgroup
23 ; CHECK-SPIRV-DAG: %[[#WORKGROUP_SCOPE:]] = OpConstant %[[#UINT]] 2{{$}}
24
25 ;; 0x0 Relaxed
26 ; CHECK-SPIRV-DAG: %[[#RELAXED:]] = OpConstantNull %[[#UINT]]
27
28 ; CHECK-SPIRV: %[[#TEST]] = OpFunction %[[#]]
29 ; CHECK-SPIRV: %[[#PTR:]] = OpFunctionParameter %[[#UINT_PTR]]
30 ; CHECK-SPIRV: %[[#VAL:]] = OpFunctionParameter %[[#UINT]]
31 ; CHECK-SPIRV: %[[#]] = OpAtomicIAdd %[[#UINT]] %[[#PTR]] %[[#WORKGROUP_SCOPE]] %[[#RELAXED]] %[[#VAL]]
32 ; CHECK-SPIRV: %[[#]] = OpAtomicIAdd %[[#UINT]] %[[#PTR]] %[[#WORKGROUP_SCOPE]] %[[#RELAXED]] %[[#VAL]]
33
34 define dso_local spir_kernel void @test_legacy_atomics(ptr addrspace(1) noundef %p, i32 noundef %val) local_unnamed_addr {
35 entry:
36 %call = tail call spir_func i32 @_Z8atom_addPU3AS1Vii(ptr addrspace(1) noundef %p, i32 noundef %val)
37 %call1 = tail call spir_func i32 @_Z10atomic_addPU3AS1Vii(ptr addrspace(1) noundef %p, i32 noundef %val)
38 ret void
39 }
40
41 declare spir_func i32 @_Z8atom_addPU3AS1Vii(ptr addrspace(1) noundef, i32 noundef) local_unnamed_addr
42
43 declare spir_func i32 @_Z10atomic_addPU3AS1Vii(ptr addrspace(1) noundef, i32 noundef) local_unnamed_addr
44
45 ;; References:
46 ;; [1]: https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_C.html#atomic-legacy
47 ;; [2]: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpAtomicIAdd