[all-commits] [llvm/llvm-project] dccdac: [mlir][arith] Canonicalize `addf(negf(x), y)` to `...

Victor Perez via All-commits all-commits at lists.llvm.org
Wed Jul 15 10:24:40 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: dccdacc2dc49c708a8fde04b04ae76b552aaf122
      https://github.com/llvm/llvm-project/commit/dccdacc2dc49c708a8fde04b04ae76b552aaf122
  Author: Victor Perez <victor.pc.upm at gmail.com>
  Date:   2026-07-15 (Wed, 15 Jul 2026)

  Changed paths:
    M mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
    M mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td
    M mlir/lib/Dialect/Arith/IR/ArithOps.cpp
    M mlir/test/Dialect/Arith/canonicalize.mlir

  Log Message:
  -----------
  [mlir][arith] Canonicalize `addf(negf(x), y)` to `subf(y, x)` (#209277)

`arith.addf` had no canonicalization patterns at all. This adds a
canonicalizer rewriting `addf(negf(x), y) -> subf(y, x)` (and the
commuted operand order).

The rewrite is valid under any rounding mode, which is propagated to the
`subf`: `negf` is an exact sign flip, IEEE addition is commutative, and
`y - x` is the correctly rounded `y + (-x)`, so `subf(y, x)` and
`addf(negf(x), y)` are bit-identical for every rounding mode. Fast-math
flags are propagated to the new `subf`.

----

Code partially generated with Claude Code.

Signed-off-by: Víctor Pérez Carrasco <victorperez at fb.com>
Co-authored-by: Víctor Pérez Carrasco <victorperez at fb.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list