<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/137147>137147</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir][vector] Update how OOB accesses are handled by vector.extract/vector.insert
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir:vectorops,
mlir:vector
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
banach-space
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
banach-space
</td>
</tr>
</table>
<pre>
At the moment, only `-1` is used to "model" poison values - i.e., accesses that produce poison:
```mlir
%c_neg_1 = arith.constant -1 : index
%0 = vector.insert %value_to_store, %dest[%c_neg_1] : vector<5xf32> into vector<4x5xf32>
%1 = vector.extract %src[%c_neg_1, 0] : f32 from vector<4x5xf32>
```
>From the discussion so far, it seems that:
* We should treat any out-of-bounds (OOB) index — not just `-1` — as producing a poison value (see [@dcaballe’s supportive comment](https://github.com/llvm/llvm-project/issues/134516#issuecomment-2789687910)).
* We should allow using `%poison = ub.poison : index` directly as an index that generates poison.
This direction would bring the dialect more in line with LLVM semantics. From [LLVM LangRef](https://llvm.org/docs/LangRef.html#id184):
> If idx exceeds the length of val for a fixed-length vector, the result is a [poison value](https://llvm.org/docs/LangRef.html#poisonvalues)
**VOICES AGAINST / CONCERNS**
We should be mindful of [@kuhar’s comment](https://github.com/llvm/llvm-project/issues/134516#issuecomment-2781890324). While not opposed to the proposed direction:
> If others would prefer consistency with the LLVM instructions, I won't object.
... we should keep him in the loop and ensure any concerns he raises are addressed.
**PRIOR DISCUSSION**
Relevant context and discussion can be found in:
* https://github.com/llvm/llvm-project/issues/134516
* https://github.com/llvm/llvm-project/pull/135498
* https://github.com/llvm/llvm-project/pull/136579
Also, this issue is to track **NEXT STEPS** from this [comment](https://github.com/llvm/llvm-project/pull/136579#issuecomment-2821065107).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0Vl1vozgU_TXOy1UQGAjhIQ9p2qwizTaj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