<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/130025>130025</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 [6311e3f](https://github.com/llvm/llvm-project/commit/6311e3fcc8539cf0f474b28f82a465e83013a792).

## 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() {
    %0 = "tosa.const"() <{value = dense<-3.871940e+03> : tensor<3x3xf32>}> : () -> tensor<3x3xf32>
    %1 = tosa.ceil %0 : (tensor<3x3xf32>) -> tensor<3x3xf32>
    %cast = tensor.cast %1 : tensor<3x3xf32> to tensor<*xf32>
    call @printMemrefF32(%cast) : (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 -sparsification-and-bufferization -convert-linalg-to-affine-loops -lower-affine -convert-scf-to-cf -convert-cf-to-llvm -convert-arith-to-llvm -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | \
/path/llvm-project/build/bin/mlir-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`:**

```
[[-3871,   -3871, -3871], 
 [-3871,   -3871,   -3871], 
 [-3871,   -3871, -3871]]
```

### 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 -sparsification-and-bufferization -convert-linalg-to-affine-loops -lower-affine -scf-for-loop-peeling=peel-front=true -convert-scf-to-cf -convert-cf-to-llvm -convert-arith-to-llvm -finalize-memref-to-llvm -convert-func-to-llvm -reconcile-unrealized-casts | \
/path/llvm-project/build/bin/mlir-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`:**

```
[[-3871, 0,   0], 
 [-3871,   -3871,   -3871], 
 [-3871,   -3871, -3871]]
```

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="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsV02P2zYQ_TXjy4ACRUqWffDBa8fAAglapIceA1oa2SwkUuCHdze_vqDkj91mu02CJqcAgkxTwzdPw8cnjPJeHwzRCso7KLczFcPRutV71e-tE8Vsb5un1YcnPOiAJ3JeW4PaI5R3c5nnJFsotyAWxxAGD3INYgdid9DhGPdZbXsQu647XX7Y4OxfVAcQu9r2vU6DM0xdL0q5rFveFlWxF4t2IVQxL2kheS5VtRQglhnwdbqEBCFxS752egjampSYr-9R9UiPAzlNptbmgMqgNrU1XvtAJqAjH7uAD0cySI9Ux5CiwpHQq57ww_v7jzg4e3CqxwcdjqhMMw5sDGMYzDnzdcta61hn7cAGok6bA8htGrHWWRNAboOLBHP-kvAfgQaPweJHGpxtYk0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