brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 5e1752f Raw
54 lines · plain
1; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV2; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}3 4;; This test checks that the backend is capable to correctly translate5;; atomic_cmpxchg OpenCL C 1.2 built-in function [1] into corresponding SPIR-V6;; instruction.7 8;; __kernel void test_atomic_cmpxchg(__global int *p, int cmp, int val) {9;;   atomic_cmpxchg(p, cmp, val);10;;11;;   __global unsigned int *up = (__global unsigned int *)p;12;;   unsigned int ucmp = (unsigned int)cmp;13;;   unsigned int uval = (unsigned int)val;14;;   atomic_cmpxchg(up, ucmp, uval);15;; }16 17; CHECK-SPIRV:     OpName %[[#TEST:]] "test_atomic_cmpxchg"18; CHECK-SPIRV-DAG: %[[#UINT:]] = OpTypeInt 32 019; CHECK-SPIRV-DAG: %[[#UINT_PTR:]] = OpTypePointer CrossWorkgroup %[[#UINT]]20 21;; In SPIR-V, atomic_cmpxchg is represented as OpAtomicCompareExchange [2],22;; which also includes memory scope and two memory semantic arguments. The23;; backend applies some default memory order for it and therefore, constants24;; below include a bit more information than original source25 26;; 0x2 Workgroup27; CHECK-SPIRV-DAG: %[[#WORKGROUP_SCOPE:]] = OpConstant %[[#UINT]] 2{{$}}28 29;; 0x0 Relaxed30;; TODO: do we need CrossWorkgroupMemory here as well?31; CHECK-SPIRV-DAG: %[[#RELAXED:]] = OpConstantNull %[[#UINT]]32 33; CHECK-SPIRV:     %[[#TEST]] = OpFunction %[[#]]34; CHECK-SPIRV:     %[[#PTR:]] = OpFunctionParameter %[[#UINT_PTR]]35; CHECK-SPIRV:     %[[#CMP:]] = OpFunctionParameter %[[#UINT]]36; CHECK-SPIRV:     %[[#VAL:]] = OpFunctionParameter %[[#UINT]]37; CHECK-SPIRV:     %[[#]] = OpAtomicCompareExchange %[[#UINT]] %[[#PTR]] %[[#WORKGROUP_SCOPE]] %[[#RELAXED]] %[[#RELAXED]] %[[#VAL]] %[[#CMP]]38; CHECK-SPIRV:     %[[#]] = OpAtomicCompareExchange %[[#UINT]] %[[#PTR]] %[[#WORKGROUP_SCOPE]] %[[#RELAXED]] %[[#RELAXED]] %[[#VAL]] %[[#CMP]]39 40define dso_local spir_kernel void @test_atomic_cmpxchg(i32 addrspace(1)* noundef %p, i32 noundef %cmp, i32 noundef %val) local_unnamed_addr {41entry:42  %call = tail call spir_func i32 @_Z14atomic_cmpxchgPU3AS1Viii(i32 addrspace(1)* noundef %p, i32 noundef %cmp, i32 noundef %val)43  %call1 = tail call spir_func i32 @_Z14atomic_cmpxchgPU3AS1Vjjj(i32 addrspace(1)* noundef %p, i32 noundef %cmp, i32 noundef %val)44  ret void45}46 47declare spir_func i32 @_Z14atomic_cmpxchgPU3AS1Viii(i32 addrspace(1)* noundef, i32 noundef, i32 noundef) local_unnamed_addr48 49declare spir_func i32 @_Z14atomic_cmpxchgPU3AS1Vjjj(i32 addrspace(1)* noundef, i32 noundef, i32 noundef) local_unnamed_addr50 51;; References:52;; [1]: https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/atomic_cmpxchg.html53;; [2]: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpAtomicCompareExchange54