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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] Inconsistent output when executing MLIR program with and without `-scf-for-loop-peeling=peel-front=true`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Lambor24
      </td>
    </tr>
</table>

<pre>
    My git version is [32f7f00](https://github.com/llvm/llvm-project/commit/32f7f0010bca99ee4bd917f57272733fb2bf3bd9).

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

## Steps to Reproduce:

### 1. **MLIR Program (test.mlir)**:

test.mlir:

```
module {
  func.func private @printMemrefF32(tensor<*xf32>)
  func.func @main() -> () {
 %arg0 = "tosa.const"() {value = dense<3.88> : tensor<2x2xf32>} : () -> tensor<2x2xf32>
    %0 = tosa.floor %arg0 : (tensor<2x2xf32>) -> tensor<2x2xf32>
    %rtn1 = tensor.cast %0 : tensor<2x2xf32> to tensor<*xf32>
    call @printMemrefF32(%rtn1) : (tensor<*xf32>) -> ()
 return
  }
}
```

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

```
/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 -convert-scf-to-cf -expand-strided-metadata -convert-cf-to-llvm -convert-arith-to-llvm -convert-math-to-llvm -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 `-scf-for-loop-peeling=peel-front=true`:**

```
[[3, 3], 
 [3,   3]]
```

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

```
/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 -scf-for-loop-peeling=peel-front=true -convert-scf-to-cf -expand-strided-metadata -convert-cf-to-llvm -convert-arith-to-llvm -convert-math-to-llvm -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 `-scf-for-loop-peeling=peel-front=true`:**

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

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/eJzsV01v2zgQ_TX0ZUBBHtqWdfDBsWsgQItddA97LChpZHMhkQI_3GR__YKUYjtNkG2K7Z4KCDJDjd48ch5fNNI5ddREG7a8Y8v9TAZ_MnbzUfaVsbiYVaZ53Hx6hKPycCbrlNGgHLDlncC2aPOcLfcM1yfvB8fEluGB4eGo_ClUWW16hoeuOz_98MGav6j2DA-16XsVBxPMPK9qWZZEi6op50W7LLDAQoi2wqoVVVMyLDOWb-OFgqGAPbnaqsEro2PifHsPsgd6GMgq0rXSR5AalK6Ndsp50h4sudB5-HoiDfRAdfAxyp8InOwJPn28_wyDNUcre_iq_AmkbtLABJ_C2Crnrm55ayzvjBn4QNQpfWRiH0e8tUZ7JvbeBmKr_DnhPzwND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