[llvm] [SPIR-V] Fix vload_half builtin argument count (PR #105585)

Konrad Krawiec via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 21 13:58:57 PDT 2024


https://github.com/konrad11901 created https://github.com/llvm/llvm-project/pull/105585

OpenCL's vload_half builtin expects two arguments, but the current TableGen definition expects three.
This change fixes the mismatch and adds a test to check this.

>From 03b7f794d1e710e0787142c4de050b302e0aba0d Mon Sep 17 00:00:00 2001
From: Konrad Krawiec <konrad at krawiec.cc>
Date: Wed, 21 Aug 2024 23:55:30 +0300
Subject: [PATCH] [SPIR-V] Fix vload_half builtin argument count

OpenCL's vload_half builtin expects two arguments,
but the current TableGen definition expects three.
This change fixes the mismatch and adds a test to check this.
---
 llvm/lib/Target/SPIRV/SPIRVBuiltins.td        |  2 +-
 llvm/test/CodeGen/SPIRV/opencl/vload_halfn.ll | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/SPIRV/opencl/vload_halfn.ll

diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.td b/llvm/lib/Target/SPIRV/SPIRVBuiltins.td
index 5c057a79afa0c3..dd97263316505b 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.td
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.td
@@ -1500,7 +1500,7 @@ foreach i = ["", "2", "3", "4", "8", "16"] in {
     defm : DemangledVectorLoadStoreBuiltin<"vload_half", 2, 2, 173>;
     defm : DemangledVectorLoadStoreBuiltin<"vstore_half", 3, 3, 175>;
   } else {
-    defm : DemangledVectorLoadStoreBuiltin<!strconcat("vload_half", i), 3, 3, 174>;
+    defm : DemangledVectorLoadStoreBuiltin<!strconcat("vload_half", i), 2, 2, 174>;
     defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore_half", i), 3, 3, 177>;
   }
   defm : DemangledVectorLoadStoreBuiltin<!strconcat("vload", i), 2, 2, 171>;
diff --git a/llvm/test/CodeGen/SPIRV/opencl/vload_halfn.ll b/llvm/test/CodeGen/SPIRV/opencl/vload_halfn.ll
new file mode 100644
index 00000000000000..abfae74afb659d
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/opencl/vload_halfn.ll
@@ -0,0 +1,15 @@
+; 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: %[[#IMPORT:]] = OpExtInstImport "OpenCL.std"
+
+; CHECK: %[[#FLOAT:]] = OpTypeFloat 32
+; CHECK: %[[#V2FLOAT:]] = OpTypeVector %[[#FLOAT]] 2
+
+define void @test(i64 %a, ptr addrspace(1) %b) {
+; CHECK: %[[#]] = OpExtInst %[[#V2FLOAT:]] %[[#IMPORT]] vload_halfn %[[#]] %[[#]] 2
+  %c = call spir_func <2 x float> @_Z11vload_half2mPU3AS1KDh(i64 %a, ptr addrspace(1) %b)
+  ret void
+}
+
+declare <2 x float> @_Z11vload_half2mPU3AS1KDh(i64, ptr addrspace(1))



More information about the llvm-commits mailing list