19 Commits

Author SHA1 Message Date
Yi Zhang
188bf2769a
Fix variable only used by assert in #172716. (#172788) 2025-12-17 23:47:05 -05:00
Maksim Levental
54eee1e947
Reapply "[mlir][math] Add FP software implementation lowering pass: math-to-apfloat" (#172714) (#172716)
Reapply https://github.com/llvm/llvm-project/pull/171221 - Fix builder
by linking `MLIRTransformUtils`. Also move headers to
`mlir/Conversion/ArithAndMathToAPFloat`.
2025-12-17 17:26:37 -08:00
Maksim Levental
621fe03eaa
Revert "[mlir][math] Add FP software implementation lowering pass: math-to-apfloat" (#172714)
Reverts llvm/llvm-project#171221

Broken builder https://lab.llvm.org/buildbot/#/builders/138/builds/23270
2025-12-17 10:52:43 -08:00
Maksim Levental
7f1a30ebd2
[mlir][math] Add FP software implementation lowering pass: math-to-apfloat (#171221)
Add APFloat software implementation for `math.fma`, `math.abs`,
`math.isnan`, `math.isfinite`, `math.isinf`, `math.isnormal` for reduced
precision (`fp4*`, `fp6*`, `fp8*`).
2025-12-17 18:37:13 +00:00
Matthias Springer
147c466bcd
[mlir][arith] Add support for min/max to ArithToAPFloat (#169760)
Add support for `arith.minnumf`, `arith.maxnumf`, `arith.minimumf`,
`arith.maximumf`.
2025-12-01 08:50:02 +00:00
Matthias Springer
05b1989551
[mlir][arith] Add support for negf to ArithToAPFloat (#169759)
Add support for `arith.negf`.
2025-12-01 08:28:23 +00:00
Matthias Springer
4d7abe5355
[mlir][arith] Add support for cmpf to ArithToAPFloat (#169753)
Add support for `arith.cmpf`.
2025-12-01 09:12:11 +01:00
Matthias Springer
6ec686735c
[mlir][arith] Add support for sitofp, uitofp to ArithToAPFloat (#169284)
Add support for `arith.sitofp` and `arith.uitofp`.
2025-11-25 11:31:23 +09:00
Matthias Springer
3db8ed0500
[mlir][arith] Add support for fptosi, fptoui to ArithToAPFloat (#169277)
Add support for `arith.fptosi` and `arith.fptoui`.
2025-11-25 10:50:20 +09:00
Matthias Springer
78994706d8
[mlir][arith] Add support for extf, truncf to ArithToAPFloat (#169275)
Add support for `arith.extf` and `arith.truncf`. No support for custom
rounding modes yet.
2025-11-25 10:09:26 +09:00
Matthias Springer
7a53d33e7c
[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#167848)
Reland pass and fix linker errors.

---------

Co-authored-by: Maksim Levental <maksim.levental@gmail.com>
2025-11-13 18:35:30 +09:00
Maksim Levental
140e07c862
Revert "Reland yet again: [mlir] Add FP software implementation lowering pass: arith-to-apfloat" (#167834)
Reverts llvm/llvm-project#167608

Broken builder https://lab.llvm.org/buildbot/#/builders/52/builds/12781
2025-11-12 23:02:21 -08:00
Maksim Levental
0bba1e7658
Reland yet again: [mlir] Add FP software implementation lowering pass: arith-to-apfloat (#167608)
Fix both symbol visibility issue in the mlir_apfloat_wrappers lib and the linkage issue in ArithToAPFloat.
2025-11-12 17:57:53 -08:00
Maksim Levental
e67ac07881
Revert "Reapply "Reapply "[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#166618)" (#167431)"" (#167549)
Reverts llvm/llvm-project#167436 to fix sanitizers
2025-11-11 09:29:09 -08:00
Maksim Levental
75751f33a8
Reapply "Reapply "[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#166618)" (#167431)" (#167436)
Reland https://github.com/llvm/llvm-project/pull/166618 by fixing
missing symbol issues by explicitly loading
`--shared-libs=%mlir_apfloat_wrappers` as well as
`--shared-libs=%mlir_c_runner_utils`.
2025-11-11 08:50:37 -08:00
Maksim Levental
93b3c1b7e1
Revert "Reapply "[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#166618)" (#167431)" (#167435)
This reverts commit 0e639ae6e030ade849fa7a09cb7dc40b42f25373.
2025-11-10 17:40:51 -08:00
Maksim Levental
0e639ae6e0
Reapply "[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#166618)" (#167431)
Reland https://github.com/llvm/llvm-project/pull/166618 with
MLIRFuncUtils linked in.
2025-11-10 17:13:29 -08:00
Maksim Levental
70d379fd7a
Revert "[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#166618)" (#167429)
This reverts commit 222f4e494a0cd9515c242fd083c2776772734385.
2025-11-10 16:54:44 -08:00
Maksim Levental
222f4e494a
[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#166618)
This commit adds a new pass that lowers floating-point `arith`
operations to calls into the execution engine runtime library. Currently
supported operations: `addf`, `subf`, `mulf`, `divf`, `remf`.

All floating-point types that have an APFloat semantics are supported.
This includes low-precision floating-point types such as `f4E2M1FN` that
cannot execute natively on CPUs.

This commit also improves the `vector.print` lowering pattern to call
into the runtime library for floating-point types that are not supported
by LLVM. This is necessary to write a meaningful integration test.

The way it works is 

```mlir
func.func @full_example() {
  %a = arith.constant 1.4 : f8E4M3FN
  %b = func.call @foo() : () -> (f8E4M3FN)
  %c = arith.addf %a, %b : f8E4M3FN
  vector.print %c : f8E4M3FN
  return
}
```

gets transformed to

```mlir
func.func private @__mlir_apfloat_add(i32, i64, i64) -> i6
func.func @full_example() {
  %cst = arith.constant 1.375000e+00 : f8E4M3FN
  %0 = call @foo() : () -> f8E4M3FN
  // bitcast operand A to integer of equal width
  %1 = arith.bitcast %cst : f8E4M3FN to i8
  // zext A to i64
  %2 = arith.extui %1 : i8 to i64
  // same for operand B
  %3 = arith.bitcast %0 : f8E4M3FN to i8
  %4 = arith.extui %3 : i8 to i64
  // get the llvm::fltSemantics(f8E4M3FN) as an enum
  %c10_i32 = arith.constant 10 : i32
  // call the impl against APFloat in mlir_apfloat_wrappers
  %5 = call @__mlir_apfloat_add(%c10_i32, %2, %4) : (i32, i64, i64) -> i64
  // "cast" back to the original fp type
  %6 = arith.trunci %5 : i64 to i8
  %7 = arith.bitcast %6 : i8 to f8E4M3FN
  vector.print %7 : f8E4M3FN
}
```

Note, `llvm::fltSemantics(f8E4M3FN)` is emitted by the pattern each time
an `arith` op is transformed, thereby making the call to
`__mlir_apfloat_add` correct (i.e., no name mangling on type necessary).


RFC:
https://discourse.llvm.org/t/rfc-software-implementation-for-unsupported-fp-types-in-convert-arith-to-llvm/88785

---------

Co-authored-by: Matthias Springer <me@m-sp.org>
2025-11-10 16:21:39 -08:00