[Mlir-commits] [mlir] db98e98 - [mlir][ArithToSPIRV] Fix crash on tensor arith.uitofp/sitofp lowering (#227102)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Oct 5 05:52:27 PDT 2026
Author: Vinicius Silva
Date: 2026-10-05T12:52:19Z
New Revision: db98e980edc62055667241aeb20f3ab4c6bfee4b
URL: https://github.com/llvm/llvm-project/commit/db98e980edc62055667241aeb20f3ab4c6bfee4b
DIFF: https://github.com/llvm/llvm-project/commit/db98e980edc62055667241aeb20f3ab4c6bfee4b.diff
LOG: [mlir][ArithToSPIRV] Fix crash on tensor arith.uitofp/sitofp lowering (#227102)
This PR adds type validation before calling getIntOrFloatBitWidth() in
uitofp/sitofp conversion, avoiding assertion failures on unsupported
types.
Closes #226380
Added:
mlir/test/Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir
Modified:
mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
index 40c0ac7064fdb..d73208323c414 100644
--- a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
+++ b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
@@ -731,8 +731,14 @@ struct IntToFPPattern final : public OpConversionPattern<ArithOp> {
// Check if the source integer type was widened during type conversion.
unsigned originalBitwidth =
getElementTypeOrSelf(op.getIn().getType()).getIntOrFloatBitWidth();
- unsigned convertedBitwidth =
- getElementTypeOrSelf(srcType).getIntOrFloatBitWidth();
+
+ Type srcElemType = getElementTypeOrSelf(srcType);
+ if (!srcElemType.isIntOrFloat()) {
+ return rewriter.notifyMatchFailure(op,
+ "unsupported type for uitofp/sitofp");
+ }
+
+ unsigned convertedBitwidth = srcElemType.getIntOrFloatBitWidth();
if (originalBitwidth >= convertedBitwidth) {
rewriter.replaceOpWithNewOp<SPIRVOp>(op, dstType, adaptor.getOperands());
diff --git a/mlir/test/Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir b/mlir/test/Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir
new file mode 100644
index 0000000000000..76f564b62b563
--- /dev/null
+++ b/mlir/test/Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir
@@ -0,0 +1,40 @@
+// RUN: mlir-opt --split-input-file --convert-arith-to-spirv --verify-diagnostics %s
+
+// -----
+
+// Regression test: arith.uitofp on tensor types should not crash
+// (https://github.com/llvm/llvm-project/issues/226380).
+func.func @uitofp_tensor_no_crash(%arg0: tensor<1xi32>) -> tensor<1xf32> {
+ // expected-error @+1 {{failed to legalize operation 'arith.uitofp'}}
+ %0 = arith.uitofp %arg0 : tensor<1xi32> to tensor<1xf32>
+ return %0 : tensor<1xf32>
+}
+
+// -----
+
+// Regression test: arith.sitofp on tensor types should not crash
+// (https://github.com/llvm/llvm-project/issues/226380).
+func.func @sitofp_tensor_no_crash(%arg0: tensor<1xi32>) -> tensor<1xf32> {
+ // expected-error @+1 {{failed to legalize operation 'arith.sitofp'}}
+ %0 = arith.sitofp %arg0 : tensor<1xi32> to tensor<1xf32>
+ return %0 : tensor<1xf32>
+}
+
+// -----
+
+// Dynamically shaped tensors must not crash uitofp lowering.
+func.func @uitofp_dynamic_tensor_no_crash(%arg0: tensor<?xi16>) -> tensor<?xf32> {
+ // expected-error @+1 {{failed to legalize operation 'arith.uitofp'}}
+ %0 = arith.uitofp %arg0 : tensor<?xi16> to tensor<?xf32>
+ return %0 : tensor<?xf32>
+}
+
+// -----
+
+// Multi-dimensional tensors must not crash sitofp lowering.
+func.func @sitofp_multidim_tensor_no_crash(%arg0: tensor<2x2xi16>) -> tensor<2x2xf32> {
+ // expected-error @+1 {{failed to legalize operation 'arith.sitofp'}}
+ %0 = arith.sitofp %arg0 : tensor<2x2xi16> to tensor<2x2xf32>
+ return %0 : tensor<2x2xf32>
+}
+
More information about the Mlir-commits
mailing list