-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Description
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.