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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] Inconsistent output when executing MLIR program with and without `-convert-math-to-llvm`
        </td>
    </tr>

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

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

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

<pre>
    test commit: [87e39c3](https://github.com/llvm/llvm-project/commit/87e39c399c96128307a826fd9168679f7c8c8d10)

## Description:

I am experiencing an inconsistent result when executing the same MLIR program with and without the `-convert-arith-to-llvm`.


## Steps to Reproduce:

### Minimal MLIR program (test.mlir):

```
#map = affine_map<(d0, d1) -> (d0, d1)>
module {
  func.func @main() -> () {
 %0 = "tosa.const"() <{values = dense<-170> : tensor<3x4xi64>}> : () -> tensor<3x4xi64>
    %1 = "tosa.const"() <{values = dense<0> : tensor<1x4xi64>}> : () -> tensor<1x4xi64>
    %2 = tosa.arithmetic_right_shift %0, %1 {round = true} : (tensor<3x4xi64>, tensor<1x4xi64>) -> tensor<3x4xi64>
    %cast = tensor.cast %2 : tensor<3x4xi64> to tensor<*xi64>
    call @printMemrefI64(%cast) : (tensor<*xi64>) -> ()
    return
  }
  func.func private @printMemrefI64(tensor<*xi64>)
}
```
### 1. Without -convert-arith-to-llvm:

#### Command:
```
/home/workdir/llvm-project/build/bin/mlir-opt test.mlir --pass-pipeline="builtin.module(func.func(tosa-to-linalg))"| \
/home/workdir/llvm-project/build/bin/mlir-opt   -sparsifier | \
/home/workdir/llvm-project/build/bin/mlir-runner -e main -entry-point-result=void -shared-libs=/home/workdir/llvm-project/build/lib/libmlir_runner_utils.so

```
#### Output:
```
[[-170,   -170,   -170,   -170], 
 [-170,   -170,   -170, -170], 
 [-170,   -170,   -170,   -170]]
```
### 2. With -convert-arith-to-llvm:
```
/home/workdir/llvm-project/build/bin/mlir-opt test.mlir --pass-pipeline="builtin.module(func.func(tosa-to-linalg))"| \
/home/workdir/llvm-project/build/bin/mlir-opt -convert-arith-to-llvm -sparsifier | \
/home/workdir/llvm-project/build/bin/mlir-runner -e main -entry-point-result=void -shared-libs=/home/workdir/llvm-project/build/lib/libmlir_runner_utils.so
```
#### Output:
The results are inconsistent. Possible output include:
```
[[93942316279653,   0,   0,   0], 
 [0,   0,   0,   0], 
 [0,   0,   0,   0]]
```
```
[[94258813645071,   0,   140648166016064, 140648166015632], 
 [2,   0,   0,   0], 
 [3,   0,   0, 0]]
```
```
[[0,   0,   0,   0], 
 [0,   0,   0,   0], 
 [0,   0,   0, 0]]
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzcV01vpDgQ_TXuiwWCMp-HPnS6p6VIO9rV7Ep7jAwUjXfBRrZJMv9-ZUMyISFRz-Y2EuLL5Vevyq9MwY0RF4m4J-kNSU87PtlO6b15QOTNrlLN971FY2mthkFYwg6UpDdFjqysGUlPBIrO2tEQdiBwJnC-CNtNVVirgcC57--fLsGo1T9YWwLnBQrOC0xZ1mUWQ8GinBeQtU0ZZ0WWl21eF3XRxBGBkkQHdwAjwOgJTa3FaIWSzq8fuqV8oPg4ohYoayEvlEsqZK2kEcaitFSjmXpLHzqUFB-xnqyzsh1SwwekX3-7_UZHrS6aD_RB2I5y2fgbNVlvRrIoqJW8R20DroXtAqsCH2IWhQvBZ45_WhwNtYp-w1GrZqrxmeps4Yy-CikG3q99EyhcxsOhF9pF_jwti5bDQwx8pISdKG9bIfFu4CNhRwJFExE40iYmUNKAsC90_Y6wLyQ6DKqZeqQkvyHRgdJ2knXoTpQk0cCFJFC8nO_uF1sCaeT9EgCrDA9dhi0BeDJjR5Lf3PN-QuPtGpQGCTsGcR55OHagFqVRmrAje0weRZY4UvnpafSl8y1Lx5g6IvH_IvKWRXw1i3iDBXh0T8GrYkAr6jstLp29M51orc-ZW4CZcn6j1SSbe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