Issue 154259
Summary [MLIR] Inconsistent output with `-convert-arith-to-llvm`
Labels mlir
Assignees
Reporter sweead
    test commit: [98e8f01](https://github.com/llvm/llvm-project/commit/98e8f01d183177a4f54187c23183da50a7cf6daf)

## Description:
Since the shift amount is 0, the `tosa.arithmetic_right_shift` operation does not change the value. However, when using the `-convert-arith-to-llvm` pass, I am encountering inconsistent results.

## Steps to Reproduce:

### Minimal MLIR program (test.mlir):

```
module {
  func.func private @printMemrefI64(tensor<*xi64>)
  func.func @main() {
    %cst0 = "tosa.const"() {values = dense<125> : tensor<i64>} : () -> tensor<i64>
    %cst1 = "tosa.const"() {values = dense<0> : tensor<i64>} : () -> tensor<i64>  // Modified to ensure a non-negative shift amount
    %2 = tosa.arithmetic_right_shift %cst0, %cst1 {round = true} : (tensor<i64>, tensor<i64>) -> tensor<i64>
    %cast = tensor.cast %2 : tensor<i64> to tensor<*xi64>
    call @printMemrefI64(%cast) : (tensor<*xi64>) -> ()
 return
  }
}
```
### 1. Without -convert-arith-to-llvm:

#### Command:
```
/home/workdir/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))" |\
/home/workdir/llvm-project-latest/build/bin/mlir-opt -linalg-fuse-elementwise-ops -one-shot-bufferize="bufferize-function-boundaries=1" -convert-linalg-to-loops  -convert-scf-to-cf  -gpu-to-llvm | \
/home/workdir/llvm-project/build/bin/mlir-runner -e main -entry-point-result=void -shared-libs=/home/workdir/llvm-project/build/lib/libmlir_runner_utils.so
```
#### Output:
```
[125]
```
### 2. With -convert-arith-to-llvm:
```
/home/workdir/llvm-project/build/bin/mlir-opt test.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))" |\
/home/workdir/llvm-project-latest/build/bin/mlir-opt -convert-arith-to-llvm -linalg-fuse-elementwise-ops -one-shot-bufferize="bufferize-function-boundaries=1" -convert-linalg-to-loops  -convert-scf-to-cf  -gpu-to-llvm | \
/home/workdir/llvm-project/build/bin/mlir-runner -e main -entry-point-result=void -shared-libs=/home/workdir/llvm-project/build/lib/libmlir_runner_utils.so
```
#### Output:
The results are inconsistent. Possible output include:
```
[94195214772498]
```
```
[0]
```
```
[10]
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to