[llvm-dev] [RFC] Extending shufflevector for vscale vectors (SVE etc.)

Nicolai Hähnle via llvm-dev llvm-dev at lists.llvm.org
Thu Jan 30 00:21:34 PST 2020

Hi Eli,

On Thu, Jan 30, 2020 at 1:48 AM Eli Friedman via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> Proposed IR syntax:
> %result = shufflevector <vscale x 4 x i32> %v1, <vscale x 4 x i32> %v2, SHUFFLE_NAME
> SHUFFLE_NAME can be one of the following (with examples of the equivalent <4 x i32> shuffles):
> splat - Splat element 0 of the first operand. (<0, 0, 0, 0>)
> reverse - Reverse the elements of the first operand (<3, 2, 1, 0>)
> concat - Concatenate the two operands (<0, 1, 2, 3, 4, 5, 6, 7>)
> split_low - Return the low half of the first operand (<0, 1>)
> split_high - Return the high half of the first operand (<2, 3>)
> zip_low - Zip together the low halves of the two operands (<0, 4, 1, 5>)
> zip_high - Zip together the high halves of the two operands (<2, 6, 3, 7>)
> unzip_even - Unzip the even elements of the two operands (<0, 2, 4, 6>)
> unzip_odd - unzip the odd elements of the two operands (<1, 3, 5, 7>)

This fixed list of shuffles makes me uncomfortable, and I wonder if
there isn't a much simpler solution to the problem. Specifically,
allow the IR form:

%result = shufflevector <vscale x n x TY> %v1, <vscale x n x TY> %v2,
<m x i32> <mask>

yielding a result of type <vscale x m x TY>. (The <mask> could still
just be a constant list of integers, i.e. this doesn't require a
relaxation to arbitrary Value* masks.)

I believe that all the shuffle names you listed above could fit into
that scheme, simply by plugging in the mask that you've already
written in that list. In other words, the mask isn't vscale, is still
represent as just a straightforward list of constant, and it is
applied equally to each "vscale part" of the operand vectors. This is
conceptually analogous to how `select` on vectors can have either an
<n x i1> selection operand to operate as a fully vector select, or an
i1 selection operand that is applied equally to each part of the
operand vectors.

Maybe I'm misunderstanding the intended semantics of your list of
shuffles, in which case, please enlighten me :)


Lerne, wie die Welt wirklich ist,
aber vergiss niemals, wie sie sein sollte.

More information about the llvm-dev mailing list