[Mlir-commits] [mlir] [MLIR][Math] add canonicalize-f32-promotion pass (PR #92482)

Mehdi Amini llvmlistbot at llvm.org
Fri May 17 08:07:08 PDT 2024


================
@@ -36,4 +36,51 @@ def MathLegalizeToF32 : Pass<"math-legalize-to-f32"> {
   let dependentDialects = ["math::MathDialect", "arith::ArithDialect"];
 }
 
+def MathCanonicalizeF32Promotion : Pass<"math-canonicalize-f32-promotion"> {
+  let summary = "Eliminate redundant truncf/extf pairs";
+  let description = [{
+    `legalize-to-f32` pass does f32 promotion for every op belonging to the
+    illegal op list. Once there are some consecutive illegal ops, `legalize-to-f32`
+    will insert redundant `arith.truncf` and `arith.extf` pairs between the illegal
+    ops.
+    
+    This pass is to eliminate the redundant truncf/extf pairs to improve
+    performance.
+
+    However, this pass may introduce numerical difference as the `f32->bf16` rounding
----------------
joker-eph wrote:

> I don't think they're valid under fastmath.

Can you elaborate? I don't follow. 
Assuming you meant to send a link to https://github.com/llvm/llvm-project/pull/88486#discussion_r1586918033 instead, there you wrote:

> This rewrite has caused per-element result errors around 1e-2 (if I remember right 16.25 vs 16.3125 or the like)

But numerical differences is actually in scope for fast-math...

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


More information about the Mlir-commits mailing list