Hi everyone,
TL;DR: I’m thinking about making a few cleanup changes to the Vector dialect and thought that removing the legacy vector.extractelement
and vector.insertelement
operations in favor of their bigger siblings vector.extract
and vector.insert
would be a good start. If we agree on this, this post will serve as an initial PSA of the change. Please let me know what you think! Collaboration on this work is more than welcome!
Background
Currently, we have two operations for extracting elements from a vector value: vector.extractelement
and vector.extract
. vector.extractelement
was introduced in early stages of MLIR as a carbon copy of the LLVM extractelement
instruction. This operation can only extract scalar elements from a 1-D or 0-D vector. Some time later, the Vector dialect evolved towards n-D vectors and vector.extractelement
was introduced to model scalar and sub-vector extractions from an n-D vector. To some extent, vector.extract
is a superset of vector.extractelement
, although the former currently does not support extractions from 0-D vectors. The same applies to the vector.insertelement
and vector.insert
operations.
Proposal
I propose that we add support for 0-D vectors to vector.extract
and vector.insert
and remove vector.extractelement
and vector.insertelement
. The replacement of vector.extractelement/insertelement
’s uses would be mechanical once vector.extract/insert
support 0-D vectors.
This change will improve the Vector dialect by:
- Removing ambiguity from the vector representation when it comes to extracting elements from a vector value.
- Removing redundant patterns/transformations currently implemented for both
vector.extract/insert
andvector.extractelement/insertelement
. - Filling implementation gaps in patterns/transformations where only one of the operation flavors is supported.
Action Plan
- Introduce 0-D support in
vector.extract/insert
ops. - Fill any implementation gap in
vector.extract/insert
ops. Make sure that all thevector.extractelement/insertelement
patterns and transformations are also supported forvector.extract/insert
. - Remove
vector.extractelement/insertelement
from upstream except for the ops themselves. Send another PSA with the imminent removal of the ops. We can add warnings to the ops’ builders for downstream users, if necessary. - Remove
vector.extractelement/insertelement
operations.
Please let me know if you have any concerns or feedback! This is also a call for collaboration on this work. I’ll definitely need help!
Thanks,
Diego
cc: @nicolasvasilache, @aartbik, @ThomasRaoux, @banach-space, @javiersetoain