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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] Inconsistent results for linalg.map and linalg.generic
        </td>
    </tr>

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

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

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

<pre>
    I have the following MLIR program:
test1.mlir:
```
module {
 func.func nested @func1() -> f32 {
    %c1 = arith.constant 1 : index
 %alloc = memref.alloc() : memref<24xi32>
    %0 = arith.constant 1 : i32
    memref.store %0, %alloc[%c1] : memref<24xi32>
    %false_22 = arith.constant false
    %splat_23 = tensor.splat %false_22 : tensor<13x13x1xi1>
    %splat_86 = tensor.splat %false_22 : tensor<13x13x1xi1>
    %mapped = linalg.map ins(%splat_23, %splat_23 : tensor<13x13x1xi1>, tensor<13x13x1xi1>) outs(%splat_86 : tensor<13x13x1xi1>)
      (%in: i1, %in_97: i1) {
        %false_106 = arith.constant false
        %2 = arith.constant 10 : i32
 memref.store %2, %alloc[%c1] : memref<24xi32>
        linalg.yield %false_106 : i1
      }
    %1 = memref.load %alloc[%c1] : memref<24xi32>

    %111 = arith.sitofp %1 :i32 to f32
 vector.print %1 : i32
    return %111 : f32
  }
}
```
When I ran ```/data/tmp/v1018/llvm-project/build/bin/mlir-opt --one-shot-bufferize="dialect-filter=tensor,linalg,bufferization" --expand-strided-metadata --func-bufferize --convert-linalg-to-loops --one-shot-bufferize="dialect-filter=arith" --convert-arith-to-llvm --lower-affine --finalize-memref-to-llvm --convert-index-to-llvm --convert-scf-to-cf --convert-func-to-llvm --convert-vector-to-llvm --convert-arith-to-llvm --reconcile-unrealized-casts test1.mlir | /data/tmp/v1018/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1018/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1018/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
10
1.000000e+01
```
However, when I ran ```/data/tmp/v1018/llvm-project/build/bin/mlir-opt --linalg-named-op-conversion --one-shot-bufferize="dialect-filter=tensor,linalg,bufferization" --expand-strided-metadata --func-bufferize --convert-linalg-to-loops --one-shot-bufferize="dialect-filter=arith" --convert-arith-to-llvm --lower-affine --finalize-memref-to-llvm --convert-index-to-llvm --convert-scf-to-cf --convert-func-to-llvm --convert-vector-to-llvm --convert-arith-to-llvm --reconcile-unrealized-casts test1.mlir | /data/tmp/v1018/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1018/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1018/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
1
1.000000e+00
```

The above two results seem to be inconsistent. I'm not sure if there is any bug in my program or if the wrong usage of the above passes caused these results.
Besides, the following MLIR program test2.mlir will cause similar inconsistent results using the same commands:
test2.mlir:
```
module {
  func.func private @func1() -> f32 {
    %c1 = arith.constant 1 : index
    %alloc = memref.alloc() : memref<24xi32>
    %0 = arith.constant 1 : i32
 memref.store %0, %alloc[%c1] : memref<24xi32>
    %c-22846_i32 = arith.constant -22846 : i32
    %from_elements_108 = tensor.splat %c-22846_i32 : tensor<3xi32>
    %from_elements_110 = tensor.splat %c-22846_i32 : tensor<3xi32>
    %215 = linalg.generic {indexing_maps = [affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>], iterator_types = ["parallel"]} ins(%from_elements_108 : tensor<3xi32>) outs(%from_elements_110 : tensor<3xi32>) {
    ^bb0(%in: i32, %out: i32):
      memref.store %in, %alloc[%c1] : memref<24xi32>
 linalg.yield %in : i32
    } -> tensor<3xi32>
    %1 = memref.load %alloc[%c1] : memref<24xi32>

    %111 = arith.sitofp %1 :i32 to f32
    vector.print %1 : i32
    return %111 : f32
 }
}
```
My git version is 18ac0178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