[Mlir-commits] [mlir] [MLIR][Spirv] Don't lower tensors that can't be represented by an ArrayType (PR #171002)
Stefan Weigl-Bosker
llvmlistbot at llvm.org
Sun Dec 7 09:49:42 PST 2025
https://github.com/sweiglbosker updated https://github.com/llvm/llvm-project/pull/171002
>From 2cdfa7df8bb4b6590b21ee0acfc021065b75a174 Mon Sep 17 00:00:00 2001
From: Stefan Weigl-Bosker <stefan at s00.xyz>
Date: Sat, 6 Dec 2025 18:14:51 -0500
Subject: [PATCH 1/2] [MLIR] Don't lower tensors that can't be represented by
an ArrayType
---
mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
index cb9b7f6ec2fd2..f07307fcd2f9d 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
@@ -502,6 +502,11 @@ static Type convertTensorType(const spirv::TargetEnv &targetEnv,
<< type << " illegal: cannot handle zero-element tensors\n");
return nullptr;
}
+ if (arrayElemCount > std::numeric_limits<unsigned>::max()) {
+ LLVM_DEBUG(llvm::dbgs()
+ << type << " illegal: cannot fit tensor into target type\n");
+ return nullptr;
+ }
Type arrayElemType = convertScalarType(targetEnv, options, scalarType);
if (!arrayElemType)
>From 39e3fc30ab641d3babafa273fe8a20ceeb39dea3 Mon Sep 17 00:00:00 2001
From: Stefan Weigl-Bosker <stefan at s00.xyz>
Date: Sun, 7 Dec 2025 12:49:18 -0500
Subject: [PATCH 2/2] Add test
---
.../test/Conversion/TensorToSPIRV/tensor-ops-to-spirv.mlir | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/mlir/test/Conversion/TensorToSPIRV/tensor-ops-to-spirv.mlir b/mlir/test/Conversion/TensorToSPIRV/tensor-ops-to-spirv.mlir
index b69c2d0408d17..c30ee2fa38c34 100644
--- a/mlir/test/Conversion/TensorToSPIRV/tensor-ops-to-spirv.mlir
+++ b/mlir/test/Conversion/TensorToSPIRV/tensor-ops-to-spirv.mlir
@@ -79,3 +79,10 @@ func.func @tensor_2d_empty() -> () {
%x = arith.constant dense<> : tensor<2x0xi32>
return
}
+
+// CHECK-LABEL: func @very_large_tensor
+// CHECK-NEXT: arith.constant dense<1>
+func.func @very_large_tensor() -> () {
+ %x = arith.constant dense<1> : tensor<4294967296xi32>
+ return
+}
More information about the Mlir-commits
mailing list