<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/119825>119825</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] Inconsistent output when executing MLIR program with `--scf-parallel-loop-tiling` `--canonicalize`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Emilyaxe
</td>
</tr>
</table>
<pre>
git version: 953838dceaf
system: `Ubuntu 18.04.6 LTS`
## Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without `--scf-parallel-loop-tiling` `--canonicalize`.
The output becomes correct when either of these two options is removed, so I'm unsure which optimization contains the bug.
## Steps to Reproduce:
### 1. **MLIR Program (a.mlir)**:
a.mlir:
```
module {
func.func private @printMemrefI32(tensor<*xi32>)
func.func private @printMemrefF32(tensor<*xf32>)
func.func @main() {
%7 = "tosa.const"() <{value = dense<6220> : tensor<1x6x6xi32>}> : () -> tensor<1x6x6xi32>
%9 = "tosa.const"() <{value = dense<-298> : tensor<1x6x6xi32>}> : () -> tensor<1x6x6xi32>
%51 = tosa.bitwise_or %7, %9 : (tensor<1x6x6xi32>, tensor<1x6x6xi32>) -> tensor<1x6x6xi32>
%cast = tensor.cast %51 : tensor<1x6x6xi32> to tensor<*xi32>
call @printMemrefI32(%cast) : (tensor<*xi32>) -> ()
return
}
}
```
### 2. **Command to Run without optimizations :**
```
/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt a.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg))" | /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-parallel-loops -convert-index-to-llvm -convert-arith-to-llvm -convert-scf-to-cf -convert-arith-to-llvm -convert-cf-to-llvm -finalize-memref-to-llvm -convert-func-to-llvm -lower-affine -convert-arith-to-llvm -reconcile-unrealized-casts | timeout 10 /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner -e main -entry-point-result=void --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_c_runner_utils.so --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_runner_utils.so --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_async_runtime.so
```
### 3. **Output without optimizations :**:
```
[[[-290, -290, -290, -290, -290, -290],
[-290, -290, -290, -290, -290, -290],
[-290, -290, -290, -290, -290, -290],
[-290, -290, -290, -290, -290, -290],
[-290, -290, -290, -290, -290, -290],
[-290, -290, -290, -290, -290, -290]]]
```
### 4. **Command to Run with optimizations :**
```
/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt a.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg))" | /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-parallel-loops -convert-index-to-llvm -convert-arith-to-llvm --scf-parallel-loop-tiling="parallel-loop-tile-sizes=1,4 no-min-max-bounds=true" --canonicalize --scf-parallel-loop-tiling="parallel-loop-tile-sizes=1,4 no-min-max-bounds=true" -convert-scf-to-cf -convert-arith-to-llvm -convert-cf-to-llvm -finalize-memref-to-llvm -convert-func-to-llvm -lower-affine -convert-arith-to-llvm -reconcile-unrealized-casts | timeout 10 /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-cpu-runner -e main -entry-point-result=void --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_c_runner_utils.so --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_runner_utils.so --shared-libs=/data/szy/MLIR/llvm-release/llvm-project/build/lib/libmlir_async_runtime.so
```
### 5. **Output with optimizations :**
```
[[[-290, -290, -290, -290, -290, -290],
[-290, -290, -290, -290, -290, -290],
[-290, -290, -290, -290, -290, -290],
[-290, -290, -290, -290, -290, -290],
[0, 0, 0, 32767, -1553697280, 22067],
[-1553697280, 22067, -1553697264, 22067, 0, 0]]]
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWMtu27wSfhp6Q1CQKEuyFl64cQ0EaHEO2p51QFEjmwcUKfDiOHn6H6TkSxKnLfqnRRcJDEUkh998M5yLTWat2CqAJSo-oGI9Y97ttFl-7IV8YAeYNbp9WG6Fw3swVmiF8hWui3yRL1oOrEPpCqUr-2Ad9GEJlen_Gq-cx9kiSedJiT99-4rKdJRDNEc0x2uw3IjBjXAoXd1i1mM4DGAEKC7UFjOFheJaWWEdKIcNWC8dvt-BwnAA7l2QcjvAlvWAP3-6_YIHo7eG9fheuB1mqo0v2rtAihDLOzIww6QESaTWA3FCCrVFZToKcKa0EpxJ8QioTBOUrr7tAGvvBu9wA1z3YDHXxgA_MhFuBwbrLjCxgN29xjraZbGw2ECv99AieoOtxreIVj32ynoD-H4n-C7K9uKRhR2Ya-WYUDZa1fht8sRnXx0MFjuNv8BgdOs5jK67FApyWYIRXSG6ii757-QSRBcs6aUwiNbj8rh7mgwHl67CMcVPGPS69RIwqj6gdIVx5xVPwgMPRuyZA4zm6WCEcp-hN9Dd5hTRhQNltUH5DaKrg8gpyj8GhT8DsHkJ0L0CgOZpz4RCdIFofWKIMaJFhVG-xohSpy1LQvw4ROlRMr9B1Yc9kx6iWAvKAspvSkpTlH_EwQ0nAtmhPJRHG6r1cX2CImF8XfbEpf4VLoTWi9_ApciilsikEe5eWLjTJnosROfENkJeR6I3r6j4SQKcWTdSiHLJOJ6IvWJqiPZrETWCcibl1SCctI1efmrSk7AceY9OnDANOG9UHAQ_p6vp-Sw3gsA54-gx425034eyE5LUq1P1uUxyGyhNCXgFl25a5hiiG_v4gOgmpDCiGyn3PTEggVk4Dgej_w_cIbppvJBt-B8yYhPSmejB4TGzMRmYtWQQA0ihAOVrRGnY4YRKxhRHdHFKreArbRlxmkihmNzGclEjSjGqQpi8HT9yVMRMK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