<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/119876>119876</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] Inconsistent output when executing MLIR program with and without `-test-loop-fusion=test-loop-fusion-transformation`
</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 [ea44647](https://github.com/llvm/llvm-project/commit/ea44647a0b49de826191eeb6e05020262b5a81e9).
## Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without the `-test-loop-fusion=test-loop-fusion-transformation`.
## Steps to Reproduce:
### 1. **MLIR Program (test.mlir)**:
test.mlir:
```
module {
func.func private @printMemrefI64(tensor<*xi64>)
func.func @main() -> () {
%arg0 = "tosa.const"() {value = dense<20> : tensor<36x2x3xi64>} : () -> tensor<36x2x3xi64>
%0 = tosa.reduce_sum %arg0 {axis = 0 : i32} : (tensor<36x2x3xi64>) -> tensor<1x2x3xi64>
%rtn1 = tensor.cast %0 : tensor<1x2x3xi64> to tensor<*xi64>
call @printMemrefI64(%rtn1) : (tensor<*xi64>) -> ()
return
}
}
```
### 2. **Command to Run Without `-test-loop-fusion=test-loop-fusion-transformation`:**
```
/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -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-cpu-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-loop-fusion=test-loop-fusion-transformation`:**
```
[[[720, 720, 720],
[720, 720, 720]]]
```
### 4. **Command to Run With `-test-loop-fusion=test-loop-fusion-transformation`:**
```
/path/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline='builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))' | \
/path/llvm-project/build/bin/mlir-opt -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops -test-loop-fusion=test-loop-fusion-transformation -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-cpu-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-loop-fusion=test-loop-fusion-transformation`:**
```
[[[20, 20, 20],
[20, 20, 20]]]
```
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/eJzsV0uPozgQ_jXOpWQE5hUOOaSTidTSjHY1e9jjyEBBvAIb-ZFO769f2ZCkX9Orae1IexjJAsd8rvooV32huDGil4gbkt-RfL_izh6V3nzmY600y1a1ah83Xx6hFxZOqI1QEoQBkt8hz7IiK0m-J2x9tHYyJN0SdiDs0At7dHXUqJGwwzCcLjc6afUXNpawQ6PGUfjJYobHdVa1uGZFUiWIdYFxHrOYFazO-TrBirAqIvHWD5YSlsIeTaPFZIWS3nG8vQc-Ap4n1AJlI2QPXIKQjZJGGIvSgkbjBgsPR5SAZ2yc9Sh7RDB8RPjy-f4rTFr1mo_wIOwRuGzDRDkbYKSIqUVj6aDURDtng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