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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] Inconsistent output when executing MLIR program with and without `-linalg-specialize-generic-ops`
        </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 [6311e3f](https://github.com/llvm/llvm-project/commit/6311e3fcc8539cf0f474b28f82a465e83013a792).

## Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without the `-linalg-specialize-generic-ops`.

## Steps to Reproduce:

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

test.mlir:

```
module {
  func.func private @printMemrefI64(tensor<*xi64>)
  func.func @main() {
    %0 = "tosa.const"() <{value = dense<false> : tensor<2x3xi1>}> : () -> tensor<2x3xi1>
    %1 = tosa.clamp %0 {max_val = true, min_val = false} : (tensor<2x3xi1>) -> tensor<2x3xi1>
    %2 = tosa.cast %1 : (tensor<2x3xi1>) -> tensor<2x3xi64>
    %cast = tensor.cast %2 : tensor<2x3xi64> to tensor<*xi64>
    call @printMemrefI64(%cast) : (tensor<*xi64>) -> ()
 return
  }
}
```

### 2. **Command to Run Without `-linalg-specialize-generic-ops`:**

```
/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 -sparsifier="vl=8" | \
/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 `-linalg-specialize-generic-ops`:**

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

### 4. **Command to Run With `-linalg-specialize-generic-ops`:**

```
/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 -linalg-specialize-generic-ops -tosa-to-arith -sparsifier="vl=8" | \
/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 `-linalg-specialize-generic-ops`:**

```
[[0,   0,   0], 
 [0,   0,   0]]
```

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/eJzsV1GPmzgQ_jWTlxHIGAjkIQ_ZpJFWanWn3sM9VgaGxCdjI9uku_frTwZCN22011Z7DydVQhjw8M3HzHxmLJyTJ020hfwB8sNKDP5s7Pa96CpjebaqTPO8_fCMJ-nxQtZJo1E6hPxhnSYJpS3kB-Dl2fveQboDfgR-PEl_Hqq4Nh3wo1KX6xD11vxFtQd-rE3XyXAxw9R1maebumVtVmQVL9uSi2ydU5myJBXFhgPfxMB24eAp8BQP5Gorey-NDo7Z7hFFh_TUk5Wka6lPKDRKXRvtpPOkPVpyg_L4-Uwa6YnqwQcrfyZ0oiP88P7xI_bWnKzo8LP0ZxS6GS_M4EczWLNISS3UKXI91VIo-TdFJ9JkZR2Z3sGa3bL8w1Pv0Bv8SL01zVDTRHaxCEZJjMB3wHcjg99nBsBLT87HnZIW-GayWN7-MrXgrdl8sF1nmkERQvEAbIfYDrqOwwl7Ky_CE0LGeiu1_0CdpfZxnY3etDMW0j3w3ZNcZ5C-C35vASBjnZAaeAl8szhABJ4zhPSAwLk3TsQh7h44v1qmeygeLkINNJo1pB1Bum-FCuM7hHSHCwP-lD7JJBAoDt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