[InstCombine] enhance shuffle-of-binops to allow different variable ops (PR37806)
authorSanjay Patel <spatel@rotateright.com>
Fri, 29 Jun 2018 13:44:06 +0000 (13:44 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 29 Jun 2018 13:44:06 +0000 (13:44 +0000)
commitda66753e0112f667441097e9bfd38dea111cd8df
treed0de1c36c7584259a20ea38cc8861cbf38260a6b
parentf9e1dc002364efe0f06bad68254c8d4f6b08a435
[InstCombine] enhance shuffle-of-binops to allow different variable ops (PR37806)

This was discussed in D48401 as another improvement for:
https://bugs.llvm.org/show_bug.cgi?id=37806

If we have 2 different variable values, then we shuffle (select) those lanes,
shuffle (select) the constants, and then perform the binop. This eliminates a binop.

The new shuffle uses the same shuffle mask as the existing shuffle, so there's no
danger of creating a difficult shuffle.

All of the earlier constraints still apply, but we also check for extra uses to
avoid creating more instructions than we'll remove.

Additionally, we're disallowing the fold for div/rem because that could expose a
UB hole.

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

llvm-svn: 335974
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/test/Transforms/InstCombine/shuffle_select.ll