<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/143335>143335</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] Inconsistent output when executing MLIR program with and without `-test-math-polynomial-approximation="enable-avx2"`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Lambor24
</td>
</tr>
</table>
<pre>
My git version is [90beda2](https://github.com/llvm/llvm-project/commit/90beda2aba3cac34052827c560449fcb184c7313).
## Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without the `-test-math-polynomial-approximation="enable-avx2"`.
## Steps to Reproduce:
### 1. **MLIR Program (test.mlir)**:
test.mlir:
```
module attributes {llvm.data_layout = ""} {
func.func private @printMemrefI64(tensor<*xi64>)
func.func private @printMemrefF32(tensor<*xf32>)
func.func @main() {
%0 = "tosa.const"() <{values = dense<0.000000e+00> : tensor<1xf32>}> : () -> tensor<1xf32>
%1 = "tosa.const"() <{values = dense<-1.023950e+03> : tensor<1x1x6x3xf32>}> : () -> tensor<1x1x6x3xf32>
%2 = "tosa.const"() <{values = dense<3.671420e+03> : tensor<4x4x3x1xf32>}> : () -> tensor<4x4x3x1xf32>
%3 = "tosa.const"() <{values = dense<4.235330e+03> : tensor<3xf32>}> : () -> tensor<3xf32>
%4 = tosa.depthwise_conv2d %1, %2, %3, %0, %0 {acc_type = f32, dilation = array<i64: 1, 2>, pad = array<i64: 1, 2, 2, 2>, stride = array<i64: 2, 1>} : (tensor<1x1x6x3xf32>, tensor<4x4x3x1xf32>, tensor<3xf32>, tensor<1xf32>, tensor<1xf32>) -> tensor<1x1x4x3xf32>
%5 = tosa.cos %4 : (tensor<1x1x4x3xf32>) -> tensor<1x1x4x3xf32>
%cast = tensor.cast %5 : tensor<1x1x4x3xf32> to tensor<*xf32>
call @printMemrefF32(%cast) : (tensor<*xf32>) -> ()
return
}
}
```
### 2. **Command to Run Without `-test-math-polynomial-approximation="enable-avx2"`:**
```
/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops -test-lower-to-llvm | \
/path/llvm-project/build/bin/mlir-runner -e main -entry-point-result=void \
-shared-libs=/path/llvm-project/build/lib/libmlir_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_c_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_async_runtime.so
```
### 3. **Output Without `-test-math-polynomial-approximation="enable-avx2"`:**
```
[[[[-0.290655, -0.290655, -0.290655],
[-0.290655, -0.290655, -0.290655],
[-0.290655, -0.290655, -0.290655],
[-0.290655, -0.290655, -0.290655]]]]
```
### 4. **Command to Run With `-test-math-polynomial-approximation="enable-avx2"`:**
```
/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops -test-math-polynomial-approximation="enable-avx2" -test-lower-to-llvm | \
/path/llvm-project/build/bin/mlir-runner -e main -entry-point-result=void \
-shared-libs=/path/llvm-project/build/lib/libmlir_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_c_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_async_runtime.so
```
### 5. **Output With `-test-math-polynomial-approximation="enable-avx2"`:**
```
[[[[-0.841471, -0.841471, -0.841471],
[-0.841471, -0.841471, -0.841471],
[-0.841471, -0.841471, -0.841471],
[-0.841471, -0.841471, -0.841471]]]]
```
I'm not sure if there is any bug in my program or if the wrong usage of the above passes caused this result.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWFFvozgQ_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