[Mlir-commits] [mlir] [mlir][ArithToLLVM] Do not lower sitofp to unsupported float types (PR #230975)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Oct 11 07:44:57 PDT 2026


https://github.com/SomnusGG created https://github.com/llvm/llvm-project/pull/230975

The LLVM type converter maps float types with no LLVM equivalent (for example
f8E4M3FN, f8E5M2 and f8E8M0FNU) to an integer of the same width. Unlike
`UIToFPOpLowering`, `FPToSIOpLowering` and `FPToUIOpLowering`,
`SIToFPOpLowering` did not set `FailOnUnsupportedFP`. As a result, it
produced an invalid op that the verifier rejects:

  'llvm.sitofp' op result #0 must be floating point LLVM type or LLVM
  dialect-compatible vector of floating point LLVM type, but got 'i8'

Reproducer (`mlir-opt --convert-arith-to-llvm`, or `--convert-to-llvm`):

  %0 = arith.sitofp %arg0 : i32 to f8E4M3FN

Set `FailOnUnsupportedFP` so that the op stays unconverted, as the other
int/float conversions already do. Users can emulate the op first with
`arith-emulate-unsupported-floats`.



🤖 Generated with [Claude Code](https://claude.com/claude-code)

>From e5dad09000e2c47c4ac7315c839aefbae359c12b Mon Sep 17 00:00:00 2001
From: SomnusGG <a69254758 at gmail.com>
Date: Sun, 11 Oct 2026 22:14:48 +0800
Subject: [PATCH] [mlir][ArithToLLVM] Do not lower sitofp to unsupported float
 types

The LLVM type converter maps float types with no LLVM equivalent (for example
f8E4M3FN, f8E5M2 and f8E8M0FNU) to an integer of the same width. Unlike
`UIToFPOpLowering`, `FPToSIOpLowering` and `FPToUIOpLowering`,
`SIToFPOpLowering` did not set `FailOnUnsupportedFP`. As a result, it
produced an invalid op that the verifier rejects:

  'llvm.sitofp' op result #0 must be floating point LLVM type or LLVM
  dialect-compatible vector of floating point LLVM type, but got 'i8'

Reproducer (`mlir-opt --convert-arith-to-llvm`, or `--convert-to-llvm`):

  %0 = arith.sitofp %arg0 : i32 to f8E4M3FN

Set `FailOnUnsupportedFP` so that the op stays unconverted, as the other
int/float conversions already do. Users can emulate the op first with
`arith-emulate-unsupported-floats`.

Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
---
 .../Conversion/ArithToLLVM/ArithToLLVM.cpp    |  4 +++-
 .../Conversion/ArithToLLVM/arith-to-llvm.mlir | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
index bac19144d6ea7..e61374cfcfda9 100644
--- a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
+++ b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
@@ -198,7 +198,9 @@ using ShRSIOpLowering =
 using ShRUIOpLowering =
     VectorConvertToLLVMPattern<arith::ShRUIOp, LLVM::LShrOp>;
 using SIToFPOpLowering =
-    VectorConvertToLLVMPattern<arith::SIToFPOp, LLVM::SIToFPOp>;
+    VectorConvertToLLVMPattern<arith::SIToFPOp, LLVM::SIToFPOp,
+                               AttrConvertPassThrough,
+                               /*FailOnUnsupportedFP=*/true>;
 using SubFOpLowering =
     ConstrainedVectorConvertToLLVMPattern<arith::SubFOp, LLVM::FSubOp,
                                           /*HasRoundingMode=*/false,
diff --git a/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir b/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
index 372561d9653c8..aea4be2195274 100644
--- a/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
+++ b/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
@@ -1008,6 +1008,25 @@ func.func @unsupported_fp_type(%arg0: f4E2M1FN, %arg1: vector<4xf4E2M1FN>, %arg2
 
 // -----
 
+// Integer to float conversions with a result type that has no LLVM equivalent
+// are not converted. sitofp used to be lowered to an invalid `llvm.sitofp` with
+// an integer result.
+
+// CHECK-LABEL: func @unsupported_fp_type_int_to_fp
+//       CHECK:   arith.sitofp {{.*}} : i32 to f8E4M3FN
+//       CHECK:   arith.sitofp {{.*}} : vector<4xi32> to vector<4xf8E5M2>
+//       CHECK:   arith.sitofp {{.*}} : vector<2x4xi32> to vector<2x4xf8E8M0FNU>
+//       CHECK:   arith.uitofp {{.*}} : i32 to f8E4M3FN
+func.func @unsupported_fp_type_int_to_fp(%arg0: i32, %arg1: vector<4xi32>, %arg2: vector<2x4xi32>) -> (f8E4M3FN, vector<4xf8E5M2>, vector<2x4xf8E8M0FNU>, f8E4M3FN) {
+  %0 = arith.sitofp %arg0 : i32 to f8E4M3FN
+  %1 = arith.sitofp %arg1 : vector<4xi32> to vector<4xf8E5M2>
+  %2 = arith.sitofp %arg2 : vector<2x4xi32> to vector<2x4xf8E8M0FNU>
+  %3 = arith.uitofp %arg0 : i32 to f8E4M3FN
+  return %0, %1, %2, %3 : f8E4M3FN, vector<4xf8E5M2>, vector<2x4xf8E8M0FNU>, f8E4M3FN
+}
+
+// -----
+
 // CHECK-LABEL: func @supported_fp_type
 //       CHECK:   llvm.fadd {{.*}} : f32
 //       CHECK:   llvm.fadd {{.*}} : vector<4xf32>



More information about the Mlir-commits mailing list