[Mlir-commits] [mlir] dd0c192 - [mlir][ArithToLLVM] Do not lower sitofp to unsupported float types (#230975)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Oct 12 23:17:47 PDT 2026
Author: SomnusGG
Date: 2026-10-13T06:17:40Z
New Revision: dd0c1922f72680ce2850881719f2529e2d39a2aa
URL: https://github.com/llvm/llvm-project/commit/dd0c1922f72680ce2850881719f2529e2d39a2aa
DIFF: https://github.com/llvm/llvm-project/commit/dd0c1922f72680ce2850881719f2529e2d39a2aa.diff
LOG: [mlir][ArithToLLVM] Do not lower sitofp to unsupported float types (#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)
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
Added:
Modified:
mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
Removed:
################################################################################
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