[llvm] [SPIRV] Porting 4 tests from Translator (PR #151678)

via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 3 12:28:51 PDT 2025


https://github.com/EbinJose2002 updated https://github.com/llvm/llvm-project/pull/151678

>From 0b48528847816078cc176e51e161ee1f26c4e140 Mon Sep 17 00:00:00 2001
From: EbinJose2002 <ebin.jose at multicorewareinc.com>
Date: Tue, 29 Jul 2025 11:03:00 +0530
Subject: [PATCH 1/4] Porting 4 tests from Translator that checks:  - Duplicate
 alignment  - Duplicate types  - Non-function storage class for global
 variable  - Generating image instructions from opencl builtins

---
 llvm/test/CodeGen/SPIRV/GlobalVarAddrspace.ll | 23 ++++++++++++
 .../test/CodeGen/SPIRV/SamplerArgNonKernel.ll | 37 +++++++++++++++++++
 llvm/test/CodeGen/SPIRV/align-duplicate.ll    | 16 ++++++++
 llvm/test/CodeGen/SPIRV/duplicate-types.ll    | 16 ++++++++
 4 files changed, 92 insertions(+)
 create mode 100644 llvm/test/CodeGen/SPIRV/GlobalVarAddrspace.ll
 create mode 100644 llvm/test/CodeGen/SPIRV/SamplerArgNonKernel.ll
 create mode 100644 llvm/test/CodeGen/SPIRV/align-duplicate.ll
 create mode 100644 llvm/test/CodeGen/SPIRV/duplicate-types.ll

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 %[[#]]
+
+ at 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
+}

>From 23f928397217f09cd8e2f03a0a591224a6ec4df3 Mon Sep 17 00:00:00 2001
From: Ebin-McW <ebin.jose at multicorewareinc.com>
Date: Mon, 4 Aug 2025 00:55:08 +0530
Subject: [PATCH 2/4] Update llvm/test/CodeGen/SPIRV/GlobalVarAddrspace.ll

Co-authored-by: Michal Paszkowski <michal at michalpaszkowski.com>
---
 llvm/test/CodeGen/SPIRV/GlobalVarAddrspace.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/CodeGen/SPIRV/GlobalVarAddrspace.ll b/llvm/test/CodeGen/SPIRV/GlobalVarAddrspace.ll
index 6841f15e7f5b4..2bccfde36e8a5 100644
--- a/llvm/test/CodeGen/SPIRV/GlobalVarAddrspace.ll
+++ b/llvm/test/CodeGen/SPIRV/GlobalVarAddrspace.ll
@@ -9,7 +9,7 @@
 ;
 ; "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: 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 %}
 
 ; CHECK: %[[#Ptr:]] = OpTypePointer CrossWorkgroup %[[#]]

>From ea3b9413ef718f14dd86fddbf0cc7443908f6762 Mon Sep 17 00:00:00 2001
From: Ebin-McW <ebin.jose at multicorewareinc.com>
Date: Mon, 4 Aug 2025 00:56:47 +0530
Subject: [PATCH 3/4] Update llvm/test/CodeGen/SPIRV/align-duplicate.ll

Co-authored-by: Michal Paszkowski <michal at michalpaszkowski.com>
---
 llvm/test/CodeGen/SPIRV/align-duplicate.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/CodeGen/SPIRV/align-duplicate.ll b/llvm/test/CodeGen/SPIRV/align-duplicate.ll
index fd23653761a0b..8a8d8aec14a1c 100644
--- a/llvm/test/CodeGen/SPIRV/align-duplicate.ll
+++ b/llvm/test/CodeGen/SPIRV/align-duplicate.ll
@@ -1,4 +1,4 @@
-; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o -
+; 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 %}
 
 ; Test that duplicate align information does not result in SPIR-V validation

>From 3fd969a8b55dbabb1c1e8156614917b2b1c0b262 Mon Sep 17 00:00:00 2001
From: Ebin-McW <ebin.jose at multicorewareinc.com>
Date: Mon, 4 Aug 2025 00:58:43 +0530
Subject: [PATCH 4/4] Update llvm/test/CodeGen/SPIRV/duplicate-types.ll

Co-authored-by: Michal Paszkowski <michal at michalpaszkowski.com>
---
 llvm/test/CodeGen/SPIRV/duplicate-types.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/CodeGen/SPIRV/duplicate-types.ll b/llvm/test/CodeGen/SPIRV/duplicate-types.ll
index 81c72d8b98917..df1ae0431b3a2 100644
--- a/llvm/test/CodeGen/SPIRV/duplicate-types.ll
+++ b/llvm/test/CodeGen/SPIRV/duplicate-types.ll
@@ -1,6 +1,6 @@
 ; 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: llc -verify-machineinstrs -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 %[[#]] %[[#]]



More information about the llvm-commits mailing list