<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/145514>145514</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] Inconsistent output when executing MLIR program with and without `-tosa-layerwise-constant-fold`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Lambor24
</td>
</tr>
</table>
<pre>
My git version is [e04c938](https://github.com/llvm/llvm-project/commit/e04c938cc08a90ae60440ce22d072ebc69d67ee8).
## Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without the `-tosa-layerwise-constant-fold`.
## Steps to Reproduce:
### 1. **MLIR Program (test.mlir)**:
test.mlir:
```
module {
func.func private @printMemrefI64(tensor<*xi64>)
func.func @main() {
%0 = "tosa.const"() <{values = dense<true> : tensor<7xi1>}> : () -> tensor<7xi1>
%1 = tosa.reduce_any %0 {axis = 0 : i32} : (tensor<7xi1>) -> tensor<1xi1>
%2 = tosa.cast %1 : (tensor<1xi1>) -> tensor<1xi64>
%cast = tensor.cast %2 : tensor<1xi64> to tensor<*xi64>
call @printMemrefI64(%cast) : (tensor<*xi64>) -> ()
return
}
}
```
### 2. **Command to Run Without `-tosa-layerwise-constant-fold`:**
```
/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-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-loops -expand-strided-metadata -lower-affine -convert-scf-to-cf -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
```
### 3. **Output Without `-tosa-layerwise-constant-fold`:**
```
[[1]]
```
### 4. **Command to Run With `-tosa-layerwise-constant-fold`:**
```
/path/llvm-project/build/bin/mlir-opt test.mlir -tosa-layerwise-constant-fold | \
/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-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-loops -expand-strided-metadata -lower-affine -convert-scf-to-cf -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
```
### 5. **Output With `-tosa-layerwise-constant-fold`:**
```
[[-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-P27YT_TTjy4CGTEmWffDBu46BBRL8fkgPPQYUNbJZUKTAP97dfvqCkmzH2dRN0wBFgRiCLFHDN08z80ak8F4dDNEGygcodzMRw9G6zXvR1dbxYlbb5nXz4RUPKuCJnFfWoPII5QNlhVznKyh3wFfHEHoP-Rb4Hvj-oMIx1nNpO-B7rU_nP9Y7-xvJAHwvbdepdDHBSJmtxDoTtMyKIpPEeZNVnGq5XDfLimgFfD2HbJsOngPPcUdeOtUHZU1ynG2fUHRILz05RUYqc0BhUBlpjVc-kAnoyEcd8PlIBumFZAzJKhwJvegIP7x_-oi9swcnOnxW4YjCNMOFjWEwg2XGgvWCafFK7ll5Ygk-CBNYa3UDy-yW5C-Beo_B4kfqnW2ipJHrxSIZLeYIfAt8OxD4_0QA-CqQD_NOKwd8PVpcZl8fXfCW2XRk2842URNC9QDZFrGNRs7TCXunTiIQQpH1TpnwgTpH7dOyGLwZbx3kj8C3L2pZQP4u-b0FgCLrhDLAU0IuDhC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