Skip to content

Commit 1968efb

Browse files
committed
[mlir][spir] Handle vectors of integers of unsupported width
Fixes: #118612
1 parent 3b904ae commit 1968efb

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ convertScalarType(const spirv::TargetEnv &targetEnv,
299299
/// supported integer types.
300300
static Type convertSubByteIntegerType(const SPIRVConversionOptions &options,
301301
IntegerType type) {
302+
if (type.getWidth() > 8) {
303+
LLVM_DEBUG(llvm::dbgs() << "not a subbyte type\n");
304+
return nullptr;
305+
}
302306
if (options.subByteTypeStorage != SPIRVSubByteTypeStorage::Packed) {
303307
LLVM_DEBUG(llvm::dbgs() << "unsupported sub-byte storage kind\n");
304308
return nullptr;
@@ -348,6 +352,9 @@ convertVectorType(const spirv::TargetEnv &targetEnv,
348352
}
349353

350354
Type elementType = convertSubByteIntegerType(options, intType);
355+
if (!elementType)
356+
return nullptr;
357+
351358
if (type.getRank() <= 1 && type.getNumElements() == 1)
352359
return elementType;
353360

mlir/test/Conversion/ArithToSPIRV/arith-to-spirv-unsupported.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ func.func @int_vector4_invalid(%arg0: vector<2xi16>) {
6060
return
6161
}
6262

63+
// -----
64+
65+
func.func @int_vector_invalid_bitwidth(%arg0: vector<2xi12>) {
66+
// expected-error @+1 {{failed to legalize operation 'arith.addi'}}
67+
%0 = arith.addi %arg0, %arg0: vector<2xi12>
68+
return
69+
}
70+
6371
///===----------------------------------------------------------------------===//
6472
// Constant ops
6573
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)