[llvm] [SPIR-V] Add tests for lowering unmangled builtins calls (PR #84319)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 05:12:09 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-spir-v

Author: Michal Paszkowski (michalpaszkowski)

<details>
<summary>Changes</summary>

This pull request adds initial tests for lowering unmangled SPIR-V builtin function calls. One `; XFAIL: *` test is added to demonstrate the reliance on mangled function names in SPIRVBuiltins.cpp (ultimately the types should be restored from either the TargetExtType or GR).

The pull request also moves and renames relevant builtin calls tests to `/builtins/`.

---
Full diff: https://github.com/llvm/llvm-project/pull/84319.diff


19 Files Affected:

- (renamed) llvm/test/CodeGen/SPIRV/builtins/FOrdGreaterThanEqual-bool.ll (+1) 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/SampledImage-return-type.ll () 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/SpecConstant-decoration.ll () 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/SpecConstant.ll () 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/SpecConstantComposite.ll () 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/bool-spirv-specconstant.ll () 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/builtin-calls.ll (+1) 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/builtin-vars-arithmetics.ll () 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/builtin-vars-decorate.ll () 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/builtin-vars-opt.ll () 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/builtin-vars.ll () 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/relationals.ll (+1) 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/select.ll (+1) 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/spirv-load-store.ll (+7-3) 
- (renamed) llvm/test/CodeGen/SPIRV/builtins/spirv-types.ll () 
- (added) llvm/test/CodeGen/SPIRV/builtins/unmangled-SampledImage-return-type.ll (+29) 
- (added) llvm/test/CodeGen/SPIRV/builtins/unmangled-builtin-calls.ll (+17) 
- (added) llvm/test/CodeGen/SPIRV/builtins/unmangled-select.ll (+15) 
- (added) llvm/test/CodeGen/SPIRV/builtins/unmangled-spirv-load-store.ll (+20) 


``````````diff
diff --git a/llvm/test/CodeGen/SPIRV/FOrdGreaterThanEqual_bool.ll b/llvm/test/CodeGen/SPIRV/builtins/FOrdGreaterThanEqual-bool.ll
similarity index 81%
rename from llvm/test/CodeGen/SPIRV/FOrdGreaterThanEqual_bool.ll
rename to llvm/test/CodeGen/SPIRV/builtins/FOrdGreaterThanEqual-bool.ll
index 735b35d757e7d8..24491f313490b2 100644
--- a/llvm/test/CodeGen/SPIRV/FOrdGreaterThanEqual_bool.ll
+++ b/llvm/test/CodeGen/SPIRV/builtins/FOrdGreaterThanEqual-bool.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
 
 ; CHECK-SPIRV:     OpFOrdGreaterThanEqual
 ; CHECK-SPIRV-NOT: OpSelect
diff --git a/llvm/test/CodeGen/SPIRV/SampledImageRetType.ll b/llvm/test/CodeGen/SPIRV/builtins/SampledImage-return-type.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/SampledImageRetType.ll
rename to llvm/test/CodeGen/SPIRV/builtins/SampledImage-return-type.ll
diff --git a/llvm/test/CodeGen/SPIRV/spec_const_decoration.ll b/llvm/test/CodeGen/SPIRV/builtins/SpecConstant-decoration.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/spec_const_decoration.ll
rename to llvm/test/CodeGen/SPIRV/builtins/SpecConstant-decoration.ll
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/spec_const.ll b/llvm/test/CodeGen/SPIRV/builtins/SpecConstant.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/transcoding/spec_const.ll
rename to llvm/test/CodeGen/SPIRV/builtins/SpecConstant.ll
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/SpecConstantComposite.ll b/llvm/test/CodeGen/SPIRV/builtins/SpecConstantComposite.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/transcoding/SpecConstantComposite.ll
rename to llvm/test/CodeGen/SPIRV/builtins/SpecConstantComposite.ll
diff --git a/llvm/test/CodeGen/SPIRV/SpecConstants/bool-spirv-specconstant.ll b/llvm/test/CodeGen/SPIRV/builtins/bool-spirv-specconstant.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/SpecConstants/bool-spirv-specconstant.ll
rename to llvm/test/CodeGen/SPIRV/builtins/bool-spirv-specconstant.ll
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/builtin_calls.ll b/llvm/test/CodeGen/SPIRV/builtins/builtin-calls.ll
similarity index 86%
rename from llvm/test/CodeGen/SPIRV/transcoding/builtin_calls.ll
rename to llvm/test/CodeGen/SPIRV/builtins/builtin-calls.ll
index 9b1ce76631809d..0a02a8bf56ace5 100644
--- a/llvm/test/CodeGen/SPIRV/transcoding/builtin_calls.ll
+++ b/llvm/test/CodeGen/SPIRV/builtins/builtin-calls.ll
@@ -1,4 +1,5 @@
 ; 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 %}
 
 ; CHECK-SPIRV-DAG: OpDecorate %[[#Id:]] BuiltIn GlobalInvocationId
 ; CHECK-SPIRV-DAG: OpDecorate %[[#Id:]] BuiltIn GlobalLinearId
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/builtin_vars_arithmetics.ll b/llvm/test/CodeGen/SPIRV/builtins/builtin-vars-arithmetics.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/transcoding/builtin_vars_arithmetics.ll
rename to llvm/test/CodeGen/SPIRV/builtins/builtin-vars-arithmetics.ll
diff --git a/llvm/test/CodeGen/SPIRV/builtin_vars-decorate.ll b/llvm/test/CodeGen/SPIRV/builtins/builtin-vars-decorate.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/builtin_vars-decorate.ll
rename to llvm/test/CodeGen/SPIRV/builtins/builtin-vars-decorate.ll
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/builtin_vars_opt.ll b/llvm/test/CodeGen/SPIRV/builtins/builtin-vars-opt.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/transcoding/builtin_vars_opt.ll
rename to llvm/test/CodeGen/SPIRV/builtins/builtin-vars-opt.ll
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/builtin_vars.ll b/llvm/test/CodeGen/SPIRV/builtins/builtin-vars.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/transcoding/builtin_vars.ll
rename to llvm/test/CodeGen/SPIRV/builtins/builtin-vars.ll
diff --git a/llvm/test/CodeGen/SPIRV/relationals.ll b/llvm/test/CodeGen/SPIRV/builtins/relationals.ll
similarity index 95%
rename from llvm/test/CodeGen/SPIRV/relationals.ll
rename to llvm/test/CodeGen/SPIRV/builtins/relationals.ll
index 1644dc7c03d911..13a9869ec17ed3 100644
--- a/llvm/test/CodeGen/SPIRV/relationals.ll
+++ b/llvm/test/CodeGen/SPIRV/builtins/relationals.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
 
 declare dso_local spir_func <4 x i8> @_Z13__spirv_IsNanIDv4_aDv4_fET_T0_(<4 x float>)
 declare dso_local spir_func <4 x i8> @_Z13__spirv_IsInfIDv4_aDv4_fET_T0_(<4 x float>)
diff --git a/llvm/test/CodeGen/SPIRV/select.ll b/llvm/test/CodeGen/SPIRV/builtins/select.ll
similarity index 80%
rename from llvm/test/CodeGen/SPIRV/select.ll
rename to llvm/test/CodeGen/SPIRV/builtins/select.ll
index b34e91be1dbcda..6a42b63dcd34a6 100644
--- a/llvm/test/CodeGen/SPIRV/select.ll
+++ b/llvm/test/CodeGen/SPIRV/builtins/select.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
 
 ; CHECK-SPIRV: OpSelect
 
diff --git a/llvm/test/CodeGen/SPIRV/spirv-load-store.ll b/llvm/test/CodeGen/SPIRV/builtins/spirv-load-store.ll
similarity index 60%
rename from llvm/test/CodeGen/SPIRV/spirv-load-store.ll
rename to llvm/test/CodeGen/SPIRV/builtins/spirv-load-store.ll
index a82bf0ab2e01f6..8b80e0308dd0e1 100644
--- a/llvm/test/CodeGen/SPIRV/spirv-load-store.ll
+++ b/llvm/test/CodeGen/SPIRV/builtins/spirv-load-store.ll
@@ -1,9 +1,13 @@
 ; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
 ;; Translate SPIR-V friendly OpLoad and OpStore calls
 
-; CHECK: %[[#CONST:]] = OpConstant %[[#]] 42
-; CHECK: OpStore %[[#PTR:]] %[[#CONST]] Volatile|Aligned 4
-; CHECK: %[[#]] = OpLoad %[[#]] %[[#PTR]]
+; CHECK-DAG: %[[#INT32:]] = OpTypeInt 32 0
+; CHECK-DAG: %[[#CONST:]] = OpConstant %[[#INT32]] 42
+; CHECK-DAG: %[[#PTRINT32:]] = OpTypePointer CrossWorkgroup %[[#INT32]]
+; CHECK: %[[#BITCASTorPARAMETER:]] = {{OpBitcast|OpFunctionParameter}}{{.*}}%[[#PTRINT32]]{{.*}}
+
+; CHECK: OpStore %[[#BITCASTorPARAMETER]] %[[#CONST]] Volatile|Aligned 4
+; CHECK: %[[#]] = OpLoad %[[#]] %[[#BITCASTorPARAMETER]]
 
 define weak_odr dso_local spir_kernel void @foo(i32 addrspace(1)* %var) {
 entry:
diff --git a/llvm/test/CodeGen/SPIRV/transcoding/spirv-types.ll b/llvm/test/CodeGen/SPIRV/builtins/spirv-types.ll
similarity index 100%
rename from llvm/test/CodeGen/SPIRV/transcoding/spirv-types.ll
rename to llvm/test/CodeGen/SPIRV/builtins/spirv-types.ll
diff --git a/llvm/test/CodeGen/SPIRV/builtins/unmangled-SampledImage-return-type.ll b/llvm/test/CodeGen/SPIRV/builtins/unmangled-SampledImage-return-type.ll
new file mode 100644
index 00000000000000..3459598735e65a
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/builtins/unmangled-SampledImage-return-type.ll
@@ -0,0 +1,29 @@
+; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+
+; XFAIL: *
+
+; CHECK: %[[#image1d_t:]] = OpTypeImage
+; CHECK: %[[#sampler_t:]] = OpTypeSampler
+; CHECK: %[[#sampled_image_t:]] = OpTypeSampledImage
+
+declare dso_local spir_func ptr addrspace(4) @__spirv_SampledImage(target("spirv.Image", void, 0, 0, 0, 0, 0, 0, 0) %0, target("spirv.Sampler") %1) local_unnamed_addr
+
+declare dso_local spir_func <4 x float> @__spirv_ImageSampleExplicitLod(ptr addrspace(4) %0, i32 %1, i32 %2, float %3) local_unnamed_addr
+
+ at __spirv_BuiltInGlobalInvocationId = external dso_local local_unnamed_addr addrspace(2) constant <3 x i64>, align 32
+
+define weak_odr dso_local spir_kernel void @_ZTS17image_kernel_readILi1EE(target("spirv.Image", void, 0, 0, 0, 0, 0, 0, 0), target("spirv.Sampler")) {
+; CHECK: OpFunction
+; CHECK: %[[#image:]] = OpFunctionParameter %[[#image1d_t]]
+; CHECK: %[[#sampler:]] = OpFunctionParameter %[[#sampler_t]]
+  %3 = load <3 x i64>, ptr addrspace(2) @__spirv_BuiltInGlobalInvocationId, align 32
+  %4 = extractelement <3 x i64> %3, i64 0
+  %5 = trunc i64 %4 to i32
+  %6 = call spir_func ptr addrspace(4) @__spirv_SampledImage(target("spirv.Image", void, 0, 0, 0, 0, 0, 0, 0) %0, target("spirv.Sampler") %1)
+  %7 = call spir_func <4 x float> @__spirv_ImageSampleExplicitLod(ptr addrspace(4) %6, i32 %5, i32 2, float 0.000000e+00)
+
+; CHECK: %[[#sampled_image:]] = OpSampledImage %[[#sampled_image_t]] %[[#image]] %[[#sampler]]
+; CHECK: %[[#]] = OpImageSampleExplicitLod %[[#]] %[[#sampled_image]] %[[#]] {{.*}} %[[#]]
+
+  ret void
+}
diff --git a/llvm/test/CodeGen/SPIRV/builtins/unmangled-builtin-calls.ll b/llvm/test/CodeGen/SPIRV/builtins/unmangled-builtin-calls.ll
new file mode 100644
index 00000000000000..4519d52dc8f30e
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/builtins/unmangled-builtin-calls.ll
@@ -0,0 +1,17 @@
+; 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 %}
+
+; CHECK-SPIRV-DAG: OpDecorate %[[#Id:]] BuiltIn GlobalInvocationId
+; CHECK-SPIRV-DAG: OpDecorate %[[#Id:]] BuiltIn GlobalLinearId
+; CHECK-SPIRV:     %[[#Id:]] = OpVariable %[[#]]
+; CHECK-SPIRV:     %[[#Id:]] = OpVariable %[[#]]
+
+define spir_kernel void @f() {
+entry:
+  %0 = call spir_func i32 @__spirv_BuiltInGlobalLinearId()
+  %1 = call spir_func i64 @__spirv_BuiltInGlobalInvocationId(i32 1)
+  ret void
+}
+
+declare spir_func i32 @__spirv_BuiltInGlobalLinearId()
+declare spir_func i64 @__spirv_BuiltInGlobalInvocationId(i32)
diff --git a/llvm/test/CodeGen/SPIRV/builtins/unmangled-select.ll b/llvm/test/CodeGen/SPIRV/builtins/unmangled-select.ll
new file mode 100644
index 00000000000000..e88fa49a8f55f9
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/builtins/unmangled-select.ll
@@ -0,0 +1,15 @@
+; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK-SPIRV: OpSelect
+
+;; LLVM IR was generated with -cl-std=c++ option
+
+define spir_kernel void @test(i32 %op1, i32 %op2) {
+entry:
+  %0 = trunc i8 undef to i1
+  %call = call spir_func i32 @__spirv_Select(i1 zeroext %0, i32 %op1, i32 %op2)
+  ret void
+}
+
+declare spir_func i32 @__spirv_Select(i1 zeroext, i32, i32)
diff --git a/llvm/test/CodeGen/SPIRV/builtins/unmangled-spirv-load-store.ll b/llvm/test/CodeGen/SPIRV/builtins/unmangled-spirv-load-store.ll
new file mode 100644
index 00000000000000..19fc7967a3b63b
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/builtins/unmangled-spirv-load-store.ll
@@ -0,0 +1,20 @@
+; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+
+; CHECK-DAG: %[[#INT8:]] = OpTypeInt 8 0
+; CHECK-DAG: %[[#INT32:]] = OpTypeInt 32 0
+; CHECK-DAG: %[[#CONST:]] = OpConstant %[[#INT32]] 42
+; CHECK-DAG: %[[#PTRINT8:]] = OpTypePointer CrossWorkgroup %[[#INT8]]
+; CHECK: %[[#BITCASTorPARAMETER:]] = {{OpBitcast|OpFunctionParameter}}{{.*}}%[[#PTRINT8]]{{.*}}
+
+; CHECK: OpStore %[[#BITCASTorPARAMETER]] %[[#CONST]] Volatile|Aligned 4
+; CHECK: %[[#]] = OpLoad %[[#]] %[[#BITCASTorPARAMETER]]
+
+define weak_odr dso_local spir_kernel void @foo(ptr addrspace(1) %var) {
+entry:
+  tail call spir_func void @__spirv_Store(ptr addrspace(1) %var, i32 42, i32 3, i32 4)
+  %value = tail call spir_func double @__spirv_Load(ptr addrspace(1) %var)
+  ret void
+}
+
+declare dso_local spir_func double @__spirv_Load(ptr addrspace(1)) local_unnamed_addr
+declare dso_local spir_func void @__spirv_Store(ptr addrspace(1), i32, i32, i32) local_unnamed_addr

``````````

</details>


https://github.com/llvm/llvm-project/pull/84319


More information about the llvm-commits mailing list