[Mlir-commits] [mlir] [MLIR] [SPIR-V] Verify element type in SPIR-V's vector-type verifier (PR #177787)
Gabriel Dehame
llvmlistbot at llvm.org
Sun Jan 25 09:45:15 PST 2026
https://github.com/gdehame updated https://github.com/llvm/llvm-project/pull/177787
>From 6225c240f4374035a52ffe27ee04d3f17b43e0b9 Mon Sep 17 00:00:00 2001
From: gdehame <gabrieldehame at gmail.com>
Date: Sat, 24 Jan 2026 20:01:55 +0100
Subject: [PATCH 1/2] Verify element type in SPIR-V's vector-type verifier
---
mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
index 7c3bfd72115e6..24d3bcfd9cee3 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
@@ -186,6 +186,13 @@ static Type parseAndVerifyType(SPIRVDialect const &dialect,
parser.emitError(typeLoc, "only 1-D vector allowed but found ") << t;
return Type();
}
+ if (!isa<ScalarType>(t.getElementType())) {
+ parser.emitError(typeLoc,
+ "vector element type has to be SPIR-V compatible "
+ "integer, float or boolean but found ")
+ << t.getElementType();
+ return Type();
+ }
if (t.getNumElements() > 4) {
parser.emitError(
typeLoc, "vector length has to be less than or equal to 4 but found ")
>From 7fa71f209f52d82a83dff6173fb39c24ae04e32f Mon Sep 17 00:00:00 2001
From: gdehame <gabrieldehame at gmail.com>
Date: Sun, 25 Jan 2026 18:45:03 +0100
Subject: [PATCH 2/2] Added test and reformulated error message
---
mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp | 3 +--
mlir/test/Dialect/SPIRV/IR/invalid.mlir | 8 ++++++++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
index 24d3bcfd9cee3..3c9a1942ca23b 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
@@ -188,8 +188,7 @@ static Type parseAndVerifyType(SPIRVDialect const &dialect,
}
if (!isa<ScalarType>(t.getElementType())) {
parser.emitError(typeLoc,
- "vector element type has to be SPIR-V compatible "
- "integer, float or boolean but found ")
+ "vector element type has to be SPIR-V scalar but found ")
<< t.getElementType();
return Type();
}
diff --git a/mlir/test/Dialect/SPIRV/IR/invalid.mlir b/mlir/test/Dialect/SPIRV/IR/invalid.mlir
index e0100748a0d68..84034f85b10eb 100644
--- a/mlir/test/Dialect/SPIRV/IR/invalid.mlir
+++ b/mlir/test/Dialect/SPIRV/IR/invalid.mlir
@@ -41,3 +41,11 @@ func.func @aligned_store_non_power_of_two(%arg0 : f32) -> () {
spirv.Store "Function" %0, %arg0 ["Aligned", 3] : f32
return
}
+
+// -----
+
+func.func @vector_with_non_spirv_scalar_element_type() -> () {
+ // expected-error at below {{vector element type has to be SPIR-V scalar but found 'index'}}
+ %0 = spirv.Variable : !spirv.ptr<vector<1xindex>, Function>
+ return
+}
More information about the Mlir-commits
mailing list