This PR: * adds support for G_SPLAT_VECTOR generic opcode that may be legally generated instead of G_BUILD_VECTOR by previous passes of the translator (see https://github.com/llvm/llvm-project/pull/80378 for the source of breaking changes); * improves deduction of types for opaque pointers. This PR also fixes the following issues: * if a function has ptr argument(s), two functions that have different SPIR-V type definitions may get identical LLVM function types and break agreements of global register and duplicate checker; * checks for pointer types do not account for TypedPointerType. Update of tests: * A test case is added to cover the issue with function ptr parameters. * The first case, that is support for G_SPLAT_VECTOR generic opcode, is covered by existing test cases. * Multiple additional checks by `spirv-val` is added to cover more possibilities of generation of invalid code.
48 lines
2.3 KiB
LLVM
48 lines
2.3 KiB
LLVM
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
|
|
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
|
|
|
|
;; This test checks that the backend is capable to correctly translate
|
|
;; legacy atomic OpenCL C 1.2 built-in functions [1] into corresponding SPIR-V
|
|
;; instruction.
|
|
|
|
;; __kernel void test_legacy_atomics(__global int *p, int val) {
|
|
;; atom_add(p, val); // from cl_khr_global_int32_base_atomics
|
|
;; atomic_add(p, val); // from OpenCL C 1.1
|
|
;; }
|
|
|
|
; CHECK-SPIRV: OpName %[[#TEST:]] "test_legacy_atomics"
|
|
; CHECK-SPIRV-DAG: %[[#UINT:]] = OpTypeInt 32 0
|
|
; CHECK-SPIRV-DAG: %[[#UINT_PTR:]] = OpTypePointer CrossWorkgroup %[[#UINT]]
|
|
|
|
;; In SPIR-V, atomic_add is represented as OpAtomicIAdd [2], which also includes
|
|
;; memory scope and memory semantic arguments. The backend applies a default
|
|
;; memory scope and memory order for it and therefore, constants below include
|
|
;; a bit more information than original source
|
|
|
|
;; 0x2 Workgroup
|
|
; CHECK-SPIRV-DAG: %[[#WORKGROUP_SCOPE:]] = OpConstant %[[#UINT]] 2
|
|
|
|
;; 0x0 Relaxed
|
|
; CHECK-SPIRV-DAG: %[[#RELAXED:]] = OpConstant %[[#UINT]] 0
|
|
|
|
; CHECK-SPIRV: %[[#TEST]] = OpFunction %[[#]]
|
|
; CHECK-SPIRV: %[[#PTR:]] = OpFunctionParameter %[[#UINT_PTR]]
|
|
; CHECK-SPIRV: %[[#VAL:]] = OpFunctionParameter %[[#UINT]]
|
|
; CHECK-SPIRV: %[[#]] = OpAtomicIAdd %[[#UINT]] %[[#PTR]] %[[#WORKGROUP_SCOPE]] %[[#RELAXED]] %[[#VAL]]
|
|
; CHECK-SPIRV: %[[#]] = OpAtomicIAdd %[[#UINT]] %[[#PTR]] %[[#WORKGROUP_SCOPE]] %[[#RELAXED]] %[[#VAL]]
|
|
|
|
define dso_local spir_kernel void @test_legacy_atomics(i32 addrspace(1)* noundef %p, i32 noundef %val) local_unnamed_addr {
|
|
entry:
|
|
%call = tail call spir_func i32 @_Z8atom_addPU3AS1Vii(i32 addrspace(1)* noundef %p, i32 noundef %val)
|
|
%call1 = tail call spir_func i32 @_Z10atomic_addPU3AS1Vii(i32 addrspace(1)* noundef %p, i32 noundef %val)
|
|
ret void
|
|
}
|
|
|
|
declare spir_func i32 @_Z8atom_addPU3AS1Vii(i32 addrspace(1)* noundef, i32 noundef) local_unnamed_addr
|
|
|
|
declare spir_func i32 @_Z10atomic_addPU3AS1Vii(i32 addrspace(1)* noundef, i32 noundef) local_unnamed_addr
|
|
|
|
;; References:
|
|
;; [1]: https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_C.html#atomic-legacy
|
|
;; [2]: https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#OpAtomicIAdd
|