<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/116664>116664</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] Inconsistent results for affine.for and memref.store
</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:
test.mlir:
```
module {
func.func private @func1() -> f32{
%idx0 = index.constant 0
%c21848_i16 = arith.constant 21848 : i16
%c1 = arith.constant 1 : index
%c5 = arith.constant 5 : index
%alloc_107 = memref.alloc(%c5, %c1) : memref<?x?x1xi16>
%c-58_i16 = arith.constant -58 : i16
linalg.fill ins(%c-58_i16 : i16) outs(%alloc_107 : memref<?x?x1xi16>)
affine.for %arg0 = 0 to 61 {
memref.store %c21848_i16, %alloc_107[%idx0, %idx0, %idx0] : memref<?x?x1xi16>
}
%1 = memref.load %alloc_107[%idx0, %idx0, %idx0] : memref<?x?x1xi16>
vector.print %1 : i16
%2 = arith.sitofp %1 : i16 to f32
return %2 : f32
}
}
```
When I ran ```/data/tmp/v1118/llvm-project/build/bin/mlir-opt --affine-loop-tile="tile-size=32" --affine-loop-normalize --lower-affine --convert-vector-to-llvm --convert-arith-to-llvm --convert-linalg-to-loops --convert-arith-to-llvm --convert-scf-to-cf --convert-arith-to-llvm --convert-index-to-llvm --finalize-memref-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1118/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1118/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1118/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
21848
2.184800e+04
```
However, when I ran ```/data/tmp/v1118/llvm-project/build/bin/mlir-opt --affine-loop-tile="tile-size=32" --affine-loop-normalize --lower-affine --test-vector-sink-patterns --scf-for-loop-range-folding --convert-vector-to-llvm --convert-arith-to-llvm --convert-linalg-to-loops --convert-arith-to-llvm --convert-scf-to-cf --convert-arith-to-llvm --convert-index-to-llvm --finalize-memref-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1118/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1118/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1118/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
-58
-5.800000e+01
```
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.
My git version is c25c6c32494c8d1038438b6208d42ba40f25270e.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV0uP2zYQ_jX0ZUBBpB62Dz4k6xg10FyKAj0uKGkkM6VIgaTs3fz6gpT8yjrFtkEPBbLY9ZLDbx7kfEOOhXOy04gbUnwkxXYhRn8wdnMSuns1uvvCxKIyzetmDwdxRPAHhNYoZU5Sd_D51_1vMFjTWdGT7ANJtyT94NH5pFfSXiSkTOffOO1NMyoEsvw4zaEddZ2EDxisPAqPQPI0zBnhK8LXQEn2CdqMX1UAgPBCNi8pkGwLUjf4ktRGOy-0h9lRgNScrfLVs2RlBAor_eEKjItAsg8gWXlnumaP8GzCBm_36OIRuniDvlMSSpn6maXLqNtjb7FNojBuu6gLwp-mWMIhBFsTiGRPJNu9hD_2EgLPPt1HQ4vv7pgWD_arpBaqS1qpFEjtZvdXKxOcr8GMfl69Df7v4uLrqxvRtlJj0hobt2-7KXkpeAMlg7vswvlAnDcW7zM5H8slhEDdiQzzyrfDYvvu01tur9xht4lRRjT_hder7yPW3thksFL7s_u3xOQ3WXXSm3a4w4azDJVyUbHoR6snzQi6Wb3s9jq4L9U_DqhhD1ZouK7wXSO8IHzn-4Hw3ZExtiJ8p9Sxp4M1X7D2hO-qUaom_Jea8F24D6gZPFA6sYAqYwbqpUKSbQnnYUS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