Open
Description
At the moment, only -1
is used to "model" poison values - i.e., accesses that produce poison:
%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). - 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:
If idx exceeds the length of val for a fixed-length vector, the result is a poison value
VOICES AGAINST / CONCERNS
We should be mindful of @kuhar’s comment. 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:
- [mlir][vector] Error when running
--canonicalize
with out of bounds positions invector.extract
#134516 - [mlir][vector] Prevent folding of OOB values in insert/extract #135498
- [mlir][vector] Update the folder for vector.{insert|extract} #136579
Also, this issue is to track NEXT STEPS from this comment.