<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/119852>119852</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Inconsistent output when executing MLIR program with `--linalg-fuse-elementwise-ops `
        </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 `--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],
  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