[Mlir-commits] [mlir] [mlir][spir] Handle vectors of integers of unsupported width (PR #118663)

Jakub Kuderski llvmlistbot at llvm.org
Wed Dec 4 08:18:26 PST 2024


https://github.com/kuhar created https://github.com/llvm/llvm-project/pull/118663

Fixes: https://github.com/llvm/llvm-project/issues/118612

>From 1968efb794096094db23a49fcfd8c7065332568f Mon Sep 17 00:00:00 2001
From: Jakub Kuderski <jakub at nod-labs.com>
Date: Wed, 4 Dec 2024 11:11:51 -0500
Subject: [PATCH] [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 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
 //===----------------------------------------------------------------------===//



More information about the Mlir-commits mailing list