<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/118784>118784</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Inconsistent output when executing MLIR program with and without --test-math-polynomial-approximation
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Emilyaxe
      </td>
    </tr>
</table>

<pre>
    
git version: adf892d743d

system: `Ubuntu 18.04.6 LTS`

## Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without the `--test-math-polynomial-approximation`. I am not sure whether the semantic of `--test-math-polynomial-approximation` should affect the results.

## Steps to Reproduce:


### 1. **MLIR Program (a.mlir)**:
a.mlir: 
``` 
module {
  func.func private @printMemrefI32(tensor<*xi32>)
  func.func private @printMemrefF32(tensor<*xf32>)
  func.func @main() {
    %0 = "tosa.const"() <{value = dense<[0, 2, 1]> : tensor<3xi32>}> : () -> tensor<3xi32>
    %1 = "tosa.const"() <{value = dense<4068> : tensor<1x4x3xi32>}> : () -> tensor<1x4x3xi32>
    %2 = "tosa.const"() <{value = dense<-1976> : tensor<1x4x3xi32>}> : () -> tensor<1x4x3xi32>
 %3 = tosa.maximum %2, %1 : (tensor<1x4x3xi32>, tensor<1x4x3xi32>) -> tensor<1x4x3xi32>
    %4 = tosa.transpose %3, %0 : (tensor<1x4x3xi32>, tensor<3xi32>) -> tensor<1x3x4xi32>
    %5 = tosa.matmul %2, %4 : (tensor<1x4x3xi32>, tensor<1x3x4xi32>) -> tensor<1x4x4xi32>
    %6 = tosa.cast %5 : (tensor<1x4x4xi32>) -> tensor<1x4x4xf32>
    %7 = tosa.floor %6 : (tensor<1x4x4xf32>) -> tensor<1x4x4xf32>
    %8 = tosa.sin %7 : (tensor<1x4x4xf32>) -> tensor<1x4x4xf32>
    %cast = tensor.cast %8 : tensor<1x4x4xf32> to tensor<*xf32>
    call @printMemrefF32(%cast) : (tensor<*xf32>) -> ()
    return
  }
}

``` 

 ### 2. **Command to Run Without `--test-math-polynomial-approximation`:**:

``` 
 /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt /data/szy/workspace/mlir-inconsistent/tosa.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))" |  /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops  -finalize-memref-to-llvm   -lower-affine -finalize-memref-to-llvm   -convert-arith-to-llvm  -convert-math-to-llvm -convert-scf-to-cf  -convert-arith-to-llvm  -convert-func-to-llvm -convert-func-to-llvm  -reconcile-unrealized-casts | /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner -e main -entry-point-result=void --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_c_runner_utils.so --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_runner_utils.so --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_async_runtime.so

``` 

### 3. **Output without `--test-math-polynomial-approximation`:**:

``` 
[[[-0.0299986,    -0.0299986,    -0.0299986,    -0.0299986],
 [-0.0299986,    -0.0299986,    -0.0299986,    -0.0299986],
  [-0.0299986, -0.0299986,    -0.0299986,    -0.0299986],
  [-0.0299986,    -0.0299986, -0.0299986,    -0.0299986]]]

``` 

### 4. **Command to Run With `--test-math-polynomial-approximation`:**:


``` 
 /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt /data/szy/workspace/mlir-inconsistent/tosa.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))" |  /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -tosa-to-arith  --test-math-polynomial-approximation -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops  -finalize-memref-to-llvm   -lower-affine -finalize-memref-to-llvm   -convert-arith-to-llvm  -convert-math-to-llvm -convert-scf-to-cf  -convert-arith-to-llvm  -convert-func-to-llvm -convert-func-to-llvm  -reconcile-unrealized-casts | /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner -e main -entry-point-result=void --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_c_runner_utils.so --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_runner_utils.so --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_async_runtime.so
``` 

### 5. **Output with `--test-math-polynomial-approximation`:**:

``` 
[[[1,    1,    1,    1],
  [1,    1,    1,    1],
  [1,    1,    1, 1],
  [1,    1,    1,    1]]]
``` 

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWM1u2zwWfRp6Q1CgKMk_Cy8cuwYCtJhBO4NZFpR0ZXOGIgX-OE6ffkBKcuw6TZ0m_TZfAUGOqKtzzuWl7lHIrRU7BbBExR0qNhPu3V6b5YdWyEd-hEmp68cloqudcPgAxgqtULbCvG7mC1bP8qxGdIXoyj5aB224hab036VXzuN0ntA8meKP__qCprSPQyxDLMMbsJURnevhEF3dY95iOHZgBKhKqB3mCgtVaWWFdaAcNmC9dPhhDwrDESrvQpTbA7a8Bfzp4_1n3Bm9M7zFD8LtMVd1_EN7F8PQlBLiwDrScrcnnZaPSreCS8K7zuijaHnUM6UJjnKUdth6A4HT7cH0ZNBy5USFdfMKRGz32ssa86aBqpfT52OTi3n54qCz2Gn8GTqja19BPz3nQSEuTTBiK8RWMe1_DmkjNudJK4VBbNHf7p8eBkNx6CqUIh7hotW1l4DR7A7RFcaNV1USTrgz4sAdYJTTzgjlPkFroLnPGGJzB8pqg7I1YqujyBjKPgTCWwC21wDNDwBQTlsuFGJzxBYnhRgjVlCMsg1GjDlteRLWiEOMjZHZGs3uDlx6iGE1KAthsLijiK0xC6cUFRuUfcBhTk5qsjGZ2eneg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