[Mlir-commits] [mlir] [math] lower rsqrt to sqrt + fdiv (PR #91344)
Corentin Ferry
llvmlistbot at llvm.org
Wed May 8 01:19:58 PDT 2024
cferry-AMD wrote:
>
> I have actually not thought of that other way. Let me have a look... that's a good point!
Shallow testing on 1/sqrt(x) for integer values of x did not point out significant accuracy differences. However, the behavior with respect to `-0.0` looks different when hand-writing the two versions into `test-expand-math-approx.mlir`:
```mlir
%1 = arith.constant -0.0 : f32
%one = arith.constant 1.0 : f32
// CHECK: -nan
%2 = arith.divf %one, %1 : f32
%3 = math.sqrt %2 : f32
vector.print %3 : f32
// CHECK: -inf
%4 = math.sqrt %1 : f32
%5 = arith.divf %one, %4 : f32
vector.print %5 : f32
```
* div(1, sqrt(x)) will return -inf,
* sqrt(div(1, x)) will return -nan.
Given that MathToLLVM uses 1/sqrt(x), I'd go the same route to be consistent with it.
https://github.com/llvm/llvm-project/pull/91344
More information about the Mlir-commits
mailing list