<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118939>118939</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] Inconsistent output when executing MLIR program with and without `-linalg-inline-scalar-operands`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</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 `-linalg-inline-scalar-operands`.
## 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<83> : tensor<i32>} : () -> tensor<i32>
%arg1 = "tosa.const"() {value = dense<36> : 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 `-linalg-inline-scalar-operands`:**
```
/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 -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 `-linalg-inline-scalar-operands`:**
```
[5]
```
### 4. **Command to Run With `-linalg-inline-scalar-operands`:**
```
/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 -linalg-inline-scalar-operands -tosa-to-arith -one-shot-bufferize='bufferize-function-boundaries' -convert-linalg-to-loops -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 `-linalg-inline-scalar-operands`:**
```
[0]
```
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/eJzsV02PozgT_jXOpWRkbAjhkEM6mUgtvaN3NXvYY8tABTwCG_kjMz2_fmUg6U_1fPTuYaWREHFMuZ6nyvVYLumcajXiluQ3JD-sZPCdsdvP32qappyvKtPcbz_eQ6s8nNE6ZTQoByS_Efk6LeuC5AfCN533oyNiR_iR8GOrfBeqpDYD4ce-P19-6GjNZ6w94cfaDIOKg8VNmTbpKU_5pknXdSE3yMoSN5t8jSmXlShrwsuEsF18uCBcwAFdbdXoldERmO3gFuQA-HVEq1DXSrcgNShdG-2U86g9WHSh9_ClQw34Fevgo5XvEJwcED7-7_YTjNa0Vg7wRfkOpG6mgQl-MiNrRnulZd9SpXulkbpa9tJSM6KVunFkzZ7S_NPj6MAb-ISjNU2ocWZ7tYhGaQKE7wjfTQz-WBgQvvHofDL0yhJezhbX1Q-frv7WbHnYbjBN6BFIcRMzA6eg6yS-YLTqLD0CydholfYfcbB4uhV8QtPOWCL2hO--KsGJ-BBxnzogGRuk0oRvCC-BEvEBlvEFDIDwXNqWAREHIJx742QSt8ETzh-Mz7IPONk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