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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR]Non-deterministic results from repeated JIT executions
        </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: [f3a3270](https://github.com/llvm/llvm-project/commit/f3a3270dbca3649b7d56aaa42cb8481fb34e2d67)


## Description:

Each JIT compilation yields different output tensors, even though the program and input are unchanged.

## Steps to Reproduce:


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

```
module {
 func.func private @printMemrefI32(tensor<*xi32>)
  func.func @main() {
 %0 = "tosa.const"() <{values = dense<false> : tensor<7x5x10xi1>}> : () -> tensor<7x5x10xi1>
    %1 = tosa.argmax %0 {axis = 0 : i32} : (tensor<7x5x10xi1>) -> tensor<5x10xi32>
    %cast = tensor.cast %1 : tensor<5x10xi32> to tensor<*xi32>
    call @printMemrefI32(%cast) : (tensor<*xi32>) -> ()
    return
  }
}
```

### Command:
Execute first:
```
mlir-opt test.mlir --pass-pipeline="builtin.module(func.func(tosa-to-linalg))"  | \
mlir-opt --tosa-to-tensor --sparsification-and-bufferization="parallelization-strategy=any-storage-any-loop" \
--sparsification-and-bufferization="parallelization-strategy=any-storage-any-loop" --test-linalg-transform-patterns=test-patterns \
--tosa-to-arith --sparsifier -o output3.mlir |  \
```
Next, run the JIT compilation:
```
mlir-runner output3.mlir -e main -entry-point-result=void -shared-libs=/home/workdir/llvm-project/build/lib/libmlir_runner_utils.so
```
### Possible Output(across runs):

```
[[0,   0,   0,   0,   0,   0,   0,   0, 0,   0], 
 [0,   0,   0,   0,   0,   0,   0,   0,   0,   0], 
 [0,   0, 0,   0,   0,   1,   0,   0,   0,   0], 
 [0,   0,   0,   1,   0,   0,   0, 0,   0,   0], 
 [0,   0,   0,   0,   0,   0,   0,   0,   2, 0]]
```

```
[[0,   0,   0,   1,   0,   1,   0,   0,   0,   0], 
 [0, 0,   0,   0,   0,   0,   0,   3,   3,   0], 
 [0,   0,   0,   0,   0,   0, 0,   0,   1,   1], 
 [0,   0,   0,   0,   0,   0,   0,   0,   0,   0], 
 [0,   0,   0,   0,   0,   0,   0,   0,   0,   0]]
```
```
[[0,   0,   3, 0,   1,   1,   0,   0,   0,   0], 
 [0,   0,   1,   1,   0,   0,   0,   0, 0,   0], 
 [0,   0,   0,   0,   0,   0,   0,   0,   0,   0], 
 [0,   0, 0,   0,   0,   0,   0,   0,   0,   0], 
 [0,   0,   3,   0,   1,   1,   0, 0,   0,   0]]
```
....





</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMV12P2ygX_jXkBmE5YMfJRS4y8UTqq7fdVXfvq2NzHLOLwQI8zeyvX2E7aaZN1cxUu1oJmRAOz3nOBwcA79XRIG5J_kDycgFDaK3b-s-IIBeVlc_bgD7Q2nadCkTsKMkfGgGCFynJS8LXbQi9J2JH-IHww1GFdqiS2naEH7R-Onesd_YPrAPhhxmKH2YYWdUgVtmmKmS-AoCM19U6Wy-bSmTI5aogfEPS3dy4IFzQEn3tVB-UNVH1OPUIdUv_9-73yLVXGuIkfVaopadSNQ06NIHaIfRDoAGNt84Tvqf4hIaG1g7HloYWae_s0UFHwUiqTBQGh3QwdQvmiDJ5QeS3gL2nwdKP2DsrhxovfC5CUe69MqoDTd___93HiwbC19G5SaeVi0ZeVq7SuaW7zspBIyXFA0l3tBlMncQP7Z16goCUZGnvlAnvsXPYvBN8BI3GEbEnfHdSghPxOPmQXgGQLO1AGcLXhG_O-ITnKSWipITzYD0ktTU-EM7PYmJPiocn0AP6UU6i8UjEvgEd-0caU-Sivzjlp2V6UsvIoCjP8zMYi-PbspEqjWyWo5aRCrhjB6eZYvEAJzVRSEfMaGZRnuFvo36jc5qbHHRRWYMPk9ZRLJ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