[llvm-dev] [RFC] Named shuffle intrinsics
Joe Ellis via llvm-dev
llvm-dev at lists.llvm.org
Tue Nov 24 07:58:12 PST 2020
Hi there,
For fixed-length vectors, shufflevector can represent all possible shuffles. However, shufflevector uses an ArrayRef for its mask, which cannot work for scalable vectors. Splats are an exception to this in that shufflevector can represent scalable vector splats, but they are inconsistent with all other shuffles because the result's element count is taken from the first source vector rather than the mask.
shufflevector could be extended with more support for scalable types, but it is not clear what advantage this has over using explicitly named shuffles.
We are proposing having named shuffle intrinsics under the llvm.vector namespace that work for both fixed-length and scalable vectors. We do not intend to introduce new types of shuffles, and it is our expectation that all intrinsics will simplify to shufflevector when operating on fixed-length vectors.
We would like to start with the following named shuffle intrinsics:
llvm.vector.extract (see below)
llvm.vector.insert (see below)
llvm.vector.reverse (as used by LoopVectorize)
llvm.vector.splice (as used by LoopVectorize)
Our immediate interest here is with the llvm.vector.insert and llvm.vector.extract intrinsics, for which there is a proof of concept on Phabricator[1]. The llvm.vector.insert and llvm.llvm.vector.extract intrinsics are directly lowered to the INSERT_SUBVECTOR and EXTRACT_SUBVECTOR ISD nodes, and have the same semantics. We plan to simplify fixed-length variants of these intrinsics to shufflevector within LLVM IR to maintain existing code paths/optimisations.
We intend to use the llvm.vector.insert and llvm.vector.extract intrinsics to avoid going through memory when generating IR that translates a C/C++ bitcast from scalable vectors to fixed-width vectors, and vice-versa. As an example, see clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c, which shows that these bitcasts are currently done through memory.
Joe
[1]: https://reviews.llvm.org/D91362
More information about the llvm-dev
mailing list