<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/128273>128273</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] Inconsistent results when using --affine-loop-invariant-code-motion
</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 @main() -> i32{
%idx0 = index.constant 0
%c821775651_i32 = arith.constant 821775651 : i32
%c-58822_i32 = arith.constant -58822 : i32
%alloc_150 = memref.alloc() : memref<1xi32>
memref.store %c-58822_i32, %alloc_150[%idx0] : memref<1xi32>
affine.for %1 = 0 to 0 {
affine.store %c821775651_i32, %alloc_150[%idx0] : memref<1xi32>
}
%11 = memref.load %alloc_150[%idx0] : memref<1xi32>
vector.print %11 : i32
return %11 : i32
}
}
```
When I ran
```
/data/tmp/v0222/llvm-project/build/bin/mlir-opt \
--lower-affine --convert-scf-to-cf --convert-cf-to-llvm --convert-index-to-llvm --convert-vector-to-llvm --convert-arith-to-llvm --finalize-memref-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v0222/llvm-project/build/bin/mlir-runner --entry-point-result=i32 --shared-libs=/data/tmp/v0222/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v0222/llvm-project/build/lib/libmlir_c_runner_utils.so
```
on the program, I got the result of:
```
-58822
-58822
```
However, when I ran
```
/data/tmp/v0222/llvm-project/build/bin/mlir-opt \
--affine-loop-invariant-code-motion \
--lower-affine --convert-scf-to-cf --convert-cf-to-llvm --convert-index-to-llvm --convert-vector-to-llvm --convert-arith-to-llvm --finalize-memref-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v0222/llvm-project/build/bin/mlir-runner --entry-point-result=i32 --shared-libs=/data/tmp/v0222/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v0222/llvm-project/build/lib/libmlir_c_runner_utils.so
```
on the program, I got the result of:
```
821775651
821775651
```
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 93b2e47f12649bd33b99b88f25beb277a181274a.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsVk-P4yYU_zTk8oSFwY7jgw_ZyUaN1L1UlXocYfvZYYUhApxs-ukr7EzinZlW3al6Wyki-Mf7zw940nvVG8SK5J9IvlvJMRytqy7S9Fdr-q-pXNW2vVYHOMozQjgidFZre1Gmhy-_Hn6Dk7O9kwMRW8K2AX1IBq3c_EnW7PZj28G2o0YgxSfCtgDdaJokDkAyNkhlCN8QXgIl4jMowV_kAAjPVfuNARE7UKbFb0ljjQ_SBGAPkWbD06LI13n6rASfhKVT4fgQvgsAEdvJxUOZ5psN53-nOa--VZNa2-Y5zefYBhwcdskE3pKJGjNMxFP6LSqLzzf9m7gP1uGrGAh_-s583Ju5CCTf_aNR2XXKYNJZFw2kU1wMggUGj4LexR6-vyveB92TYvcoTZoua6KtbD-Y0RmbYF1ycsqEu-HlPjgMozPvLM3x3MYFEf84ooEDOGng1Qrh-1YGSfg-DCfC92fGOSd8r_V5oCdnv2ITCN_Xo9Jt_I-k3Ue2U3sKACR_ImxLqbYXdHSuMVDaWHNGF6hvOhosbboFNkPR_gKcSP4OPpfinYWJrgu8U0Zq9SfSuajvaMSDt4AdNtY0SiMdjcNJt6WN9MHD_UQDKSItPlohNxqDDihFE9yVnqwygTr0ow5E7OLBo9QfpcOWalV7InY_6Eureh6ju-fZ3fMYlPaJt4Q__SdzzRuD3zPHmulqfLkL-RMcoLdhAuckwXZv78T5yC8ny9Vf7AXP6KK1y__E2RfKzmSl2toTVeYsnZIm0Ma2SAcblDU_yf2T3D9I7vub8mq-lPn9iCBrGzuLi70Z8-ARh_ho1QjKxFdY-YAmJHAgvBjA2AB-dAiqizHEiQdprlCP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