From 1968efb794096094db23a49fcfd8c7065332568f Mon Sep 17 00:00:00 2001 From: Jakub Kuderski Date: Wed, 4 Dec 2024 11:11:51 -0500 Subject: [PATCH 1/3] [mlir][spir] Handle vectors of integers of unsupported width Fixes: https://github.com/llvm/llvm-project/issues/118612 --- mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp | 7 +++++++ .../ArithToSPIRV/arith-to-spirv-unsupported.mlir | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp index f5700059f68ee..d8b67bb4389ea 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 24a0bab352c34..9d7ab2be096ef 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 //===----------------------------------------------------------------------===// From 1ee3f31f27481445c88cab87893bbdaf492512b1 Mon Sep 17 00:00:00 2001 From: Jakub Kuderski Date: Wed, 4 Dec 2024 11:28:07 -0500 Subject: [PATCH 2/3] Clarify --- mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp index d8b67bb4389ea..93449e850ef98 100644 --- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp +++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp @@ -292,6 +292,7 @@ convertScalarType(const spirv::TargetEnv &targetEnv, } /// Converts a sub-byte integer `type` to i32 regardless of target environment. +/// Returns a nullptr for unsupported integer types, including sup-byte types. /// /// Note that we don't recognize sub-byte types in `spirv::ScalarType` and use /// the above given that these sub-byte types are not supported at all in From ce2e778876d7991abcee6c0aef11d73867ce8c62 Mon Sep 17 00:00:00 2001 From: Jakub Kuderski Date: Wed, 4 Dec 2024 11:37:29 -0500 Subject: [PATCH 3/3] Typo --- mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp index 93449e850ef98..877ac87fb0fe5 100644 --- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp +++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp @@ -292,7 +292,8 @@ convertScalarType(const spirv::TargetEnv &targetEnv, } /// Converts a sub-byte integer `type` to i32 regardless of target environment. -/// Returns a nullptr for unsupported integer types, including sup-byte types. +/// Returns a nullptr for unsupported integer types, including non sub-byte +/// types. /// /// Note that we don't recognize sub-byte types in `spirv::ScalarType` and use /// the above given that these sub-byte types are not supported at all in