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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] Inconsistent output with `-convert-arith-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: [98e8f01](https://github.com/llvm/llvm-project/commit/98e8f01d183177a4f54187c23183da50a7cf6daf)

## Description:
Since the shift amount is 0, the `tosa.arithmetic_right_shift` operation does not change the value. However, when using the `-convert-arith-to-llvm` pass, I am encountering inconsistent results.

## Steps to Reproduce:

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

```
module {
  func.func private @printMemrefI64(tensor<*xi64>)
  func.func @main() {
    %cst0 = "tosa.const"() {values = dense<125> : tensor<i64>} : () -> tensor<i64>
    %cst1 = "tosa.const"() {values = dense<0> : tensor<i64>} : () -> tensor<i64>  // Modified to ensure a non-negative shift amount
    %2 = tosa.arithmetic_right_shift %cst0, %cst1 {round = true} : (tensor<i64>, tensor<i64>) -> tensor<i64>
    %cast = tensor.cast %2 : tensor<i64> to tensor<*xi64>
    call @printMemrefI64(%cast) : (tensor<*xi64>) -> ()
 return
  }
}
```
### 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-named,tosa-to-linalg))" |\
/home/workdir/llvm-project-latest/build/bin/mlir-opt -linalg-fuse-elementwise-ops -one-shot-bufferize="bufferize-function-boundaries=1" -convert-linalg-to-loops  -convert-scf-to-cf  -gpu-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:
```
[125]
```
### 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-named,tosa-to-linalg))" |\
/home/workdir/llvm-project-latest/build/bin/mlir-opt -convert-arith-to-llvm -linalg-fuse-elementwise-ops -one-shot-bufferize="bufferize-function-boundaries=1" -convert-linalg-to-loops  -convert-scf-to-cf  -gpu-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:
```
[94195214772498]
```
```
[0]
```
```
[10]
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsV12PqzYT_jXOzcgIDA5wkYtscqJ3pXfV6pxKvVwZGIJbYyN_ZHv66ytDNrvZkz0fvelFKyEiYGaeZ2aesSbCOXnUiBvC7wjfr0Twg7Eb94QoulVjus8bj85Da8ZRepJvgfC7usKqTzPC94RVg_eTI_mWsANhh6P0Q2iS1oyEHZQ6Pf_QyZrfsPWEHc6h2OEcpsuqPCtLUfS8yKqyZXlW5Z3gqSjbft2JnrCapNt4sZywHPboWisnL42OuOn2k9Qtgh8Q3CB7D2I0QXuQDlLCdvMHsk69cSIRVvphRC_bRyuPg3-cPcg6BTOhFTEmdAYdaOOhHYQ-LoFPQgVM4H_mCU9oY9SnATUEJ_XxGYC2Rp_QejqDUG_oXIB1CpNwLvrcgxgBdRvpoY2uUrdGO-k8ag8WXVDeJVfZfvI4OfAGPuJkTRdaXJK-WESjB6nlKBQ8_P_-I0zWHK0YgbAq9i4ZlbSxhhe3dXq-0u1ouqAQSHlH0i1AH3SbxBtMVp6ERyBFOlmp_QOOFvv7dTFH1c5Yku8I2_4h1wXJPyw9eh2AFOkopCasIqy-AAAQxlvnUyD5Hghjc1diDTxh7MV4rrebjTrUDkm-yxgn-QeIGrwQOIOX-_n12Z1Gs7cmr8GzHwdP_z50RI2jAQ-mk73ELjYTtQsWQY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