Issue 119852
Summary [mlir] Inconsistent output when executing MLIR program with `--linalg-fuse-elementwise-ops `
Labels mlir
Assignees
Reporter Emilyaxe
    
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 `--linalg-fuse-elementwise-ops `.

## 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()  {
    %1 = "tosa.const"() <{value = dense<5319> : tensor<1x28x1xi32>}> : () -> tensor<1x28x1xi32>
    %2 = "tosa.const"() <{value = dense<-5633> : tensor<1x28x1xi32>}> : () -> tensor<1x28x1xi32>
    %8 = tosa.int_div %1, %2 : (tensor<1x28x1xi32>, tensor<1x28x1xi32>) -> tensor<1x28x1xi32>
    %9 = tosa.clz %8 : (tensor<1x28x1xi32>) -> tensor<1x28x1xi32>
    %12 = tosa.logical_left_shift %8, %9 : (tensor<1x28x1xi32>, tensor<1x28x1xi32>) -> tensor<1x28x1xi32>
    %cast = tensor.cast %12 : tensor<1x28x1xi32> to tensor<*xi32>
    call @printMemrefI32(%cast) : (tensor<*xi32>) -> ()
 return 
  }
}

``` 

 ### 2. **Command to Run without `--linalg-fuse-elementwise-ops ` :**

``` 
/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt a.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))" | /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -tosa-to-arith   -convert-linalg-to-loops -one-shot-bufferize="bufferize-function-boundaries" --expand-strided-metadata    -convert-arith-to-llvm -test-math-polynomial-approximation      -convert-arith-to-llvm -convert-math-to-llvm  -convert-linalg-to-parallel-loops -finalize-memref-to-llvm   -convert-scf-to-cf  -convert-func-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  `--linalg-fuse-elementwise-ops `  :**:

``` 
[[[0],
  [0],
  [0],
  [0],
  [0]]]

``` 

### 4. **Command to Run with `--linalg-fuse-elementwise-ops ` :**


``` 
/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt a.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg-named,tosa-to-linalg))" | /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -tosa-to-arith   --linalg-fuse-elementwise-ops   -convert-linalg-to-loops -one-shot-bufferize="bufferize-function-boundaries" --expand-strided-metadata    -convert-arith-to-llvm -test-math-polynomial-approximation      -convert-arith-to-llvm -convert-math-to-llvm  -convert-linalg-to-parallel-loops -finalize-memref-to-llvm   -convert-scf-to-cf  -convert-func-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 `--linalg-fuse-elementwise-ops ` :**

``` 
[[[64],
  [22050],
  [1],
  [0],
  [0]]]
``` 

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

Reply via email to