<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/119836>119836</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] Inconsistent output when executing MLIR program with and without `-test-expand-math`
</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-expand-math`.
## Steps to Reproduce:
### 1. **MLIR Program (test.mlir)**:
test.mlir:
```
module {
func.func private @printMemrefF32(tensor<*xf32>)
func.func @main() -> () {
%arg0 = "tosa.const"() {value = dense<9.5> : tensor<10x20xf32>} : () -> tensor<10x20xf32>
%0 = tosa.reduce_prod %arg0 {axis = 1 : i32} : (tensor<10x20xf32>) -> tensor<10x1xf32>
%1 = tosa.floor %0 : (tensor<10x1xf32>) -> tensor<10x1xf32>
%rtn1 = tensor.cast %1 : tensor<10x1xf32> to tensor<*xf32>
call @printMemrefF32(%rtn1) : (tensor<*xf32>) -> ()
return
}
}
```
### 2. **Command to Run Without `-test-expand-math`:**
```
/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 -convert-scf-to-cf -expand-strided-metadata -convert-cf-to-llvm -convert-arith-to-llvm -convert-math-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-expand-math`:**
```
[[3.58486e+19],
[3.58486e+19],
[3.58486e+19],
[3.58486e+19],
[3.58486e+19],
[3.58486e+19],
[3.58486e+19],
[3.58486e+19],
[3.58486e+19],
[3.58486e+19]]
```
### 4. **Command to Run With `-test-expand-math`:**
```
/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 -test-expand-math -convert-scf-to-cf -expand-strided-metadata -convert-cf-to-llvm -convert-arith-to-llvm -convert-math-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-expand-math`:**
```
[[9.22337e+18],
[9.22337e+18],
[9.22337e+18],
[9.22337e+18],
[9.22337e+18],
[9.22337e+18],
[9.22337e+18],
[9.22337e+18],
[9.22337e+18],
[9.22337e+18]]
```
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/eJzsV01v27oS_TX0ZkBBGkmWtPDCiWsgQIv30Ld4y4KSxjYvJFLgh5vcX39Byh9J4-aiub2rFhBkmhydc0TOHHuEtXKviFasvGPlZiG8O2iz-ijGVhssFq3un1afnmAvHRzJWKkVSAusvCNRFMuiYuWGYX1wbrIsXzPcMtzupTv4Nun0yHA7DMfzB5-M_oM6x3Db6XGUYXCCEWlbND3VuMyajKhdUlqmmOIS21LUGTUMm4Sl63BhzjCHDdnOyMlJrQJxun4AMQI9TmQkqU6qPQgFUnVaWWkdKQeGrB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