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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] Inconsistent output when executing MLIR program with and without `-test-expand-math`
        </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 [6003c30](https://github.com/llvm/llvm-project/commit/6003c3055a4630be31cc3d459cdbb88248a007b9).

## Description:
I am experiencing an inconsistent result when executing the same MLIR program with and without the `-test-expand-math`.

## Steps to Reproduce:

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

test.mlir:

```
module {
  func.func private @printMemrefF32(tensor<*xf32>)
  func.func @main() {
    %0 = "tosa.const"() <{values = dense<-4.671000e+01> : tensor<2x3xf32>}> : () -> tensor<2x3xf32>
    %1 = tosa.floor %0 : (tensor<2x3xf32>) -> tensor<2x3xf32>
    %2 = tosa.transpose %1 {perms = array<i32: 0, 1>} : (tensor<2x3xf32>) -> tensor<2x3xf32>
    %3 = tosa.add %2, %2 : (tensor<2x3xf32>, tensor<2x3xf32>) -> tensor<2x3xf32>
    %4 = tosa.pow %3, %2 : (tensor<2x3xf32>, tensor<2x3xf32>) -> tensor<2x3xf32>
    %cast = tensor.cast %4 : tensor<2x3xf32> to tensor<*xf32>
    call @printMemrefF32(%cast) : (tensor<*xf32>) -> ()
    return
 }
}
```

### 2. **Command to Run Without `-test-expand-math`:**

```
/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-tensor -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops -lower-affine -convert-scf-to-cf -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-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 `-test-expand-math`:**

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

### 4. **Command to Run With `-test-expand-math`:**

```
/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-tensor -tosa-to-arith -one-shot-bufferize="bufferize-function-boundaries" -convert-linalg-to-affine-loops -lower-affine -convert-scf-to-cf -convert-cf-to-llvm -test-expand-math -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-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 `-test-expand-math`:**

```
[[-nan,   -nan,   -nan], 
 [-nan,   -nan,   -nan]]
```

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_TX0ZUCBHkqWffDBa8fAAglapIceA0oa2SwkUiAp725_fUFJttfZzTZNGqBAAwiSSA3fe_yYZ4_yXh8M0ZpldyzbzVQfjtat36u2sA7TWWGrp_WHJzjoACdyXlsD2gPL7hZCyFIKlu0YLo8hdJ7JDcM9w_1Bh2NfJKVtGe6b5nR-8M7ZP6gMDPelbVsdXyaYLFPpQoqC5LwsZZVmq7IqiuUS06USIi9WDFcJE5t4oWQoYUe-dLoL2ppILDb3oFqg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