[Mlir-commits] [mlir] [mlir][ArithToSPIRV] Fix crash on tensor arith.uitofp/sitofp lowering (PR #227102)
Vinicius Silva
llvmlistbot at llvm.org
Fri Oct 2 06:14:44 PDT 2026
https://github.com/viniciusfdasilva updated https://github.com/llvm/llvm-project/pull/227102
>From 15d22fdf20bb62ed900a429804f9b5ed9781d126 Mon Sep 17 00:00:00 2001
From: Vinicius Silva <viniciusilva at ieee.org>
Date: Mon, 28 Sep 2026 20:11:41 +0000
Subject: [PATCH 1/7] [mlir][ArithToSPIRV] Fix crash on tensor
arith.uitofp/sitofp lowering (#226380)
---
mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
index 40c0ac7064fdb5..8d44c343f73e25 100644
--- a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
+++ b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
@@ -731,6 +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();
+
+ if (!srcType ||
+ !(isa<IntegerType, FloatType>(getElementTypeOrSelf(srcType)) ||
+ isa<mlir::VectorType>(srcType))) {
+ return rewriter.notifyMatchFailure(op,
+ "unsupported type for uitofp/sitofp");
+ }
+
unsigned convertedBitwidth =
getElementTypeOrSelf(srcType).getIntOrFloatBitWidth();
>From 3f29207643950b5864d39656093e03b7fec0fd73 Mon Sep 17 00:00:00 2001
From: Vinicius Silva <viniciusilva at ieee.org>
Date: Tue, 29 Sep 2026 08:59:42 -0300
Subject: [PATCH 2/7] Update mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
Co-authored-by: Igor Wodiany <dev at wodiany.com>
---
mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
index 8d44c343f73e25..90a6860da2e363 100644
--- a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
+++ b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
@@ -734,7 +734,7 @@ struct IntToFPPattern final : public OpConversionPattern<ArithOp> {
if (!srcType ||
!(isa<IntegerType, FloatType>(getElementTypeOrSelf(srcType)) ||
- isa<mlir::VectorType>(srcType))) {
+ isa<VectorType>(srcType))) {
return rewriter.notifyMatchFailure(op,
"unsupported type for uitofp/sitofp");
}
>From bea37ec0e1ed2368a97a2cba3588b60a70caff8d Mon Sep 17 00:00:00 2001
From: Vinicius Silva <viniciusilva at ieee.org>
Date: Tue, 29 Sep 2026 10:16:18 -0300
Subject: [PATCH 3/7] Adding regression tests
---
.../arith_itofp_tensor_regression.mlir | 40 +++++++++++++++++++
1 file changed, 40 insertions(+)
create mode 100644 mlir/test/Conversion/ArithToSPIRV/arith_itofp_tensor_regression.mlir
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 00000000000000..6d15360c01d237
--- /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>
+}
+
>From ace769283121e41c13098c44bfd6af853384333b Mon Sep 17 00:00:00 2001
From: Vinicius Silva <viniciusilva at ieee.org>
Date: Thu, 1 Oct 2026 22:11:19 -0300
Subject: [PATCH 4/7] [mlir][ArithToSPIRV] Check element type in IntToFPPattern
and rename test
---
mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp | 5 ++---
...or_regression.mlir => arith-itofp-tensor-regression.mlir} | 0
2 files changed, 2 insertions(+), 3 deletions(-)
rename mlir/test/Conversion/ArithToSPIRV/{arith_itofp_tensor_regression.mlir => arith-itofp-tensor-regression.mlir} (100%)
diff --git a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
index 90a6860da2e363..4f9d0075c027d2 100644
--- a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
+++ b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
@@ -732,9 +732,8 @@ struct IntToFPPattern final : public OpConversionPattern<ArithOp> {
unsigned originalBitwidth =
getElementTypeOrSelf(op.getIn().getType()).getIntOrFloatBitWidth();
- if (!srcType ||
- !(isa<IntegerType, FloatType>(getElementTypeOrSelf(srcType)) ||
- isa<VectorType>(srcType))) {
+ Type srcElemType = getElementTypeOrSelf(srcType);
+ if (!srcElemType.isIntOrFloat()) {
return rewriter.notifyMatchFailure(op,
"unsupported type for uitofp/sitofp");
}
diff --git a/mlir/test/Conversion/ArithToSPIRV/arith_itofp_tensor_regression.mlir b/mlir/test/Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir
similarity index 100%
rename from mlir/test/Conversion/ArithToSPIRV/arith_itofp_tensor_regression.mlir
rename to mlir/test/Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir
>From ea4b5888281893e601b0008f2f92363f59272676 Mon Sep 17 00:00:00 2001
From: Vinicius Silva <viniciusilva at ieee.org>
Date: Fri, 2 Oct 2026 10:12:53 -0300
Subject: [PATCH 5/7] Update
mlir/test/Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir
Co-authored-by: Igor Wodiany <dev at wodiany.com>
---
.../Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/test/Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir b/mlir/test/Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir
index 6d15360c01d237..76f564b62b563b 100644
--- a/mlir/test/Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir
+++ b/mlir/test/Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -split-input-file -convert-arith-to-spirv -verify-diagnostics %s
+// RUN: mlir-opt --split-input-file --convert-arith-to-spirv --verify-diagnostics %s
// -----
>From 6300cf4a23ad1c457c040d023533263e44a1df49 Mon Sep 17 00:00:00 2001
From: Vinicius Silva <viniciusilva at ieee.org>
Date: Fri, 2 Oct 2026 10:13:20 -0300
Subject: [PATCH 6/7] Update
mlir/test/Conversion/ArithToSPIRV/arith-itofp-tensor-regression.mlir
Co-authored-by: Igor Wodiany <dev at wodiany.com>
>From 1d47d797ea6f36319eaa4acbc7ce17c84ce4c11e Mon Sep 17 00:00:00 2001
From: Vinicius Silva <viniciusilva at ieee.org>
Date: Fri, 2 Oct 2026 10:14:24 -0300
Subject: [PATCH 7/7] Update mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
Co-authored-by: Igor Wodiany <dev at wodiany.com>
---
mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
index 4f9d0075c027d2..ab159eb6fa6628 100644
--- a/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
+++ b/mlir/lib/Conversion/ArithToSPIRV/ArithToSPIRV.cpp
@@ -739,7 +739,7 @@ struct IntToFPPattern final : public OpConversionPattern<ArithOp> {
}
unsigned convertedBitwidth =
- getElementTypeOrSelf(srcType).getIntOrFloatBitWidth();
+ srcElemType .getIntOrFloatBitWidth();
if (originalBitwidth >= convertedBitwidth) {
rewriter.replaceOpWithNewOp<SPIRVOp>(op, dstType, adaptor.getOperands());
More information about the Mlir-commits
mailing list