From 0bcd4f3e232eff7afb5eec2cb4c0d24e3c48fd4e Mon Sep 17 00:00:00 2001 From: Alan Baker Date: Mon, 5 Feb 2024 23:29:04 -0500 Subject: [PATCH] Rewrite variable pointers tests as SPIRVProducer tests refs #1292 * Rewrite as more targeted tests to reduce potential perturbations --- .../function_call_image_param.cl | 18 ------ .../function_call_image_param.ll | 34 ++++++++++ .../function_call_sampler_param.cl | 21 ------- .../function_call_sampler_param.ll | 44 +++++++++++++ test/VariablePointers/function_call_ssbo.cl | 20 ------ test/VariablePointers/function_call_ssbo.ll | 41 ++++++++++++ .../function_call_ssbo_subobject.cl | 27 -------- .../function_call_ssbo_subobject.ll | 48 ++++++++++++++ test/VariablePointers/function_call_wg.cl | 24 ------- test/VariablePointers/function_call_wg.ll | 45 ++++++++++++++ test/VariablePointers/null_pointer_ssbo.cl | 18 ------ test/VariablePointers/null_pointer_ssbo.ll | 35 +++++++++++ test/VariablePointers/null_pointer_wg.cl | 18 ------ test/VariablePointers/null_pointer_wg.ll | 32 ++++++++++ test/VariablePointers/phi_ssbo.cl | 23 ------- test/VariablePointers/phi_ssbo.ll | 62 +++++++++++++++++++ test/VariablePointers/phi_ssbo_null.cl | 25 -------- test/VariablePointers/phi_ssbo_null.ll | 57 +++++++++++++++++ test/VariablePointers/phi_ssbo_same_buffer.cl | 29 --------- test/VariablePointers/phi_ssbo_same_buffer.ll | 53 ++++++++++++++++ test/VariablePointers/phi_wg.cl | 25 -------- test/VariablePointers/phi_wg.ll | 57 +++++++++++++++++ .../VariablePointers/ptr_access_chain_ssbo.cl | 21 ------- .../VariablePointers/ptr_access_chain_ssbo.ll | 37 +++++++++++ test/VariablePointers/ptr_access_chain_wg.cl | 22 ------- test/VariablePointers/ptr_access_chain_wg.ll | 37 +++++++++++ test/VariablePointers/sampler.cl | 22 ------- test/VariablePointers/sampler.ll | 42 +++++++++++++ test/VariablePointers/select_ssbo.cl | 19 ------ test/VariablePointers/select_ssbo.ll | 54 ++++++++++++++++ test/VariablePointers/select_ssbo_null.cl | 18 ------ test/VariablePointers/select_ssbo_null.ll | 48 ++++++++++++++ .../select_ssbo_same_buffer.cl | 18 ------ .../select_ssbo_same_buffer.ll | 48 ++++++++++++++ test/VariablePointers/select_wg.cl | 20 ------ test/VariablePointers/select_wg.ll | 45 ++++++++++++++ 36 files changed, 819 insertions(+), 388 deletions(-) delete mode 100644 test/VariablePointers/function_call_image_param.cl create mode 100644 test/VariablePointers/function_call_image_param.ll delete mode 100644 test/VariablePointers/function_call_sampler_param.cl create mode 100644 test/VariablePointers/function_call_sampler_param.ll delete mode 100644 test/VariablePointers/function_call_ssbo.cl create mode 100644 test/VariablePointers/function_call_ssbo.ll delete mode 100644 test/VariablePointers/function_call_ssbo_subobject.cl create mode 100644 test/VariablePointers/function_call_ssbo_subobject.ll delete mode 100644 test/VariablePointers/function_call_wg.cl create mode 100644 test/VariablePointers/function_call_wg.ll delete mode 100644 test/VariablePointers/null_pointer_ssbo.cl create mode 100644 test/VariablePointers/null_pointer_ssbo.ll delete mode 100644 test/VariablePointers/null_pointer_wg.cl create mode 100644 test/VariablePointers/null_pointer_wg.ll delete mode 100644 test/VariablePointers/phi_ssbo.cl create mode 100644 test/VariablePointers/phi_ssbo.ll delete mode 100644 test/VariablePointers/phi_ssbo_null.cl create mode 100644 test/VariablePointers/phi_ssbo_null.ll delete mode 100644 test/VariablePointers/phi_ssbo_same_buffer.cl create mode 100644 test/VariablePointers/phi_ssbo_same_buffer.ll delete mode 100644 test/VariablePointers/phi_wg.cl create mode 100644 test/VariablePointers/phi_wg.ll delete mode 100644 test/VariablePointers/ptr_access_chain_ssbo.cl create mode 100644 test/VariablePointers/ptr_access_chain_ssbo.ll delete mode 100644 test/VariablePointers/ptr_access_chain_wg.cl create mode 100644 test/VariablePointers/ptr_access_chain_wg.ll delete mode 100644 test/VariablePointers/sampler.cl create mode 100644 test/VariablePointers/sampler.ll delete mode 100644 test/VariablePointers/select_ssbo.cl create mode 100644 test/VariablePointers/select_ssbo.ll delete mode 100644 test/VariablePointers/select_ssbo_null.cl create mode 100644 test/VariablePointers/select_ssbo_null.ll delete mode 100644 test/VariablePointers/select_ssbo_same_buffer.cl create mode 100644 test/VariablePointers/select_ssbo_same_buffer.ll delete mode 100644 test/VariablePointers/select_wg.cl create mode 100644 test/VariablePointers/select_wg.ll diff --git a/test/VariablePointers/function_call_image_param.cl b/test/VariablePointers/function_call_image_param.cl deleted file mode 100644 index 6fe97ad6d..000000000 --- a/test/VariablePointers/function_call_image_param.cl +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -no-dra -no-inline-single -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -__attribute__((noinline)) -void bar(write_only image2d_t image) { - write_imagef(image, (int2)(0, 0), (float4)(0.0)); -} - -kernel void foo(write_only image2d_t image) { - bar(image); -} - -// CHECK-NOT: OpCapability VariablePointers -// CHECK-NOT: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[image:%[a-zA-Z0-9_]+]] = OpTypeImage -// CHECK: OpFunctionParameter [[image]] diff --git a/test/VariablePointers/function_call_image_param.ll b/test/VariablePointers/function_call_image_param.ll new file mode 100644 index 000000000..d3b596236 --- /dev/null +++ b/test/VariablePointers/function_call_image_param.ll @@ -0,0 +1,34 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; CHECK-NOT: OpCapability VariablePointers +; CHECK-NOT: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[image:%[a-zA-Z0-9_]+]] = OpTypeImage +; CHECK: OpFunctionParameter [[image]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +declare spir_func void @_Z12write_imagef22ocl_image2d_wo_t.floatDv2_iDv4_f(target("spirv.Image", float, 1, 0, 0, 0, 2, 0, 1, 0), <2 x i32>, <4 x float>) + +define spir_func void @bar(target("spirv.Image", float, 1, 0, 0, 0, 2, 0, 1, 0) %image) { +entry: + tail call spir_func void @_Z12write_imagef22ocl_image2d_wo_t.floatDv2_iDv4_f(target("spirv.Image", float, 1, 0, 0, 0, 2, 0, 1, 0) %image, <2 x i32> zeroinitializer, <4 x float> zeroinitializer) + ret void +} + +define spir_kernel void @foo(target("spirv.Image", float, 1, 0, 0, 0, 2, 0, 1, 0) %image) !clspv.pod_args_impl !15 { +entry: + %0 = call target("spirv.Image", float, 1, 0, 0, 0, 2, 0, 1, 0) @_Z14clspv.resource.0(i32 0, i32 0, i32 7, i32 0, i32 0, i32 0, target("spirv.Image", float, 1, 0, 0, 0, 2, 0, 1, 0) undef) + tail call spir_func void @bar(target("spirv.Image", float, 1, 0, 0, 0, 2, 0, 1, 0) %0) + ret void +} + +declare target("spirv.Image", float, 1, 0, 0, 0, 2, 0, 1, 0) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, target("spirv.Image", float, 1, 0, 0, 0, 2, 0, 1, 0)) + +!15 = !{i32 2} + diff --git a/test/VariablePointers/function_call_sampler_param.cl b/test/VariablePointers/function_call_sampler_param.cl deleted file mode 100644 index b7b97955a..000000000 --- a/test/VariablePointers/function_call_sampler_param.cl +++ /dev/null @@ -1,21 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -no-dra -no-inline-single -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -__attribute__((noinline)) -float4 bar(read_only image2d_t image, sampler_t sampler) { - return read_imagef(image, sampler, (float2)(0.0)); -} - -kernel void foo(read_only image2d_t image, sampler_t sampler, global float4* out) { - *out = bar(image, sampler); -} - -// CHECK-NOT: OpCapability VariablePointers -// CHECK-NOT: OpExtension "SPV_KHR_variable_pointers" -// CHECK-DAG: [[image:%[a-zA-Z0-9_]+]] = OpTypeImage -// CHECK-DAG: [[sampler:%[a-zA-Z0-9_]+]] = OpTypeSampler -// CHECK: OpFunctionParameter [[image]] -// CHECK: OpFunctionParameter [[sampler]] - diff --git a/test/VariablePointers/function_call_sampler_param.ll b/test/VariablePointers/function_call_sampler_param.ll new file mode 100644 index 000000000..4016aad39 --- /dev/null +++ b/test/VariablePointers/function_call_sampler_param.ll @@ -0,0 +1,44 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; CHECK-NOT: OpCapability VariablePointers +; CHECK-NOT: OpExtension "SPV_KHR_variable_pointers" +; CHECK-DAG: [[image:%[a-zA-Z0-9_]+]] = OpTypeImage +; CHECK-DAG: [[sampler:%[a-zA-Z0-9_]+]] = OpTypeSampler +; CHECK: OpFunctionParameter [[image]] +; CHECK: OpFunctionParameter [[sampler]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +declare spir_func <4 x float> @_Z11read_imagef30ocl_image2d_ro_t.float.sampled11ocl_samplerDv2_f(target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0), target("spirv.Sampler"), <2 x float>) + +define spir_func <4 x float> @bar(target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) %image, target("spirv.Sampler") %sampler) { +entry: + %call = tail call spir_func <4 x float> @_Z11read_imagef30ocl_image2d_ro_t.float.sampled11ocl_samplerDv2_f(target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) %image, target("spirv.Sampler") %sampler, <2 x float> zeroinitializer) + ret <4 x float> %call +} + +define spir_kernel void @foo(target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) %image, target("spirv.Sampler") %sampler, ptr addrspace(1) nocapture writeonly align 16 %out) !clspv.pod_args_impl !17 { +entry: + %0 = call target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) @_Z14clspv.resource.0(i32 0, i32 0, i32 6, i32 0, i32 0, i32 0, target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) undef) + %1 = call target("spirv.Sampler") @_Z14clspv.resource.1(i32 0, i32 1, i32 8, i32 1, i32 1, i32 0, target("spirv.Sampler") zeroinitializer) + %2 = call ptr addrspace(1) @_Z14clspv.resource.2(i32 0, i32 2, i32 0, i32 2, i32 2, i32 0, { [0 x <4 x float>] } zeroinitializer) + %3 = getelementptr { [0 x <4 x float>] }, ptr addrspace(1) %2, i32 0, i32 0, i32 0 + %call = tail call spir_func <4 x float> @bar(target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) %0, target("spirv.Sampler") %1) #4 + store <4 x float> %call, ptr addrspace(1) %3, align 16 + ret void +} + +declare target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0)) + +declare target("spirv.Sampler") @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, target("spirv.Sampler")) + +declare ptr addrspace(1) @_Z14clspv.resource.2(i32, i32, i32, i32, i32, i32, { [0 x <4 x float>] }) + +!17 = !{i32 2} + diff --git a/test/VariablePointers/function_call_ssbo.cl b/test/VariablePointers/function_call_ssbo.cl deleted file mode 100644 index b04937864..000000000 --- a/test/VariablePointers/function_call_ssbo.cl +++ /dev/null @@ -1,20 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -no-dra -no-inline-single -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// Passing SSBO to function call requires VariablePointersStorageBuffer. -__attribute__((noinline)) -int bar(global int* x) { return *x; } - -kernel void foo(global int* in, global int* out) { - *out = bar(in); -} - -// CHECK-NOT: OpCapability VariablePointers -// CHECK: OpCapability VariablePointersStorageBuffer -// CHECK-NOT: OpCapability VariablePointers -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] -// CHECK: OpFunctionParameter [[ptr]] diff --git a/test/VariablePointers/function_call_ssbo.ll b/test/VariablePointers/function_call_ssbo.ll new file mode 100644 index 000000000..8bc790400 --- /dev/null +++ b/test/VariablePointers/function_call_ssbo.ll @@ -0,0 +1,41 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpCapability VariablePointersStorageBuffer +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] +; CHECK: OpFunctionParameter [[ptr]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define dso_local spir_func i32 @bar(ptr addrspace(1) nocapture readonly %x) { +entry: + %0 = load i32, ptr addrspace(1) %x, align 4 + ret i32 %0 +} + +define dso_local spir_kernel void @foo(ptr addrspace(1) nocapture readonly align 4 %in, ptr addrspace(1) nocapture writeonly align 4 %out) !clspv.pod_args_impl !16 { +entry: + %0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %1 = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0 + %2 = call ptr addrspace(1) @_Z14clspv.resource.1(i32 0, i32 1, i32 0, i32 1, i32 1, i32 0, { [0 x i32] } zeroinitializer) + %3 = getelementptr { [0 x i32] }, ptr addrspace(1) %2, i32 0, i32 0, i32 0 + %call = tail call spir_func i32 @bar(ptr addrspace(1) %1) + store i32 %call, ptr addrspace(1) %3, align 4 + ret void +} + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(1) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +!16 = !{i32 2} + diff --git a/test/VariablePointers/function_call_ssbo_subobject.cl b/test/VariablePointers/function_call_ssbo_subobject.cl deleted file mode 100644 index e7fe2c945..000000000 --- a/test/VariablePointers/function_call_ssbo_subobject.cl +++ /dev/null @@ -1,27 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -no-dra -no-inline-single -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv -// TODO(#1292) -// XFAIL: * - -// Passing SSBO to function call requires VariablePointersStorageBuffer. -// SSBO args do not require memory object declarations. -__attribute__((noinline)) -int bar(global int* x) { return *x; } - -kernel void foo(global int* in, global int* out) { - *out = bar(in + 1); -} - -// CHECK-NOT: OpCapability VariablePointers -// CHECK: OpCapability VariablePointersStorageBuffer -// CHECK-NOT: OpCapability VariablePointers -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] -// CHECK: [[uint_0:%[a-zA-Z0-9_]+]] = OpConstant [[uint]] 0 -// CHECK: [[uint_1:%[a-zA-Z0-9_]+]] = OpConstant [[uint]] 1 -// CHECK: [[gep:%[a-zA-Z0-9_]+]] = OpAccessChain [[ptr]] {{.*}} [[uint_0]] [[uint_1]] -// CHECK-NEXT: OpFunctionCall [[uint]] {{.*}} [[gep]] - diff --git a/test/VariablePointers/function_call_ssbo_subobject.ll b/test/VariablePointers/function_call_ssbo_subobject.ll new file mode 100644 index 000000000..5b43d8fdc --- /dev/null +++ b/test/VariablePointers/function_call_ssbo_subobject.ll @@ -0,0 +1,48 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; Passing SSBO to function call requires VariablePointersStorageBuffer. +; SSBO args do not require memory object declarations. +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpCapability VariablePointersStorageBuffer +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] +; CHECK: [[uint_0:%[a-zA-Z0-9_]+]] = OpConstant [[uint]] 0 +; CHECK: [[uint_1:%[a-zA-Z0-9_]+]] = OpConstant [[uint]] 1 +; CHECK: [[gep:%[a-zA-Z0-9_]+]] = OpAccessChain [[ptr]] {{.*}} [[uint_0]] [[uint_1]] +; CHECK-NEXT: OpFunctionCall [[uint]] {{.*}} [[gep]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define dso_local spir_func i32 @bar(ptr addrspace(1) nocapture readonly %x) { +entry: + %0 = load i32, ptr addrspace(1) %x, align 4 + ret i32 %0 +} + +define spir_kernel void @foo(ptr addrspace(1) nocapture readonly align 4 %in, ptr addrspace(1) nocapture writeonly align 4 %out) !clspv.pod_args_impl !16 { +entry: + %0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %1 = call ptr addrspace(1) @_Z14clspv.resource.1(i32 0, i32 1, i32 0, i32 1, i32 1, i32 0, { [0 x i32] } zeroinitializer) + %2 = getelementptr { [0 x i32] }, ptr addrspace(1) %1, i32 0, i32 0, i32 0 + %3 = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 1 + %call.i = tail call spir_func i32 @bar(ptr addrspace(1) %3) + store i32 %call.i, ptr addrspace(1) %2, align 4 + ret void +} + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(1) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(9) @_Z14clspv.resource.2(i32, i32, i32, i32, i32, i32, { { i32 } }) + +!16 = !{i32 2} + diff --git a/test/VariablePointers/function_call_wg.cl b/test/VariablePointers/function_call_wg.cl deleted file mode 100644 index 3231d2fee..000000000 --- a/test/VariablePointers/function_call_wg.cl +++ /dev/null @@ -1,24 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -no-dra -no-inline-single -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// Pass base workgroup object to a function shouldn't require variable -// pointers, but the representation inserts an OpAccessChain so we require -// VariablePointers because it is NOT a memory object declaration. -__attribute__((noinline)) -int bar(local int* x) { return *x; } - -kernel void foo(local int* in, global int* out) { - *out = bar(in); -} - -// CHECK-NOT: OpCapability VariablePointersStorageBuffer -// CHECK: OpCapability VariablePointers -// CHECK-NOT: StorageBuffer -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer Workgroup [[uint]] -// CHECK: [[gep:%[a-zA-Z0-9_]+]] = OpAccessChain [[ptr]] -// CHECK: OpFunctionCall [[uint]] {{.*}} [[gep]] - diff --git a/test/VariablePointers/function_call_wg.ll b/test/VariablePointers/function_call_wg.ll new file mode 100644 index 000000000..952221de5 --- /dev/null +++ b/test/VariablePointers/function_call_wg.ll @@ -0,0 +1,45 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; Pass base workgroup object to a function shouldn't require variable +; pointers, but the representation inserts an OpAccessChain so we require +; VariablePointers because it is NOT a memory object declaration. +; CHECK-NOT: OpCapability VariablePointersStorageBuffer +; CHECK: OpCapability VariablePointers +; CHECK-NOT: StorageBuffer +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer Workgroup [[uint]] +; CHECK: [[gep:%[a-zA-Z0-9_]+]] = OpAccessChain [[ptr]] +; CHECK: OpFunctionCall [[uint]] {{.*}} [[gep]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define dso_local spir_func i32 @bar(ptr addrspace(3) nocapture readonly %x) { +entry: + %0 = load i32, ptr addrspace(3) %x, align 4 + ret i32 %0 +} + +define dso_local spir_kernel void @foo(ptr addrspace(3) nocapture readonly align 4 %in, ptr addrspace(1) nocapture writeonly align 4 %out) !clspv.pod_args_impl !19 { +entry: + %0 = call ptr addrspace(3) @_Z11clspv.local.3(i32 3, [0 x i32] zeroinitializer) + %1 = getelementptr [0 x i32], ptr addrspace(3) %0, i32 0, i32 0 + %2 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 1, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %3 = getelementptr { [0 x i32] }, ptr addrspace(1) %2, i32 0, i32 0, i32 0 + %call = tail call spir_func i32 @bar(ptr addrspace(3) %1) + store i32 %call, ptr addrspace(1) %3, align 4 + ret void +} + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(3) @_Z11clspv.local.3(i32, [0 x i32]) + +!19 = !{i32 2} + diff --git a/test/VariablePointers/null_pointer_ssbo.cl b/test/VariablePointers/null_pointer_ssbo.cl deleted file mode 100644 index 0a3483f30..000000000 --- a/test/VariablePointers/null_pointer_ssbo.cl +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// Null pointer for SSBO requires VariablePointersStorageBuffer. -kernel void foo(global int* out, int n) { - global int* x = 0; - *out = *x; -} - -// CHECK-NOT: OpCapability VariablePointers -// CHECK: OpCapability VariablePointersStorageBuffer -// CHECK-NOT: OpCapability VariablePointers -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] -// CHECK: OpConstantNull [[ptr]] diff --git a/test/VariablePointers/null_pointer_ssbo.ll b/test/VariablePointers/null_pointer_ssbo.ll new file mode 100644 index 000000000..fafe30b36 --- /dev/null +++ b/test/VariablePointers/null_pointer_ssbo.ll @@ -0,0 +1,35 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; Null pointer for SSBO requires VariablePointersStorageBuffer. +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpCapability VariablePointersStorageBuffer +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] +; CHECK: OpConstantNull [[ptr]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define spir_kernel void @foo(ptr addrspace(1) nocapture writeonly align 4 %out, { i32 } %podargs) !clspv.pod_args_impl !14 !kernel_arg_map !15 { +entry: + %0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %1 = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0 + %2 = load i32, ptr addrspace(1) null, align 2147483648 + store i32 %2, ptr addrspace(1) %1, align 4 + ret void +} + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +!14 = !{i32 2} +!15 = !{!16, !17} +!16 = !{!"out", i32 0, i32 0, i32 0, i32 0, !"buffer"} +!17 = !{!"n", i32 1, i32 1, i32 0, i32 4, !"pod_pushconstant"} + diff --git a/test/VariablePointers/null_pointer_wg.cl b/test/VariablePointers/null_pointer_wg.cl deleted file mode 100644 index 7a82c36f6..000000000 --- a/test/VariablePointers/null_pointer_wg.cl +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// Null pointer in workgroup requires VariablePointers. -kernel void foo(global int* out) { - local int* x = 0; - *out = *x; -} - -// CHECK-NOT: OpCapability VariablePointersStorageBuffer -// CHECK: OpCapability VariablePointers -// CHECK-NOT: StorageBuffer -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer Workgroup [[uint]] -// CHECK: OpConstantNull [[ptr]] diff --git a/test/VariablePointers/null_pointer_wg.ll b/test/VariablePointers/null_pointer_wg.ll new file mode 100644 index 000000000..0ae0b0e85 --- /dev/null +++ b/test/VariablePointers/null_pointer_wg.ll @@ -0,0 +1,32 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; Null pointer in workgroup requires VariablePointers. +; CHECK-NOT: OpCapability VariablePointersStorageBuffer +; CHECK: OpCapability VariablePointers +; CHECK-NOT: StorageBuffer +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer Workgroup [[uint]] +; CHECK: OpConstantNull [[ptr]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define dso_local spir_kernel void @foo(ptr addrspace(1) nocapture writeonly align 4 %out) !clspv.pod_args_impl !13 { +entry: + %0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %1 = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0 + %2 = load i32, ptr addrspace(3) null, align 2147483648 + store i32 %2, ptr addrspace(1) %1, align 4 + ret void +} + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +!13 = !{i32 2} + diff --git a/test/VariablePointers/phi_ssbo.cl b/test/VariablePointers/phi_ssbo.cl deleted file mode 100644 index 456af9261..000000000 --- a/test/VariablePointers/phi_ssbo.cl +++ /dev/null @@ -1,23 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -no-dra -no-inline-single -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// Full VariablePointers required because phi is between different buffers. -kernel void foo(global int* in1, global int* in2, global int* out, int a) { - if (a == 0) { - barrier(CLK_GLOBAL_MEM_FENCE); - *out = *in1; - } else { - *out = *in2; - } -} - -// CHECK-NOT: OpCapability VariablePointersStorageBuffer -// CHECK-NOT: StorageBuffer -// CHECK: OpCapability VariablePointers -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] -// CHECK: OpPhi [[ptr]] - diff --git a/test/VariablePointers/phi_ssbo.ll b/test/VariablePointers/phi_ssbo.ll new file mode 100644 index 000000000..ad23777cc --- /dev/null +++ b/test/VariablePointers/phi_ssbo.ll @@ -0,0 +1,62 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; Full VariablePointers required because phi is between different buffers. +; CHECK-NOT: OpCapability VariablePointersStorageBuffer +; CHECK-NOT: StorageBuffer +; CHECK: OpCapability VariablePointers +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] +; CHECK: OpPhi [[ptr]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define spir_kernel void @foo(ptr addrspace(1) nocapture readonly align 4 %in1, ptr addrspace(1) nocapture readonly align 4 %in2, ptr addrspace(1) nocapture writeonly align 4 %out, { i32 } %podargs) !clspv.pod_args_impl !14 !kernel_arg_map !15 { +entry: + %0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %1 = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0 + %2 = call ptr addrspace(1) @_Z14clspv.resource.1(i32 0, i32 1, i32 0, i32 1, i32 1, i32 0, { [0 x i32] } zeroinitializer) + %3 = getelementptr { [0 x i32] }, ptr addrspace(1) %2, i32 0, i32 0, i32 0 + %4 = call ptr addrspace(1) @_Z14clspv.resource.2(i32 0, i32 2, i32 0, i32 2, i32 2, i32 0, { [0 x i32] } zeroinitializer) + %5 = getelementptr { [0 x i32] }, ptr addrspace(1) %4, i32 0, i32 0, i32 0 + %6 = call ptr addrspace(9) @_Z14clspv.resource.3(i32 -1, i32 3, i32 5, i32 3, i32 3, i32 0, { { i32 } } zeroinitializer) + %7 = getelementptr { { i32 } }, ptr addrspace(9) %6, i32 0, i32 0 + %8 = load { i32 }, ptr addrspace(9) %7, align 4 + %a = extractvalue { i32 } %8, 0 + %cmp.i = icmp eq i32 %a, 0 + br i1 %cmp.i, label %if.then.i, label %foo.inner.exit + +if.then.i: ; preds = %entry + tail call void @_Z8spirv.op.224.jjj(i32 224, i32 2, i32 2, i32 72) + br label %foo.inner.exit + +foo.inner.exit: ; preds = %if.then.i, %entry + %storemerge.in = phi ptr addrspace(1) [ %3, %entry ], [ %1, %if.then.i ] + %storemerge = load i32, ptr addrspace(1) %storemerge.in, align 4 + store i32 %storemerge, ptr addrspace(1) %5, align 4 + ret void +} + +declare void @_Z8spirv.op.224.jjj(i32, i32, i32, i32) + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(1) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(1) @_Z14clspv.resource.2(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(9) @_Z14clspv.resource.3(i32, i32, i32, i32, i32, i32, { { i32 } }) + +!14 = !{i32 2} +!15 = !{!16, !17, !18, !19} +!16 = !{!"in1", i32 0, i32 0, i32 0, i32 0, !"buffer"} +!17 = !{!"in2", i32 1, i32 1, i32 0, i32 0, !"buffer"} +!18 = !{!"out", i32 2, i32 2, i32 0, i32 0, !"buffer"} +!19 = !{!"a", i32 3, i32 3, i32 0, i32 4, !"pod_pushconstant"} + diff --git a/test/VariablePointers/phi_ssbo_null.cl b/test/VariablePointers/phi_ssbo_null.cl deleted file mode 100644 index b12699766..000000000 --- a/test/VariablePointers/phi_ssbo_null.cl +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -no-dra -no-inline-single -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// VariablePointersStorageBuffer required because phi has a single buffer. -kernel void foo(global int* in, global int* out, int a) { - if (a == 0) { - barrier(CLK_GLOBAL_MEM_FENCE); - *out = *in; - } else { - global int* x = 0; - *out = *x; - } -} - -// CHECK-NOT: OpCapability VariablePointers -// CHECK: OpCapability VariablePointersStorageBuffer -// CHECK-NOT: OpCapability VariablePointers -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] -// CHECK: OpPhi [[ptr]] - - diff --git a/test/VariablePointers/phi_ssbo_null.ll b/test/VariablePointers/phi_ssbo_null.ll new file mode 100644 index 000000000..9e09c4abe --- /dev/null +++ b/test/VariablePointers/phi_ssbo_null.ll @@ -0,0 +1,57 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; VariablePointersStorageBuffer required because phi has a single buffer. +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpCapability VariablePointersStorageBuffer +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] +; CHECK: OpPhi [[ptr]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define spir_kernel void @foo(ptr addrspace(1) nocapture readonly align 4 %in, ptr addrspace(1) nocapture writeonly align 4 %out, { i32 } %podargs) !clspv.pod_args_impl !14 !kernel_arg_map !15 { +entry: + %0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %1 = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0 + %2 = call ptr addrspace(1) @_Z14clspv.resource.1(i32 0, i32 1, i32 0, i32 1, i32 1, i32 0, { [0 x i32] } zeroinitializer) + %3 = getelementptr { [0 x i32] }, ptr addrspace(1) %2, i32 0, i32 0, i32 0 + %4 = call ptr addrspace(9) @_Z14clspv.resource.2(i32 -1, i32 2, i32 5, i32 2, i32 2, i32 0, { { i32 } } zeroinitializer) + %5 = getelementptr { { i32 } }, ptr addrspace(9) %4, i32 0, i32 0 + %6 = load { i32 }, ptr addrspace(9) %5, align 4 + %a = extractvalue { i32 } %6, 0 + %cmp.i = icmp eq i32 %a, 0 + br i1 %cmp.i, label %if.then.i, label %foo.inner.exit + +if.then.i: ; preds = %entry + tail call void @_Z8spirv.op.224.jjj(i32 224, i32 2, i32 2, i32 72) + br label %foo.inner.exit + +foo.inner.exit: ; preds = %if.then.i, %entry + %storemerge.in = phi ptr addrspace(1) [ null, %entry ], [ %1, %if.then.i ] + %storemerge = load i32, ptr addrspace(1) %storemerge.in, align 4 + store i32 %storemerge, ptr addrspace(1) %3, align 4 + ret void +} + +declare void @_Z8spirv.op.224.jjj(i32, i32, i32, i32) + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(1) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(9) @_Z14clspv.resource.2(i32, i32, i32, i32, i32, i32, { { i32 } }) + +!14 = !{i32 2} +!15 = !{!16, !17, !18} +!16 = !{!"in", i32 0, i32 0, i32 0, i32 0, !"buffer"} +!17 = !{!"out", i32 1, i32 1, i32 0, i32 0, !"buffer"} +!18 = !{!"a", i32 2, i32 2, i32 0, i32 4, !"pod_pushconstant"} + diff --git a/test/VariablePointers/phi_ssbo_same_buffer.cl b/test/VariablePointers/phi_ssbo_same_buffer.cl deleted file mode 100644 index 10a41d55c..000000000 --- a/test/VariablePointers/phi_ssbo_same_buffer.cl +++ /dev/null @@ -1,29 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -no-dra -no-inline-single -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv -// TODO(#1292) -// XFAIL: * - -// This should only require VariablePointersStorageBuffer, but the structurizer -// does some funny things with the if statement and we end up with two -// conditional branches. -kernel void foo(global int* in, global int* out, int a) { - if (a == 0) { - barrier(CLK_GLOBAL_MEM_FENCE); - *out = *(in + 1); - } else { - *out = *(in + 2); - } -} - -// CHECK-NOT: StorageBuffer -// CHECK: OpCapability VariablePointersStorageBuffer -// CHECK: OpCapability VariablePointers -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] -// CHECK: OpPhi [[ptr]] - - - diff --git a/test/VariablePointers/phi_ssbo_same_buffer.ll b/test/VariablePointers/phi_ssbo_same_buffer.ll new file mode 100644 index 000000000..02ae9fad2 --- /dev/null +++ b/test/VariablePointers/phi_ssbo_same_buffer.ll @@ -0,0 +1,53 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; Phi between pointers from the same buffer only requires VariablePointersStorageBuffer. +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpCapability VariablePointersStorageBuffer +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] +; CHECK: OpPhi [[ptr]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define dso_local spir_kernel void @foo(ptr addrspace(1) nocapture readonly align 4 %in, ptr addrspace(1) nocapture writeonly align 4 %out, i32 %a, i32 %x, i32 %y) !clspv.pod_args_impl !8 { +entry: + %0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %1 = call ptr addrspace(1) @_Z14clspv.resource.1(i32 0, i32 1, i32 0, i32 1, i32 1, i32 0, { [0 x i32] } zeroinitializer) + %2 = getelementptr { [0 x i32] }, ptr addrspace(1) %1, i32 0, i32 0, i32 0 + %3 = call ptr addrspace(6) @_Z14clspv.resource.2(i32 0, i32 2, i32 4, i32 2, i32 2, i32 0, { i32 } zeroinitializer) + %4 = getelementptr { i32 }, ptr addrspace(6) %3, i32 0, i32 0 + %5 = load i32, ptr addrspace(6) %4, align 4 + %ptr1 = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 1 + %cmp = icmp eq i32 %5, 0 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry + tail call void @_Z8spirv.op.224.jjj(i32 224, i32 2, i32 2, i32 72) + %ptr2 = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 2 + br label %if.end + +if.end: ; preds = %if.then, %entry + %phi = phi ptr addrspace(1) [ %ptr1, %entry ], [ %ptr2, %if.then ] + %storemerge = load i32, ptr addrspace(1) %phi, align 4 + store i32 %storemerge, ptr addrspace(1) %2, align 4 + ret void +} + +declare void @_Z8spirv.op.224.jjj(i32, i32, i32, i32) + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(1) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(6) @_Z14clspv.resource.2(i32, i32, i32, i32, i32, i32, { i32 }) + +!8 = !{i32 1} + diff --git a/test/VariablePointers/phi_wg.cl b/test/VariablePointers/phi_wg.cl deleted file mode 100644 index 803bba010..000000000 --- a/test/VariablePointers/phi_wg.cl +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -no-dra -no-inline-single -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// Despite choice against null, workgroup requires full VariablePointers. -kernel void foo(local int* in, global int* out, int a) { - if (a == 0) { - barrier(CLK_GLOBAL_MEM_FENCE); - *out = *in; - } else { - local int* x = 0; - *out = *x; - } -} - -// CHECK-NOT: OpCapability VariablePointersStorageBuffer -// CHECK: OpCapability VariablePointers -// CHECK-NOT: StorageBuffer -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer Workgroup [[uint]] -// CHECK: OpPhi [[ptr]] - - diff --git a/test/VariablePointers/phi_wg.ll b/test/VariablePointers/phi_wg.ll new file mode 100644 index 000000000..1fccfdad8 --- /dev/null +++ b/test/VariablePointers/phi_wg.ll @@ -0,0 +1,57 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; Despite choice against null, workgroup requires full VariablePointers. +; CHECK-NOT: OpCapability VariablePointersStorageBuffer +; CHECK: OpCapability VariablePointers +; CHECK-NOT: StorageBuffer +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer Workgroup [[uint]] +; CHECK: OpPhi [[ptr]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define spir_kernel void @foo(ptr addrspace(3) nocapture readonly align 4 %in, ptr addrspace(1) nocapture writeonly align 4 %out, { i32 } %podargs) !clspv.pod_args_impl !17 !kernel_arg_map !18 { +entry: + %0 = call ptr addrspace(3) @_Z11clspv.local.3(i32 3, [0 x i32] zeroinitializer) + %1 = getelementptr [0 x i32], ptr addrspace(3) %0, i32 0, i32 0 + %2 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 1, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %3 = getelementptr { [0 x i32] }, ptr addrspace(1) %2, i32 0, i32 0, i32 0 + %4 = call ptr addrspace(9) @_Z14clspv.resource.1(i32 -1, i32 1, i32 5, i32 2, i32 1, i32 0, { { i32 } } zeroinitializer) + %5 = getelementptr { { i32 } }, ptr addrspace(9) %4, i32 0, i32 0 + %6 = load { i32 }, ptr addrspace(9) %5, align 4 + %a = extractvalue { i32 } %6, 0 + %cmp.i = icmp eq i32 %a, 0 + br i1 %cmp.i, label %if.then.i, label %foo.inner.exit + +if.then.i: ; preds = %entry + tail call void @_Z8spirv.op.224.jjj(i32 224, i32 2, i32 2, i32 72) #2 + br label %foo.inner.exit + +foo.inner.exit: ; preds = %if.then.i, %entry + %storemerge.in = phi ptr addrspace(3) [ null, %entry ], [ %1, %if.then.i ] + %storemerge = load i32, ptr addrspace(3) %storemerge.in, align 4 + store i32 %storemerge, ptr addrspace(1) %3, align 4 + ret void +} + +declare void @_Z8spirv.op.224.jjj(i32, i32, i32, i32) + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(9) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { { i32 } }) + +declare ptr addrspace(3) @_Z11clspv.local.3(i32, [0 x i32]) + +!17 = !{i32 2} +!18 = !{!19, !20, !21} +!19 = !{!"in", i32 0, i32 0, i32 0, i32 0, !"local"} +!20 = !{!"out", i32 1, i32 1, i32 0, i32 0, !"buffer"} +!21 = !{!"a", i32 2, i32 2, i32 0, i32 4, !"pod_pushconstant"} + diff --git a/test/VariablePointers/ptr_access_chain_ssbo.cl b/test/VariablePointers/ptr_access_chain_ssbo.cl deleted file mode 100644 index 496a23f16..000000000 --- a/test/VariablePointers/ptr_access_chain_ssbo.cl +++ /dev/null @@ -1,21 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -no-dra -no-inline-single -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// The OpPtrAccessChain requires VariablePointersStorageBuffer. So does passing -// the of the argument though... -__attribute__((noinline)) -int bar(global int* x) { return x[1]; } -kernel void foo(global int* in, global int* out) { - *out = bar(in); -} - -// CHECK-NOT: OpCapability VariablePointers -// CHECK: OpCapability VariablePointersStorageBuffer -// CHECK-NOT: OpCapability VariablePointers -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] -// CHECK: OpPtrAccessChain [[ptr]] - diff --git a/test/VariablePointers/ptr_access_chain_ssbo.ll b/test/VariablePointers/ptr_access_chain_ssbo.ll new file mode 100644 index 000000000..93d58fa19 --- /dev/null +++ b/test/VariablePointers/ptr_access_chain_ssbo.ll @@ -0,0 +1,37 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; The OpPtrAccessChain requires VariablePointersStorageBuffer. +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpCapability VariablePointersStorageBuffer +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] +; CHECK: OpPtrAccessChain [[ptr]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define dso_local spir_kernel void @foo(ptr addrspace(1) nocapture readonly align 4 %in, ptr addrspace(1) nocapture writeonly align 4 %out) !clspv.pod_args_impl !16 { +entry: + %0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %1 = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0 + %2 = call ptr addrspace(1) @_Z14clspv.resource.1(i32 0, i32 1, i32 0, i32 1, i32 1, i32 0, { [0 x i32] } zeroinitializer) + %3 = getelementptr { [0 x i32] }, ptr addrspace(1) %2, i32 0, i32 0, i32 0 + %4 = getelementptr i32, ptr addrspace(1) %3, i32 1 + %5 = load i32, ptr addrspace(1) %4, align 4 + store i32 %5, ptr addrspace(1) %3, align 4 + ret void +} + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(1) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +!16 = !{i32 2} + diff --git a/test/VariablePointers/ptr_access_chain_wg.cl b/test/VariablePointers/ptr_access_chain_wg.cl deleted file mode 100644 index 9dd5c0247..000000000 --- a/test/VariablePointers/ptr_access_chain_wg.cl +++ /dev/null @@ -1,22 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -no-dra -no-inline-single -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// The OpPtrAccessChain requires VariablePointers for Workgorup. So does passing -// the of the argument though... -__attribute__((noinline)) -int bar(local int* x) { return x[1]; } -kernel void foo(local int* in, global int* out) { - *out = bar(in); -} - -// CHECK-NOT: OpCapability VariablePointersStorageBuffer -// CHECK: OpCapability VariablePointers -// CHECK-NOT: StorageBuffer -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer Workgroup [[uint]] -// CHECK: OpPtrAccessChain [[ptr]] - - diff --git a/test/VariablePointers/ptr_access_chain_wg.ll b/test/VariablePointers/ptr_access_chain_wg.ll new file mode 100644 index 000000000..3a4a30758 --- /dev/null +++ b/test/VariablePointers/ptr_access_chain_wg.ll @@ -0,0 +1,37 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; The OpPtrAccessChain requires VariablePointers for Workgorup. +; CHECK-NOT: OpCapability VariablePointersStorageBuffer +; CHECK: OpCapability VariablePointers +; CHECK-NOT: StorageBuffer +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer Workgroup [[uint]] +; CHECK: OpPtrAccessChain [[ptr]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define dso_local spir_kernel void @foo(ptr addrspace(3) nocapture readonly align 4 %in, ptr addrspace(1) nocapture writeonly align 4 %out) !clspv.pod_args_impl !19 { +entry: + %0 = call ptr addrspace(3) @_Z11clspv.local.3(i32 3, [0 x i32] zeroinitializer) + %1 = getelementptr [0 x i32], ptr addrspace(3) %0, i32 0, i32 0 + %2 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 1, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %3 = getelementptr { [0 x i32] }, ptr addrspace(1) %2, i32 0, i32 0, i32 0 + %4 = getelementptr i32, ptr addrspace(3) %1, i32 1 + %5 = load i32, ptr addrspace(3) %4, align 4 + store i32 %5, ptr addrspace(1) %3, align 4 + ret void +} + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(3) @_Z11clspv.local.3(i32, [0 x i32]) + +!19 = !{i32 2} + diff --git a/test/VariablePointers/sampler.cl b/test/VariablePointers/sampler.cl deleted file mode 100644 index a1162ddb4..000000000 --- a/test/VariablePointers/sampler.cl +++ /dev/null @@ -1,22 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -// RUN: spirv-dis %t.spv -o %t.spvasm -// RUN: FileCheck %s < %t.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// CHECK-NOT: OpCapability VariablePointers -// CHECK-NOT: OpExtension "SPV_KHR_variable_pointers" - -const sampler_t sampler = - CLK_NORMALIZED_COORDS_FALSE | \ - CLK_ADDRESS_CLAMP_TO_EDGE | - CLK_FILTER_NEAREST; - -kernel void foo(read_only image2d_t im1, read_only image2d_t im2) -{ - for (int l = 0; l < 30; ++l) { - float4 s = read_imagef(im1, sampler, (int2)(0,0)); - } - - float4 w = read_imagef(im2, sampler, (int2)(0, 0)); -} - diff --git a/test/VariablePointers/sampler.ll b/test/VariablePointers/sampler.ll new file mode 100644 index 000000000..daeb55418 --- /dev/null +++ b/test/VariablePointers/sampler.ll @@ -0,0 +1,42 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; CHECK-NOT: OpCapability VariablePointers +; CHECK-NOT: OpExtension "SPV_KHR_variable_pointers" + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +declare <4 x float> @_Z11read_imagef30ocl_image2d_ro_t.float.sampled11ocl_samplerDv2_f(target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0), target("spirv.Sampler"), <2 x float>) + +define spir_kernel void @foo(target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) %im1, target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) %im2) !clspv.pod_args_impl !8 { +entry: + %0 = call target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) @_Z14clspv.resource.0(i32 1, i32 0, i32 6, i32 0, i32 0, i32 0, target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) undef) + %1 = call target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) @_Z14clspv.resource.1(i32 1, i32 1, i32 6, i32 1, i32 1, i32 0, target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) undef) + %2 = call target("spirv.Sampler") @_Z25clspv.sampler_var_literal(i32 0, i32 0, i32 18, target("spirv.Sampler") zeroinitializer) + br label %for.body + +for.body: ; preds = %for.body, %entry + %l.03 = phi i32 [ 0, %entry ], [ %inc, %for.body ] + %3 = tail call <4 x float> @_Z11read_imagef30ocl_image2d_ro_t.float.sampled11ocl_samplerDv2_f(target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) %0, target("spirv.Sampler") %2, <2 x float> zeroinitializer) + %inc = add nuw nsw i32 %l.03, 1 + %cmp = icmp uge i32 %l.03, 29 + br i1 %cmp, label %for.end, label %for.body + +for.end: ; preds = %for.body + %4 = tail call <4 x float> @_Z11read_imagef30ocl_image2d_ro_t.float.sampled11ocl_samplerDv2_f(target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) %1, target("spirv.Sampler") %2, <2 x float> zeroinitializer) + ret void +} + +declare target("spirv.Sampler") @_Z25clspv.sampler_var_literal(i32, i32, i32, target("spirv.Sampler")) + +declare target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0)) + +declare target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, target("spirv.Image", float, 1, 0, 0, 0, 1, 0, 0, 0)) + +!8 = !{i32 2} + diff --git a/test/VariablePointers/select_ssbo.cl b/test/VariablePointers/select_ssbo.cl deleted file mode 100644 index aacf399c3..000000000 --- a/test/VariablePointers/select_ssbo.cl +++ /dev/null @@ -1,19 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// Requires full variable pointers because the selection is between different -// objects. -kernel void foo(global int* in1, global int* in2, global int* out, int a) { - global int* x = (a == 0) ? in1 : in2; - *out = *x; -} - -// CHECK-NOT: StorageBuffer -// CHECK: OpCapability VariablePointersStorageBuffer -// CHECK: OpCapability VariablePointers -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] -// CHECK: OpSelect [[ptr]] diff --git a/test/VariablePointers/select_ssbo.ll b/test/VariablePointers/select_ssbo.ll new file mode 100644 index 000000000..6f3491d4f --- /dev/null +++ b/test/VariablePointers/select_ssbo.ll @@ -0,0 +1,54 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; Requires full variable pointers because the selection is between different +; objects. +; CHECK-NOT: StorageBuffer +; CHECK: OpCapability VariablePointersStorageBuffer +; CHECK: OpCapability VariablePointers +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] +; CHECK: OpSelect [[ptr]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define spir_kernel void @foo(ptr addrspace(1) nocapture readonly align 4 %in1, ptr addrspace(1) nocapture readonly align 4 %in2, ptr addrspace(1) nocapture writeonly align 4 %out, { i32 } %podargs) !clspv.pod_args_impl !14 !kernel_arg_map !15 { +entry: + %0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %1 = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0 + %2 = call ptr addrspace(1) @_Z14clspv.resource.1(i32 0, i32 1, i32 0, i32 1, i32 1, i32 0, { [0 x i32] } zeroinitializer) + %3 = getelementptr { [0 x i32] }, ptr addrspace(1) %2, i32 0, i32 0, i32 0 + %4 = call ptr addrspace(1) @_Z14clspv.resource.2(i32 0, i32 2, i32 0, i32 2, i32 2, i32 0, { [0 x i32] } zeroinitializer) + %5 = getelementptr { [0 x i32] }, ptr addrspace(1) %4, i32 0, i32 0, i32 0 + %6 = call ptr addrspace(9) @_Z14clspv.resource.3(i32 -1, i32 3, i32 5, i32 3, i32 3, i32 0, { { i32 } } zeroinitializer) + %7 = getelementptr { { i32 } }, ptr addrspace(9) %6, i32 0, i32 0 + %8 = load { i32 }, ptr addrspace(9) %7, align 4 + %a = extractvalue { i32 } %8, 0 + %cmp.i = icmp eq i32 %a, 0 + %in1.in2 = select i1 %cmp.i, ptr addrspace(1) %1, ptr addrspace(1) %3 + %9 = load i32, ptr addrspace(1) %in1.in2, align 4 + store i32 %9, ptr addrspace(1) %5, align 4 + ret void +} + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(1) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(1) @_Z14clspv.resource.2(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(9) @_Z14clspv.resource.3(i32, i32, i32, i32, i32, i32, { { i32 } }) + +!14 = !{i32 2} +!15 = !{!16, !17, !18, !19} +!16 = !{!"in1", i32 0, i32 0, i32 0, i32 0, !"buffer"} +!17 = !{!"in2", i32 1, i32 1, i32 0, i32 0, !"buffer"} +!18 = !{!"out", i32 2, i32 2, i32 0, i32 0, !"buffer"} +!19 = !{!"a", i32 3, i32 3, i32 0, i32 4, !"pod_pushconstant"} + diff --git a/test/VariablePointers/select_ssbo_null.cl b/test/VariablePointers/select_ssbo_null.cl deleted file mode 100644 index c5e1895b4..000000000 --- a/test/VariablePointers/select_ssbo_null.cl +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// Only requires VariablePointersStorageBuffer because of selection against null. -kernel void foo(global int* in, global int* out, int a) { - global int* x = (a == 0) ? in : 0; - *out = *x; -} - -// CHECK-NOT: OpCapability VariablePointers -// CHECK: OpCapability VariablePointersStorageBuffer -// CHECK-NOT: OpCapability VariablePointers -// CHECK: OpExtension "SPV_KHR_variable_pointers" -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] -// CHECK: OpSelect [[ptr]] diff --git a/test/VariablePointers/select_ssbo_null.ll b/test/VariablePointers/select_ssbo_null.ll new file mode 100644 index 000000000..cba4be637 --- /dev/null +++ b/test/VariablePointers/select_ssbo_null.ll @@ -0,0 +1,48 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; Only requires VariablePointersStorageBuffer because of selection against null. +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpCapability VariablePointersStorageBuffer +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] +; CHECK: OpSelect [[ptr]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define spir_kernel void @foo(ptr addrspace(1) nocapture readonly align 4 %in, ptr addrspace(1) nocapture writeonly align 4 %out, { i32 } %podargs) !clspv.pod_args_impl !14 !kernel_arg_map !15 { +entry: + %0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %1 = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0 + %2 = call ptr addrspace(1) @_Z14clspv.resource.1(i32 0, i32 1, i32 0, i32 1, i32 1, i32 0, { [0 x i32] } zeroinitializer) + %3 = getelementptr { [0 x i32] }, ptr addrspace(1) %2, i32 0, i32 0, i32 0 + %4 = call ptr addrspace(9) @_Z14clspv.resource.2(i32 -1, i32 2, i32 5, i32 2, i32 2, i32 0, { { i32 } } zeroinitializer) + %5 = getelementptr { { i32 } }, ptr addrspace(9) %4, i32 0, i32 0 + %6 = load { i32 }, ptr addrspace(9) %5, align 4 + %a = extractvalue { i32 } %6, 0 + %cmp.i = icmp eq i32 %a, 0 + %in. = select i1 %cmp.i, ptr addrspace(1) %1, ptr addrspace(1) null + %7 = load i32, ptr addrspace(1) %in., align 4 + store i32 %7, ptr addrspace(1) %3, align 4 + ret void +} + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(1) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(9) @_Z14clspv.resource.2(i32, i32, i32, i32, i32, i32, { { i32 } }) + +!14 = !{i32 2} +!15 = !{!16, !17, !18} +!16 = !{!"in", i32 0, i32 0, i32 0, i32 0, !"buffer"} +!17 = !{!"out", i32 1, i32 1, i32 0, i32 0, !"buffer"} +!18 = !{!"a", i32 2, i32 2, i32 0, i32 4, !"pod_pushconstant"} + diff --git a/test/VariablePointers/select_ssbo_same_buffer.cl b/test/VariablePointers/select_ssbo_same_buffer.cl deleted file mode 100644 index 105d9f54f..000000000 --- a/test/VariablePointers/select_ssbo_same_buffer.cl +++ /dev/null @@ -1,18 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv - -// LLVM optimizes the selection to be between 1 and 2 and not pointers, so no -// variable pointers are required. -kernel void foo(global int* in, global int* out, int a) { - global int* x = in + 1; - global int* y = in + 2; - global int* z = (a == 0) ? x : y; - *out = *z; -} - -// CHECK-NOT: OpCapability VariablePointers -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] -// CHECK-NOT: OpSelect [[ptr]] diff --git a/test/VariablePointers/select_ssbo_same_buffer.ll b/test/VariablePointers/select_ssbo_same_buffer.ll new file mode 100644 index 000000000..7bf6c5570 --- /dev/null +++ b/test/VariablePointers/select_ssbo_same_buffer.ll @@ -0,0 +1,48 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; Only requires VariablePointersStorageBuffer because of selection in same buffer. +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpCapability VariablePointersStorageBuffer +; CHECK-NOT: OpCapability VariablePointers +; CHECK: OpExtension "SPV_KHR_variable_pointers" +; CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 +; CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer StorageBuffer [[uint]] +; CHECK: OpSelect [[ptr]] + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define spir_kernel void @foo(ptr addrspace(1) nocapture readonly align 4 %in, ptr addrspace(1) nocapture writeonly align 4 %out, { i32 } %podargs) !clspv.pod_args_impl !14 !kernel_arg_map !15 { +entry: + %0 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %1 = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 0 + %other = getelementptr { [0 x i32] }, ptr addrspace(1) %0, i32 0, i32 0, i32 1 + %2 = call ptr addrspace(1) @_Z14clspv.resource.1(i32 0, i32 1, i32 0, i32 1, i32 1, i32 0, { [0 x i32] } zeroinitializer) + %3 = getelementptr { [0 x i32] }, ptr addrspace(1) %2, i32 0, i32 0, i32 0 + %4 = call ptr addrspace(9) @_Z14clspv.resource.2(i32 -1, i32 2, i32 5, i32 2, i32 2, i32 0, { { i32 } } zeroinitializer) + %5 = getelementptr { { i32 } }, ptr addrspace(9) %4, i32 0, i32 0 + %6 = load { i32 }, ptr addrspace(9) %5, align 4 + %a = extractvalue { i32 } %6, 0 + %cmp.i = icmp eq i32 %a, 0 + %in. = select i1 %cmp.i, ptr addrspace(1) %1, ptr addrspace(1) %other + %7 = load i32, ptr addrspace(1) %in., align 4 + store i32 %7, ptr addrspace(1) %3, align 4 + ret void +} + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(1) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(9) @_Z14clspv.resource.2(i32, i32, i32, i32, i32, i32, { { i32 } }) + +!14 = !{i32 2} +!15 = !{!16, !17, !18} +!16 = !{!"in", i32 0, i32 0, i32 0, i32 0, !"buffer"} +!17 = !{!"out", i32 1, i32 1, i32 0, i32 0, !"buffer"} +!18 = !{!"a", i32 2, i32 2, i32 0, i32 4, !"pod_pushconstant"} diff --git a/test/VariablePointers/select_wg.cl b/test/VariablePointers/select_wg.cl deleted file mode 100644 index b757fb251..000000000 --- a/test/VariablePointers/select_wg.cl +++ /dev/null @@ -1,20 +0,0 @@ -// RUN: clspv %target %s -o %t.spv -// RUN: spirv-dis -o %t2.spvasm %t.spv -// RUN: FileCheck %s < %t2.spvasm -// RUN: spirv-val --target-env vulkan1.0 %t.spv -// TODO(#1292) -// XFAIL: * - -// LLVM optimizes the selection to be between 1 and 2 and not pointers, so no -// variable pointers are required. -kernel void foo(local int* in, global int* out, int a) { - local int* x = in + 1; - local int* y = in + 2; - local int* z = (a == 0) ? x : y; - *out = *z; -} - -// CHECK-NOT: OpCapability VariablePointers -// CHECK: [[uint:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0 -// CHECK: [[ptr:%[a-zA-Z0-9_]+]] = OpTypePointer Workgroup [[uint]] -// CHECK-NOT: OpSelect [[ptr]] diff --git a/test/VariablePointers/select_wg.ll b/test/VariablePointers/select_wg.ll new file mode 100644 index 000000000..0e4798d6b --- /dev/null +++ b/test/VariablePointers/select_wg.ll @@ -0,0 +1,45 @@ +; RUN: clspv-opt %s -o %t -producer-out-file %t.spv --passes=spirv-producer +; RUN: spirv-dis %t.spv -o %t.spvasm +; RUN: spirv-val --target-env vulkan1.0 %t.spv +; RUN: FileCheck %s < %t.spvasm + +; CHECK: OpCapability VariablePointers + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +@__spirv_WorkgroupSize = local_unnamed_addr addrspace(8) global <3 x i32> zeroinitializer + +define dso_local spir_kernel void @foo(ptr addrspace(3) nocapture readonly align 4 %in, ptr addrspace(1) nocapture writeonly align 4 %out, i32 %a, i32 %b, i32 %c) !clspv.pod_args_impl !8 { +entry: + %0 = call ptr addrspace(3) @_Z11clspv.local.3(i32 3, [0 x i32] zeroinitializer) + %1 = call ptr addrspace(1) @_Z14clspv.resource.0(i32 0, i32 0, i32 0, i32 1, i32 0, i32 0, { [0 x i32] } zeroinitializer) + %2 = getelementptr { [0 x i32] }, ptr addrspace(1) %1, i32 0, i32 0, i32 0 + %3 = call ptr addrspace(6) @_Z14clspv.resource.1(i32 0, i32 1, i32 4, i32 2, i32 1, i32 0, { i32 } zeroinitializer) + %4 = getelementptr { i32 }, ptr addrspace(6) %3, i32 0, i32 0 + %5 = load i32, ptr addrspace(6) %4, align 4 + %6 = call ptr addrspace(6) @_Z14clspv.resource.2(i32 0, i32 2, i32 4, i32 3, i32 2, i32 0, { i32 } zeroinitializer) + %7 = getelementptr { i32 }, ptr addrspace(6) %6, i32 0, i32 0 + %8 = load i32, ptr addrspace(6) %7, align 4 + %9 = call ptr addrspace(6) @_Z14clspv.resource.3(i32 0, i32 3, i32 4, i32 4, i32 3, i32 0, { i32 } zeroinitializer) + %10 = getelementptr { i32 }, ptr addrspace(6) %9, i32 0, i32 0 + %11 = load i32, ptr addrspace(6) %10, align 4 + %cmp = icmp eq i32 %5, 0 + %b.c = select i1 %cmp, ptr addrspace(6) %7, ptr addrspace(6) %4 + %ld = load i32, ptr addrspace(6) %b.c, align 4 + store i32 %ld, ptr addrspace(1) %2, align 4 + ret void +} + +declare ptr addrspace(1) @_Z14clspv.resource.0(i32, i32, i32, i32, i32, i32, { [0 x i32] }) + +declare ptr addrspace(6) @_Z14clspv.resource.1(i32, i32, i32, i32, i32, i32, { i32 }) + +declare ptr addrspace(6) @_Z14clspv.resource.2(i32, i32, i32, i32, i32, i32, { i32 }) + +declare ptr addrspace(6) @_Z14clspv.resource.3(i32, i32, i32, i32, i32, i32, { i32 }) + +declare ptr addrspace(3) @_Z11clspv.local.3(i32, [0 x i32]) + +!8 = !{i32 1} +