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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Inconsistent output when executing MLIR program with and without --scf-for-loop-peeling="peel-front"
        </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: adf892d743d

system: `Ubuntu 18.04.6 LTS`

## Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without the `--scf-for-loop-peeling="peel-front"`.

## 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() {
    %0 = "tosa.const"() <{value = dense<3380> : tensor<1x6x6xi32>}> : () -> tensor<1x6x6xi32>
    %1 = tosa.cast %0 : (tensor<1x6x6xi32>) -> tensor<1x6x6xf32>
    %2 = tosa.erf %1 : (tensor<1x6x6xf32>) -> tensor<1x6x6xf32>
    %cast = tensor.cast %2 : tensor<1x6x6xf32> to tensor<*xf32>
    call @printMemrefF32(%cast) : (tensor<*xf32>) -> ()
 return
  }
}


``` 

 ### 2. **Command to Run Without `--scf-for-loop-peeling="peel-front"`:**

``` 
 /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt a.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg))" | /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt  -tosa-to-arith -test-math-polynomial-approximation -convert-arith-to-llvm -convert-math-to-llvm  -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-loops  -finalize-memref-to-llvm  -convert-scf-to-cf -convert-arith-to-llvm  -convert-func-to-llvm  -convert-func-to-llvm -reconcile-unrealized-casts | /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 `--scf-for-loop-peeling="peel-front"`:**:

``` 
[[[1,    1,    1,    1, 1,    1], 
  [1,    1,    1,    1,    1,    1], 
  [1,    1,    1,    1, 1,    1], 
  [1,    1,    1,    1,    1,    1], 
  [1,    1,    1,    1, 1,    1], 
  [1,    1,    1,    1,    1,    1]]]

``` 

### 4. **Command to Run With `--scf-for-loop-peeling="peel-front"`:**:


``` 
 /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt a.mlir -pass-pipeline="builtin.module(func.func(tosa-to-linalg))" | /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt  -tosa-to-arith -test-math-polynomial-approximation -convert-arith-to-llvm -convert-math-to-llvm  -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-loops  -finalize-memref-to-llvm --scf-for-loop-peeling="peel-front"  -convert-scf-to-cf -convert-arith-to-llvm  -convert-func-to-llvm  -convert-func-to-llvm -reconcile-unrealized-casts | /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 `--scf-for-loop-peeling="peel-front"`:**:

``` 
[[[1,    3.07879e-41,    0,    0,    -2.17439e-08,    3.07879e-41],
  [1, 1,    1,    1,    1,    1],
  [1,    1,    1,    1,    1,    1],
  [1, 1,    1,    1,    1,    1],
  [1,    1,    1,    1,    1,    1],
  [1, 1,    1,    1,    1,    1]]]
``` 

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWM2O2zYQfprxhaBAkbIlHXxw1jGwQIIWSYseA0oa2SwoUiApx87TF5T8s5t4s0maFG0RQBBNauabj8P5MSi9V1uDuIT5C5ivZ3IIO-uWLzulj_KAs8o2x-VWBbJH55U1IFZENm1R8ibPRANsBWzljz5gFz_Bgv1eDSYMJC0SliUL8uq3t7BgkxxwAVyQNfraqT5McMBW90R2BA89OoWmVmZLpCHK1NZ45QOaQBz6QQfyfoeG4AHrIUSpsEPiZYfk9av7N6R3dutkR96rsCPSNOMPO4RRDBaMUl-3tLWOamt72iNqZbYg1sB5nNDWWROAc1iw5BHhtwF7T4Ilb7B3thlqnHg_FIpyaUKAr4CvRj6_nvgAL2TSaeWAl9PnSfu0GL3GVtFH4xMnnW0GjQTyF8BWpB1MncQX6Z3ay4AEMtY7ZcJr7By294IDLwIabx2IO-CrgxIcxMtoj63IswCbTwHaJwAgY51UBngBvDwTJIQAnzMCYk2A82C9TOLZjb48SYo7yF_spR5wFGvQeARxJ0TBQLwk0QsXAulhcVic95Cvz99PUDTOb8teuKSjkYmI9OFMb8S4rfoEcPsRML8Co2vPpm7htl-FO7GM0KPchTW_5ZlJOcbjrTObMGup9c1jPhmbDuUx8UcHP9GefB4xHYbBmRE9nglbnd7T8zB6o8w1J_g5J-5s18WsjGk0GPLHKTm_MjFj6kw59KlhAnzTyCCBb_yHI_BNTEPgG633HXWoUXo8T3tn_8Q6AN9Ug9JNHGNYb2JKUtsHMmUnob30nvaqj5xw4hQ1gjLJlKbAi0t-RG9aL2mwVCsj9XZM-RI4J5DffVd-hJ4tSRcLHg3oA-1k2NHe6qOxnZKayr539qA6GYstobU1e3RhUhlZ6n13XR61z6uEWoPU72yg1dC26NSHy_5PUxr3HJFpZQfTSKfQx71eACcnjJDW9p4Q2saVqNqNMfnA2lknxkKwtG6fontdj-afW6YOa2tqpZEOxuFovK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