[Mlir-commits] [mlir] [mlir] [arith] Fold trunc(extremum(ext(lhs), ext(rhs))) (PR #214658)
Chuanqi Xu
llvmlistbot at llvm.org
Tue Aug 11 02:29:53 PDT 2026
ChuanqiXu9 wrote:
> I don't think this rewrite is sound in the current form, repro with counterexamples: https://gist.github.com/kuhar/0b26ec9569195ea1d18bf0da62e27734
Thanks for pointing this out. Learned a lot. After spending the whole morning for this, I realized that if we want make this sound, we have to add `fastmath<nnan>` to the original example to make it work:
```
func.func @narrowExtremaOfExtf(%arg0: f16, %arg1: f16)
-> f16 {
%lhs = arith.extf %arg0 : f16 to f32
%rhs = arith.extf %arg1 : f16 to f32
%maximum = arith.maximumf %lhs, %rhs fastmath<nnan> : f32
%maximumTrunc = arith.truncf %maximum : f32 to f16
return %maximumTrunc : f16
}
```
this makes it less useful but still useful if the end users use fastmath mode. And it can be even better if we can introduce a new mode to allow qNaN but not sNaN.
https://github.com/llvm/llvm-project/pull/214658
More information about the Mlir-commits
mailing list