-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SPIRV] Porting 4 tests from Translator #151678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Duplicate alignment - Duplicate types - Non-function storage class for global variable - Generating image instructions from opencl builtins
Member
|
@llvm/pr-subscribers-backend-spir-v Author: Ebin-McW (EbinJose2002) ChangesTests that checks:
Full diff: https://github.com/llvm/llvm-project/pull/151678.diff 4 Files Affected:
diff --git a/llvm/test/CodeGen/SPIRV/GlobalVarAddrspace.ll b/llvm/test/CodeGen/SPIRV/GlobalVarAddrspace.ll
new file mode 100644
index 0000000000000..6841f15e7f5b4
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/GlobalVarAddrspace.ll
@@ -0,0 +1,23 @@
+; This test case checks that LLVM -> SPIR-V translation produces valid
+; SPIR-V module, where a global variable, defined with non-default
+; address space, have correct non-function storage class.
+;
+; No additional checks are needed in addition to simple translation
+; to SPIR-V. In case of an error newly produced SPIR-V module validation
+; would fail due to spirv-val that detects problematic SPIR-V code from
+; translator and reports it as the following error:
+;
+; "Variables can not have a function[7] storage class outside of a function".
+;
+; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK: %[[#Ptr:]] = OpTypePointer CrossWorkgroup %[[#]]
+; CHECK: %[[#]] = OpVariable %[[#Ptr]] CrossWorkgroup %[[#]]
+
+@G = addrspace(1) global i1 true
+
+define spir_func i1 @f(i1 %0) {
+ store i1 %0, ptr addrspace(1) @G, align 1
+ ret i1 %0
+}
diff --git a/llvm/test/CodeGen/SPIRV/SamplerArgNonKernel.ll b/llvm/test/CodeGen/SPIRV/SamplerArgNonKernel.ll
new file mode 100644
index 0000000000000..5b3a5d8ebb733
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/SamplerArgNonKernel.ll
@@ -0,0 +1,37 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+;CHECK: OpEntryPoint Kernel %[[#KernelId:]]
+;CHECK: %[[#image2d_t:]] = OpTypeImage
+;CHECK: %[[#sampler_t:]] = OpTypeSampler
+;CHECK: %[[#sampled_image_t:]] = OpTypeSampledImage
+
+define spir_func float @test(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %Img, target("spirv.Sampler") %Smp) {
+;CHECK-NOT: %[[#KernelId]] = OpFunction %[[#]]
+;CHECK: OpFunction
+;CHECK: %[[#image:]] = OpFunctionParameter %[[#image2d_t]]
+;CHECK: %[[#sampler:]] = OpFunctionParameter %[[#sampler_t]]
+entry:
+ %call = call spir_func <4 x i32> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_i(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %Img, target("spirv.Sampler") %Smp, <2 x i32> zeroinitializer)
+;CHECK: %[[#sampled_image:]] = OpSampledImage %[[#sampled_image_t]] %[[#image]] %[[#sampler]]
+;CHECK: %[[#]] = OpImageSampleExplicitLod %[[#]] %[[#sampled_image]] %[[#]] Lod %[[#]]
+
+ %0 = extractelement <4 x i32> %call, i32 0
+ %conv = sitofp i32 %0 to float
+ ret float %conv
+}
+
+declare spir_func <4 x i32> @_Z11read_imagef11ocl_image2d11ocl_samplerDv2_i(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0), i32, <2 x i32>)
+
+define spir_kernel void @test2(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %Img, target("spirv.Sampler") %Smp, ptr addrspace(1) %result) {
+;CHECK: %[[#KernelId]] = OpFunction %[[#]]
+entry:
+ %call = call spir_func float @test(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %Img, target("spirv.Sampler") %Smp)
+ %0 = load float, ptr addrspace(1) %result, align 4
+ %add = fadd float %0, %call
+ store float %add, ptr addrspace(1) %result, align 4
+ ret void
+}
diff --git a/llvm/test/CodeGen/SPIRV/align-duplicate.ll b/llvm/test/CodeGen/SPIRV/align-duplicate.ll
new file mode 100644
index 0000000000000..fd23653761a0b
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/align-duplicate.ll
@@ -0,0 +1,16 @@
+; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o -
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; Test that duplicate align information does not result in SPIR-V validation
+; errors due to duplicate Alignment Decorations.
+
+;CHECK: OpDecorate %[[#Var:]] Alignment
+;CHECK: %[[#Var]] = OpVariable %[[#]]
+
+define spir_func void @f() {
+ %res = alloca i16, align 2, !spirv.Decorations !1
+ ret void
+}
+
+!1 = !{!2}
+!2 = !{i32 44, i32 2}
diff --git a/llvm/test/CodeGen/SPIRV/duplicate-types.ll b/llvm/test/CodeGen/SPIRV/duplicate-types.ll
new file mode 100644
index 0000000000000..81c72d8b98917
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/duplicate-types.ll
@@ -0,0 +1,16 @@
+; Check that we don't end up with duplicated array types in TypeMap.
+; No FileCheck needed, we only want to check the absence of errors.
+; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o -
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK: %[[#]] = OpTypeArray %[[#]] %[[#]]
+; CHECK-NOT: OpTypeArray
+
+%duplicate = type { [2 x ptr addrspace(4)] }
+
+define spir_kernel void @foo() {
+entry:
+ alloca [2 x ptr addrspace(4)], align 8
+ alloca %duplicate, align 8
+ ret void
+}
|
Co-authored-by: Michal Paszkowski <[email protected]>
Co-authored-by: Michal Paszkowski <[email protected]>
Co-authored-by: Michal Paszkowski <[email protected]>
michalpaszkowski
approved these changes
Aug 3, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Tests that checks: