| Issue |
174523
|
| Summary |
[MLIR]`math.tanh` lowering via SPIR-V produces NaN while LLVM lowering returns 1.0
|
| Labels |
mlir
|
| Assignees |
|
| Reporter |
BealZephyr
|
**test commit**: [5cfd02](https://github.com/llvm/llvm-project/commit/5cfd02f44a43a2e2a085a633b022a62f64ba2b93)
## Description:
I found the inconsistent results when lowering `math.tanh` through different conversion pipelines.
`tanh(52.45f)` should be very close to 1.0f. However, when lowering through `-convert-math-to-spirv -convert-spirv-to-llvm`, the result is -nan.
## test case
```
module {
memref.global "private" constant @__constant_2xf32 : memref<2xf32> = dense<5.245000e+01> {alignment = 64 : i64}
func.func private @printMemrefF32(memref<*xf32>)
func.func @main() {
%c1 = arith.constant 1 : index
%c2 = arith.constant 2 : index
%c0 = arith.constant 0 : index
%0 = memref.get_global @__constant_2xf32 : memref<2xf32>
%alloc = memref.alloc() {alignment = 64 : i64} : memref<2xf32>
scf.for %arg0 = %c0 to %c2 step %c1 {
%1 = memref.load %0[%arg0] : memref<2xf32>
%2 = math.tanh %1 : f32
memref.store %2, %alloc[%arg0] : memref<2xf32>
}
%cast = memref.cast %alloc : memref<2xf32> to memref<*xf32>
call @printMemrefF32(%cast) : (memref<*xf32>) -> ()
return
}
}
```
## Command:
### 1. Use `-convert-math-to-llvm`
#### cmd:
```
mlir-opt 1.mlir -convert-scf-to-cf -convert-openmp-to-llvm -convert-math-to-llvm | mlir-runner -e main -entry-point-result=void -shared-libs=/home/workdir/llvm-project-latest/build/lib/libmlir_runner_utils.so
```
#### output:
```
[1, 1]
```
### 2. Use `-convert-math-to-spirv -convert-spirv-to-llvm`:
#### cmd:
```
mlir-opt 1.mlir -convert-scf-to-cf -convert-openmp-to-llvm -convert-math-to-spirv -convert-spirv-to-llvm | mlir-runner -e main -entry-point-result=void -shared-libs=/home/workdir/llvm-project-latest/build/lib/libmlir_runner_utils.so
```
#### output:
```
[-nan, -nan]
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs