-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[mlir][spirv] Handle vectors of integers of unsupported width #118663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-mlir-spirv @llvm/pr-subscribers-mlir Author: Jakub Kuderski (kuhar) ChangesFixes: #118612 Full diff: https://github.com/llvm/llvm-project/pull/118663.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
index f5700059f68ee2..d8b67bb4389ea2 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
@@ -299,6 +299,10 @@ convertScalarType(const spirv::TargetEnv &targetEnv,
/// supported integer types.
static Type convertSubByteIntegerType(const SPIRVConversionOptions &options,
IntegerType type) {
+ if (type.getWidth() > 8) {
+ LLVM_DEBUG(llvm::dbgs() << "not a subbyte type\n");
+ return nullptr;
+ }
if (options.subByteTypeStorage != SPIRVSubByteTypeStorage::Packed) {
LLVM_DEBUG(llvm::dbgs() << "unsupported sub-byte storage kind\n");
return nullptr;
@@ -348,6 +352,9 @@ convertVectorType(const spirv::TargetEnv &targetEnv,
}
Type elementType = convertSubByteIntegerType(options, intType);
+ if (!elementType)
+ return nullptr;
+
if (type.getRank() <= 1 && type.getNumElements() == 1)
return elementType;
diff --git a/mlir/test/Conversion/ArithToSPIRV/arith-to-spirv-unsupported.mlir b/mlir/test/Conversion/ArithToSPIRV/arith-to-spirv-unsupported.mlir
index 24a0bab352c345..9d7ab2be096ef7 100644
--- a/mlir/test/Conversion/ArithToSPIRV/arith-to-spirv-unsupported.mlir
+++ b/mlir/test/Conversion/ArithToSPIRV/arith-to-spirv-unsupported.mlir
@@ -60,6 +60,14 @@ func.func @int_vector4_invalid(%arg0: vector<2xi16>) {
return
}
+// -----
+
+func.func @int_vector_invalid_bitwidth(%arg0: vector<2xi12>) {
+ // expected-error @+1 {{failed to legalize operation 'arith.addi'}}
+ %0 = arith.addi %arg0, %arg0: vector<2xi12>
+ return
+}
+
///===----------------------------------------------------------------------===//
// Constant ops
//===----------------------------------------------------------------------===//
|
| if (!elementType) | ||
| return nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bug is that previously, it was assumed that if we entered this code path, the integer type was unsupported because of being sub-byte, but it might be unsupported for some other reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bug was essentially that it assumed that convertSubByteIntegerType would always succeed, but this is not the case even prior to my change related to subbyte types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. If you want to, you could put this in the pull-request description so it ends up in the commit message, but that may be unnecessary.
Fixes: #118612