<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/134516>134516</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir][vector] Error when running `--canonicalize` with out of bounds positions in `vector.extract`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir:vector
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
math-fehr
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
math-fehr
</td>
</tr>
</table>
<pre>
The following code
```
func.func @extract_poison_idx(%arg0: vector<16xf32>) -> f32 {
%x = arith.constant -2 : index
%0 = vector.extract %arg0[%x]: f32 from vector<16xf32>
return %0 : f32
}
```
raises the following error when running `--canonicalize`
```
<source>:3:8: error: 'vector.extract' op expected position attribute #1 to be a non-negative integer smaller than the corresponding vector dimension or poison (-1)
%0 = vector.extract %arg0[%x]: f32 from vector<16xf32>
^
```
This is due to `-1` being the only accepted static position that is out of bounds in a `vector.extract` or `vector.insert`.
There should be two ways to fix this:
* Either we allow out of bounds static positions that are not `-1` (which are also poison).
* Or the `vector.extract` builders should map out of bounds static positions to `-1`.
* Or it is the role of the users to make sure they do not pass non `-1` out of bounds static positions.
I feel both options come with a cost, and would personally prefer solution 1, as it follows LLVM semantics (`extractelement <4 x i32> %vec, i32 -2` is poison as well), and is roughly more modular. I feel solution 3 is exactly why we have this bug in the first place, and would be quite error-prone overall, because it is really easy to miss. Solution 2 is *okay* for me, but I feel following LLVM would make more sense here.
What do you think? I can write the patch, I just want to make sure we agree on a solution first before going into it. It also applies for `vector.insert` and `vector.shuffle` from what I see.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVUuP4rgW_jVmcwQKNoFiwYKuh1RSX93Fbd1ZthznhLjLsTM-NoH59aOThKarVJqZxSAEkXMe3_f5PDSRPXnEgyi_CCk7ndplg20UUoryaaFzakM8_DxeVKG-Hr61CE1wLgzWn8CEGkVxFNti_hbHJnuz4h8QmwIvKWqTvvfBU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