<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/113689>113689</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir] Inconsistent results for vector.create_mask
</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 @func1() -> f32 {
%c1 = arith.constant 1 : i64
// this scf for can not be reduced
%c51_i64 = arith.constant 51 : i64
%true = index.bool.constant true
%70 = scf.if %true -> (i64) {
scf.yield %c51_i64 : i64
} else {
scf.yield %c51_i64 : i64
}
%71 = arith.shli %c1, %70 : i64
// this value can not be a constant
%140 = index.castu %71 : i64 to index // 2251799813685248
// Documentation:
// If operand-value is negative, it is treated as if it were zero,
// and if it is greater than the corresponding dimension size,
// it is treated as if it were equal to the dimension size.
%185 = vector.create_mask %140 : vector<13xi1>
%c0 = arith.constant 0 : i1
%idx13_121 = index.constant 13
%idx0_113 = index.constant 0
%idx1_114 = index.constant 1
%255 = scf.for %arg0 = %idx0_113 to %idx13_121 step %idx1_114 iter_args(%arg1 = %c0) -> (i1) {
%746 = vector.extract %185[%arg0] : i1 from vector<13xi1>
%747 = arith.addi %arg1, %746 : i1
vector.print %746 : i1
scf.yield %747 : i1
}
%256 = arith.sitofp %255 : i1 to f32
return %256 : f32
}
}
```
When I ran ```/data/tmp/v1025/llvm-project/build/bin/mlir-opt --convert-vector-to-llvm --convert-scf-to-cf --convert-arith-to-llvm --convert-index-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts test1.mlir | /data/tmp/v1025/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1025/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1025/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
0
0
0
0
0
0
0
0
0
0
0
0
0
0.000000e+00
```
However, when I ran ```/data/tmp/v1025/llvm-project/build/bin/mlir-opt --canonicalize --convert-vector-to-llvm --convert-scf-to-cf --convert-arith-to-llvm --convert-index-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts test1.mlir | /data/tmp/v1025/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1025/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1025/llvm-project/build/lib/libmlir_c_runner_utils.so``` on the program, I got the result of:
```
1
1
1
1
1
1
1
1
1
1
1
1
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 following commands:
command1:
```
/data/tmp/v1025/llvm-project/build/bin/mlir-opt --convert-vector-to-llvm --convert-index-to-llvm --convert-arith-to-llvm --convert-scf-to-cf --finalize-memref-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts test2.mlir | /data/tmp/v1025/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1025/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1025/llvm-project/build/lib/libmlir_c_runner_utils.so
```
command2:
```
/data/tmp/v1025/llvm-project/build/bin/mlir-opt --convert-index-to-llvm --convert-vector-to-llvm --convert-arith-to-llvm --convert-scf-to-cf --finalize-memref-to-llvm --convert-func-to-llvm --reconcile-unrealized-casts test2.mlir | /data/tmp/v1025/llvm-project/build/bin/mlir-cpu-runner -e func1 --shared-libs=/data/tmp/v1025/llvm-project/build/lib/libmlir_runner_utils.so,/data/tmp/v1025/llvm-project/build/lib/libmlir_c_runner_utils.so
```
test2.mlir:
```
module {
func.func private @func1() -> f32 {
%52 = index.constant -8995940255304650
%174 = vector.create_mask %52 : vector<19xi1>
%idx0_116 = index.constant 0
%idx1_117 = index.constant 1
%false_118 = arith.constant false
%idx19_125 = index.constant 19
%217 = scf.for %arg0 = %idx0_116 to %idx19_125 step %idx1_117 iter_args(%arg1 = %false_118) -> (i1) {
%705 = vector.extract %174[%arg0] : i1 from vector<19xi1>
%706 = arith.addi %arg1, %705 : i1
vector.print %705 : i1
scf.yield %706 : i1
}
%1 = arith.sitofp %217 : i1 to f32
vector.print %217 : i1
return %1 : f32
}
}
```
My git version is 2d26ef09fc87472cd42ea219c8f9267599872958.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWFtv47oR_jX0y0CGSIm6PPghuz5GA_S8FAX6aNDSSOapRLok5Wz21xekFVvyJUl7EKAodrGIEnL4zXBu5EdhrWwV4orwb4SvF2Jwe21WL0K1r1q1f1Cx2On6dfUMe3FEcHuERnedfpGqhd__-vw3OBjdGtGT5InEaxI_ObSOLvtOmvMQyeLxf_iz1_XQIZD82-lvaAZVLf0PIGnsv5SwgrASIpL8Bk3CJrIAQBivKJBkDcJIt19WWlknlAM_-AQyS0e1kxUbwjbg9tKCrRpotIFKKFDawQ7BYD1UWM81cLqVWXpPDb_S48WdGTDISlXjj-VO6-6ywE_OwPM4yNqqWcrmvDzslrDCA7Nysmcv9yqxq-eGTU3wuPkasLM4dxZ8fvXcxKmH7b6TJ7cT9v28gWuEiZOPohtw6mIBb96YaaFpPPFaJawbzsoDPDh9mjzjM8ZpXpYFTbKCs7R4EOu1roYelRNOauXBbiSeG9AHNELV0clcaUFhK5w8ot-mdH7EGRQOaxAWZOPHXtAg_ESjgyuuQYWqRzlpoQ1rDbi9UKF0Km0M2oNWtS-fWvaorNQKrPyJd-HeswH_NYjO-8cjz7GWcycXPDj5iJXTZlkFtG0v7D8vIXgaZ0nynSY_JCXJb7eO5VV8rx7GXKAzUVn_oMmWMjqN77lQk2vZeEtpck80vkHdUpreBZ1JMs7PNebLnTAuTHuyf6rS6bm11uFhpkk6NFthWht6kgehbyBVfG5SvmzpvGrhrZLSbOp-_OGMqNwYGN92T5YRvh79CI3R_aN4TGDzSTBEXctxj-caDXrngYE3Kw5GKjeX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