[Mlir-commits] [mlir] [mlir][arith][transforms] Adds Truncf f32 to f4e2m1 (PR #144157)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jun 17 08:26:26 PDT 2025


================
@@ -0,0 +1,58 @@
+// Check various edge cases for truncf/extf ops involving f32 and f4e2m1 types.
+
+// RUN: mlir-opt %s --convert-vector-to-llvm \
+// RUN:             --convert-func-to-llvm \
+// RUN:             --arith-expand="include-f4e2m1=true" \
+// RUN:             --convert-arith-to-llvm | \
+// RUN: mlir-runner -e entry --entry-point-result=void \
+// RUN:             --shared-libs=%mlir_c_runner_utils | \
+// RUN: FileCheck %s --match-full-lines
+
+func.func @check_extf(%in : f32) -> () {
+  %trunc = arith.truncf %in : f32 to f4E2M1FN
+  %res = arith.extf %trunc : f4E2M1FN to f32
----------------
Muzammiluddin-Syed-ECE wrote:

After I added something like this to pass the f4 as input I produce these strange `unrealized_cast`s which are causing failures.

input
```
%zeroi8 = arith.constant 0 : i8
%zeroi4 = arith.trunci %zeroi8 : i8 to i4
%zeroF4 = arith.bitcast %zeroi4 : i4 to f4E2M1FN
func.call @check_extf(%zeroF4) : (f4E2M1FN) -> ()
```
output
```
%0 = llvm.mlir.constant(0.000000e+00 : f4E2M1FN) : i4
%1 = builtin.unrealized_conversion_cast %0 : i4 to f4E2M1FN
%2 = builtin.unrealized_conversion_cast %1 : f4E2M1FN to i4
```

not sure what to do here? Is there some implementation missing for a bitcast from i4 to f4E2M1FN

https://github.com/llvm/llvm-project/pull/144157


More information about the Mlir-commits mailing list