[Mlir-commits] [mlir] [mlir][SPIR-V] Validate float types in parseAndVerifyType (PR #201910)

Arseniy Obolenskiy llvmlistbot at llvm.org
Fri Jun 5 12:02:47 PDT 2026


https://github.com/aobolensk created https://github.com/llvm/llvm-project/pull/201910

None

>From d8c87778ca46e264442e71eb8e2da4325caad002 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Fri, 5 Jun 2026 21:02:10 +0200
Subject: [PATCH] [mlir][SPIR-V] Validate float types in parseAndVerifyType

---
 mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp |  7 ++++++-
 mlir/test/Dialect/SPIRV/IR/types.mlir      | 16 ++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
index 5821391b426cb..0e851fe68389c 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
@@ -173,7 +173,12 @@ static Type parseAndVerifyType(SPIRVDialect const &dialect,
 
   // Check other allowed types.
   if (auto t = dyn_cast<FloatType>(type)) {
-    // TODO: All float types are allowed for now, but this should be fixed.
+    if (!ScalarType::isValid(t)) {
+      parser.emitError(typeLoc,
+                       "only 8/16/32/64-bit float type allowed but found ")
+          << type;
+      return Type();
+    }
   } else if (auto t = dyn_cast<IntegerType>(type)) {
     if (!ScalarType::isValid(t)) {
       parser.emitError(typeLoc,
diff --git a/mlir/test/Dialect/SPIRV/IR/types.mlir b/mlir/test/Dialect/SPIRV/IR/types.mlir
index f665a83ed8826..3a36d95b9654c 100644
--- a/mlir/test/Dialect/SPIRV/IR/types.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/types.mlir
@@ -18,6 +18,12 @@ func.func private @array_type_stride(!spirv.array< 4 x !spirv.array<4 x f32, str
 // CHECK: func private @vector_array_type_bf16(!spirv.array<32 x vector<4xbf16>>)
 func.func private @vector_array_type_bf16(!spirv.array<32 x vector<4xbf16> >) -> ()
 
+// CHECK: func private @scalar_array_type_f64(!spirv.array<16 x f16>, !spirv.array<16 x f64>)
+func.func private @scalar_array_type_f64(!spirv.array<16xf16>, !spirv.array<16xf64>) -> ()
+
+// CHECK: func private @scalar_array_type_f8(!spirv.array<16 x f8E4M3FN>, !spirv.array<16 x f8E5M2>)
+func.func private @scalar_array_type_f8(!spirv.array<16xf8E4M3FN>, !spirv.array<16xf8E5M2>) -> ()
+
 // -----
 
 // expected-error @+1 {{expected '<'}}
@@ -65,6 +71,16 @@ func.func private @i256_type(!spirv.array<4xi256>) -> ()
 
 // -----
 
+// expected-error @+1 {{only 8/16/32/64-bit float type allowed but found 'f80'}}
+func.func private @f80_type(!spirv.array<4xf80>) -> ()
+
+// -----
+
+// expected-error @+1 {{only 8/16/32/64-bit float type allowed but found 'f128'}}
+func.func private @f128_type(!spirv.array<4xf128>) -> ()
+
+// -----
+
 // expected-error @+1 {{cannot use 'index' to compose SPIR-V types}}
 func.func private @index_type(!spirv.array<4xindex>) -> ()
 



More information about the Mlir-commits mailing list