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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] Inconsistent output when executing MLIR program with and without `-tosa-test-quant-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 [55fdecc](https://github.com/llvm/llvm-project/commit/55fdeccc4567bcd4e3f8df0d177195880a194a6a).

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

## Steps to Reproduce:

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

test.mlir:

```
module {
  func.func private @printMemrefI32(tensor<*xi32>)
  func.func @main() -> () {
    %arg0 = "tosa.const"() {value = dense<-4636> : tensor<52x3x2xi64>} : () -> tensor<52x3x2xi64>
    %0 = tosa.reduce_sum %arg0 {axis = 0 : i32} : (tensor<52x3x2xi64>) -> tensor<1x3x2xi64>
    %1 = tosa.equal %0, %0 : (tensor<1x3x2xi64>, tensor<1x3x2xi64>) -> tensor<1x3x2xi1>
    %2 = tosa.cast %1 : (tensor<1x3x2xi1>) -> tensor<1x3x2xi32>
    %rtn2 = tensor.cast %2 : tensor<1x3x2xi32> to tensor<*xi32>
    call @printMemrefI32(%rtn2) : (tensor<*xi32>) -> ()
    return
 }
}
```

### 2. **Command to Run Without `-tosa-test-quant-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 -convert-cf-to-llvm -convert-arith-to-llvm -finalize-memref-to-llvm -convert-func-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 `-tosa-test-quant-utils`:**

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

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

```
/path/llvm-project/build/bin/mlir-opt test.mlir -tosa-test-quant-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 -convert-cf-to-llvm -convert-arith-to-llvm -finalize-memref-to-llvm -convert-func-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 `-tosa-test-quant-utils`:**

```
[[[-1,    -1], 
  [-1, -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/eJzsV0-P4rgT_TTmUjJKbELgwIGGaamlGf1-mj3sceQ4FfAqsTP-Q9P76Vd2AjTTNKOd2dVeRrLSiVN-78Wuek0J59ROI65I8UCK7UQEvzd29VF0lbFsNqlM_bL69AI75eGA1imjQTkgxUNRNDVKSYotYYu9970jfE3YI2GPO-X3oZpK0xH22LaH0x_aW_MHSk_YozRdp-LNCCNnxbysZD1D3izqJqvzssyXxWKRiXw5E3NB2HJKsnUcjBP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