[InstCombine] eliminate commuted select-shuffles + binop (PR41304)
authorSanjay Patel <spatel@rotateright.com>
Mon, 1 Apr 2019 13:36:40 +0000 (13:36 +0000)
committerSanjay Patel <spatel@rotateright.com>
Mon, 1 Apr 2019 13:36:40 +0000 (13:36 +0000)
commit97d1bc44544f27f7e8175588e24394ab68c5d521
tree46fb9da4f9ce3d9d243ac974349ee9e18877f27b
parentd9f6ee1c3cc6ae58ef28fbb176739aad4b4644fb
[InstCombine] eliminate commuted select-shuffles + binop (PR41304)

If we have a commutable vector binop with inverted select-shuffles,
we don't care about the order of the operands in each vector lane:

LHS = shuffle V1, V2, <0, 5, 6, 3>
RHS = shuffle V2, V1, <0, 5, 6, 3>
LHS + RHS --> <V1[0]+V2[0], V2[1]+V1[1], V2[2]+V1[2], V1[3]+V2[3]> --> V1 + V2

PR41304:
https://bugs.llvm.org/show_bug.cgi?id=41304
...is currently titled as an SLP enhancement, but at least for the
given example, we can reduce that in instcombine because we are just
eliminating shuffles.

As noted in the TODO, this could be generalized, but I haven't thought
through those patterns completely, so this is limited to what appears
to be always safe.

Differential Revision: https://reviews.llvm.org/D60048

llvm-svn: 357382
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/vec-binop-select.ll