<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118942>118942</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] Inconsistent output when executing MLIR program with and without `-test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jzc-1122
</td>
</tr>
</table>
<pre>
My git version is [35619c7](https://github.com/llvm/llvm-project/commit/35619c791d1f5128d16c7a8e099e8856e12ab39c).
## Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without the `-test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control`.
The outputs are also inconsistent when running multiple times with the `-test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control`.
## 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<94> : tensor<i32>} : () -> tensor<i32>
%arg1 = "tosa.const"() {value = dense<91> : tensor<i32>} : () -> tensor<i32>
%0 = tosa.arithmetic_right_shift %arg0, %arg1 {round = true} : (tensor<i32>, tensor<i32>) -> tensor<i32>
%rtn1 = tensor.cast %0 : tensor<i32> to tensor<*xi32>
call @printMemrefI32(%rtn1) : (tensor<*xi32>) -> ()
return
}
}
```
### 2. **Command to Run Without `-test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control`:**
```
/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-tensor -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-loops -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-linalg-elementwise-fusion-patterns=fuse-generic-ops-control`:**
```
[0]
```
### 4. **Command to Run With `-test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control`:**
```
/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-tensor -tosa-to-arith -test-linalg-elementwise-fusion-patterns=fuse-generic-ops-control -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-loops -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-linalg-elementwise-fusion-patterns=fuse-generic-ops-control`:**
```
[222542855]
```
This output is different when executed multiple times.
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="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWF2Pm7wS_jXOzcgRGAjhIhfZpJFWOtU56qn0Xq4cM4ArYyN_ZHf7618ZSLIf1VZtt72qhAiY8TyPxzOPd5Y7J1uNuCHFDSn2Cx58Z-zmy1dB05SxxdHUj5uPj9BKDye0ThoN0gEpbrJilVaiJMWesHXn_eBItiXsQNihlb4Lx6UwPWEHpU7nHzpY8wWFJ-wgTN_L-DC7qdI6bYqUret0JUq-xqSqcL0uV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