1 ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
3 ;; This test checks that the backend is capable to correctly translate
4 ;; barrier OpenCL C 1.2 built-in function [1] into corresponding SPIR-V
7 ;; FIXME: Strictly speaking, this flag is not supported by barrier in OpenCL 1.2
8 ;; #define CLK_IMAGE_MEM_FENCE 0x04
10 ;; void __attribute__((overloadable)) __attribute__((convergent)) barrier(cl_mem_fence_flags);
12 ;; __kernel void test_barrier_const_flags() {
13 ;; barrier(CLK_LOCAL_MEM_FENCE);
14 ;; barrier(CLK_GLOBAL_MEM_FENCE);
15 ;; barrier(CLK_IMAGE_MEM_FENCE);
17 ;; barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
18 ;; barrier(CLK_LOCAL_MEM_FENCE | CLK_IMAGE_MEM_FENCE);
19 ;; barrier(CLK_GLOBAL_MEM_FENCE | CLK_LOCAL_MEM_FENCE | CLK_IMAGE_MEM_FENCE);
22 ;; __kernel void test_barrier_non_const_flags(cl_mem_fence_flags flags) {
23 ;; FIXME: OpenCL spec doesn't require flags to be compile-time known
27 ; CHECK-SPIRV: OpName %[[#TEST_CONST_FLAGS:]] "test_barrier_const_flags"
28 ; CHECK-SPIRV: %[[#UINT:]] = OpTypeInt 32 0
30 ;; In SPIR-V, barrier is represented as OpControlBarrier [3] and OpenCL
31 ;; cl_mem_fence_flags are represented as part of Memory Semantics [2], which
32 ;; also includes memory order constraints. The backend applies some default
33 ;; memory order for OpControlBarrier and therefore, constants below include a
34 ;; bit more information than original source
36 ;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory
37 ; CHECK-SPIRV: %[[#LOCAL:]] = OpConstant %[[#UINT]] 272
39 ; CHECK-SPIRV: %[[#WG:]] = OpConstant %[[#UINT]] 2
40 ;; 0x10 SequentiallyConsistent + 0x200 CrossWorkgroupMemory
41 ; CHECK-SPIRV-DAG: %[[#GLOBAL:]] = OpConstant %[[#UINT]] 528
42 ;; 0x10 SequentiallyConsistent + 0x800 ImageMemory
43 ; CHECK-SPIRV-DAG: %[[#IMAGE:]] = OpConstant %[[#UINT]] 2064
44 ;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x200 CrossWorkgroupMemory
45 ; CHECK-SPIRV-DAG: %[[#LOCAL_GLOBAL:]] = OpConstant %[[#UINT]] 784
46 ;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x800 ImageMemory
47 ; CHECK-SPIRV-DAG: %[[#LOCAL_IMAGE:]] = OpConstant %[[#UINT]] 2320
48 ;; 0x10 SequentiallyConsistent + 0x100 WorkgroupMemory + 0x200 CrossWorkgroupMemory + 0x800 ImageMemory
49 ; CHECK-SPIRV-DAG: %[[#LOCAL_GLOBAL_IMAGE:]] = OpConstant %[[#UINT]] 2832
51 ; CHECK-SPIRV: %[[#TEST_CONST_FLAGS]] = OpFunction %[[#]]
52 ; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL]]
53 ; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#GLOBAL]]
54 ; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#IMAGE]]
55 ; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL_GLOBAL]]
56 ; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL_IMAGE]]
57 ; CHECK-SPIRV: OpControlBarrier %[[#WG]] %[[#WG]] %[[#LOCAL_GLOBAL_IMAGE]]
59 define dso_local spir_kernel void @test_barrier_const_flags() local_unnamed_addr {
61 tail call spir_func void @_Z7barrierj(i32 noundef 1)
62 tail call spir_func void @_Z7barrierj(i32 noundef 2)
63 tail call spir_func void @_Z7barrierj(i32 noundef 4)
64 tail call spir_func void @_Z7barrierj(i32 noundef 3)
65 tail call spir_func void @_Z7barrierj(i32 noundef 5)
66 tail call spir_func void @_Z7barrierj(i32 noundef 7)
70 declare spir_func void @_Z7barrierj(i32 noundef) local_unnamed_addr
72 define dso_local spir_kernel void @test_barrier_non_const_flags(i32 noundef %flags) local_unnamed_addr {
78 ;; [1]: https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/barrier.html
79 ;; [2]: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_memory_semantics__id_a_memory_semantics_lt_id_gt
80 ;; [3]: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpControlBarrier