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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] Inconsistent output when executing MLIR program with and without `-test-commutativity-utils`
        </td>
    </tr>

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

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

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

<pre>
    My git version is [9d7ca6c](https://github.com/llvm/llvm-project/commit/9d7ca6cdf038dab24fbc5c22a91be36604decb67).

## Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without the `-test-commutativity-utils`.

## Steps to Reproduce:

### 1. **MLIR Program (test.mlir)**:

test.mlir:

```
module {
  func.func private @printMemrefI32(tensor<*xi32>)
  func.func @main() {
    %0 = "tosa.const"() <{values = dense<2> : tensor<1x3xi32>}> : () -> tensor<1x3xi32>
    %1 = tosa.equal %0, %0 : (tensor<1x3xi32>, tensor<1x3xi32>) -> tensor<1x3xi1>
    %2 = tosa.cast %1 : (tensor<1x3xi1>) -> tensor<1x3xi32>
    %cast = tensor.cast %2 : tensor<1x3xi32> to tensor<*xi32>
    call @printMemrefI32(%cast) : (tensor<*xi32>) -> ()
 return
  }
}
```

### 2. **Command to Run Without `-test-commutativity-utils`:**

```
/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-tensor -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops -lower-affine -convert-scf-to-cf -expand-strided-metadata -lower-host-to-llvm -convert-cf-to-llvm -reconcile-unrealized-casts | \
/path/llvm-project/build/bin/mlir-runner -e main -entry-point-result=void \
-shared-libs=/path/llvm-project/build/lib/libmlir_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_c_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_async_runtime.so
```

### 3. **Output Without `-test-commutativity-utils`:**

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

### 4. **Command to Run With `-test-commutativity-utils`:**

```
/path/llvm-project/build/bin/mlir-opt test.mlir -test-commutativity-utils | \
/path/llvm-project/build/bin/mlir-opt -pass-pipeline='builtin.module(func.func(tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-tensor -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops -lower-affine -convert-scf-to-cf -expand-strided-metadata -lower-host-to-llvm -convert-cf-to-llvm -reconcile-unrealized-casts | \
/path/llvm-project/build/bin/mlir-runner -e main -entry-point-result=void \
-shared-libs=/path/llvm-project/build/lib/libmlir_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_c_runner_utils.so \
-shared-libs=/path/llvm-project/build/lib/libmlir_async_runtime.so
```

### 5. **Output With `-test-commutativity-utils`:**

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

I'm not sure if there is any bug in my program or if the wrong usage of the above passes caused this result.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsV0uP2zYQ_jX0ZUBDol7WwQevXQMLJGiRHnoMKGpks6BIlQ_vOr--oCR7dxPvBk1S9NAAgqjH8PuGnJkPHO6cPGjENSnuSLFb8OCPxq7f8b4xluWLxrTn9fszHKSHE1onjQbpgBR3dVsJXgpS7AhbHb0fHMk2hO0J2x-kP4ZmKUxP2F6p02WggzV_ovCE7YXpexkfZpi2S7JVyxuWd40oBGO8ThvMyjLJWxRNWRFWL0myiRfLCMtgh05YOXhpdCRONvfAe8DHAa1ELaQ-ANcgtTDaSedRe7DogvLwcEQN-Igi-GjljwiO9wjv391_gMGag-U9PEh_BK7b8cEEP5qRMqEenafR_eC5lyfpzzR4qRwpk5cO_u5xcOANfMDBmjYInPy8WkSjdAmEbQjbjOS_zeSErSLNslfSElZPFtfZT7-ueGUyX8mmN21QCKS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