[Mlir-commits] [mlir] [mlir] [arith] Fold trunc(extremum(ext(lhs), ext(rhs))) (PR #214658)
Renato Golin
llvmlistbot at llvm.org
Fri Aug 7 02:34:42 PDT 2026
rengolin wrote:
> A "codegen prepare" phase (in the LLVM backend terminology) is usually inserted to undo canonicalization for a particular backend (or better: the backend lowering / instruction selection is extended to handle the canonical form and insert the suitable expansion as needed).
It's not just code-gen, it's also intermediate pattern matchers that will need to keep converting back and forth for particular targets and not others throughout the pipeline.
One example we're handling now is: `matmul(bf16, bf16) : bf16`. Most hardware architectures accumulate that in `fp32`, so the actual operation is `matmul(bf16, bf16) : fp32 -> trunc()`, with `extf` inside the matmul generic body. You _could_ argue that reverting back to the plain version is a canonicalization, but then you lose the ability to propagate the `trunc` after other element-wise operations that may come after. In the integer cases it gets more complicated, with `i32` or `f32` accumulation, and then some operations can be fused, other cannot.
Destroying intermediate type information is not helpful, even though it can be _argued_ it's a canonicalization. If the upstream discussions on canonicalization has thought us anything is that there's clear disagreement across the community on what a canonicalization is or when they're helpful.
https://github.com/llvm/llvm-project/pull/214658
More information about the Mlir-commits
mailing list