<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/114654>114654</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] Inconsistent results for affine.apply
</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:
```
#map2 = affine_map<(d0, d1) -> (((d1 - (d1 + 2)) floordiv 8) mod 8)>
module {
func.func nested @func1() -> f32 {
%idx1 = arith.constant 1 : index
%res2 = affine.apply #map2(%idx1, %idx1)
vector.print %res2 : index
%0 = arith.index_cast %res2 : index to i64
%1 = arith.sitofp %0 : i64 to f32
return %1 : f32
}
}
```
When I ran ```/data/tmp/v1102/llvm-project/build/bin/mlir-opt --lower-affine --convert-arith-to-llvm --convert-vector-to-llvm --convert-func-to-llvm --convert-index-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1102/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1102/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1102/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
7
7.000000e+00
```
However, when I ran ```/data/tmp/v1102/llvm-project/build/bin/mlir-opt --affine-simplify-structures --lower-affine --convert-arith-to-llvm --convert-vector-to-llvm --convert-func-to-llvm --convert-index-to-llvm --reconcile-unrealized-casts test.mlir | /data/tmp/v1102/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1102/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1102/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
8
8.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.
My git version is 33bdb53d864e3e244d8fd5649062f17b7d4c958d.
</p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