[VectorCombine] Attempt to fold select shuffles from reductions
authorDavid Green <david.green@arm.com>
Sun, 8 May 2022 09:32:41 +0000 (10:32 +0100)
committerDavid Green <david.green@arm.com>
Sun, 8 May 2022 09:32:41 +0000 (10:32 +0100)
commit6f9e1ea0efb93388c9301e672b7a73e8216ffa44
tree63ab556b01a21ff71854eeab4c5291a743b8b8c8
parentf2b16488129ef408e89c900f61dc53b1a6699c45
[VectorCombine] Attempt to fold select shuffles from reductions

Given a commutative reduction leading from a shuffle, the order of the
lanes on the shuffle are not important for the result. This means we can
reorder the shuffle to something simpler, which we try shuffling the
first vector lanes first. This was D123494.

The new shuffle may not be profitable though, and if it is not we can
try the folding of select shuffles from D123911. This, with some
adjustment as the output lane ordering is now unimportant, can allow the
final shuffle to simplify given the inputs to the patterns from D123911.
Where as each transformation on their own are not profitable, the
combination is.

We can only support a single shuffle when called from reductions, but we
are able to sort the ReconstructMask, potentially allowing it to
simplify to an identity or concat mask.

Differential Revision: https://reviews.llvm.org/D125086
llvm/lib/Transforms/Vectorize/VectorCombine.cpp
llvm/test/Transforms/VectorCombine/AArch64/select-shuffle.ll