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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR]Inconsistent Results from `tosa.arithmetic_right_shift` Operation
        </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: [98e8f01](https://github.com/llvm/llvm-project/commit/98e8f01d183177a4f54187c23183da50a7cf6daf)

## Description:
The `tosa.arithmetic_right_shift` operation should always yield a consistent result when applied to the same inputs. However, executing the same lowering sequence multiple times produces inconsistent results.

## Steps to Reproduce:

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

```
module {
  func.func private @printMemrefI16(tensor<*xi16>) attributes {llvm.emit_c_interface}
  func.func @main() {
    %0 = "tosa.const"() <{values = dense<53> : tensor<2xi16>}> : () -> tensor<2xi16>
    %1 = "tosa.const"() <{values = dense<10> : tensor<2xi16>}> : () -> tensor<2xi16>
    %2 = tosa.arithmetic_right_shift %1, %0 {round = true} : (tensor<2xi16>, tensor<2xi16>) -> tensor<2xi16>
    %cast = tensor.cast %2 : tensor<2xi16> to tensor<*xi16>
    call @printMemrefI16(%cast) : (tensor<*xi16>) -> ()
    return
  }
}
```

#### Command:
```
/home/workdir/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg))" | \
/home/workdir/llvm-project-latest/build/bin/mlir-opt -tosa-to-arith \
-one-shot-bufferize="bufferize-function-boundaries=1" \
-convert-linalg-to-affine-loops \
-lower-affine \
-convert-scf-to-cf \
-convert-to-llvm | \
/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:
```
[0, 0]
```
```
[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