[x86] Teach the 128-bit vector shuffle lowering routines to take
authorChandler Carruth <chandlerc@gmail.com>
Mon, 16 Feb 2015 01:52:02 +0000 (01:52 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 16 Feb 2015 01:52:02 +0000 (01:52 +0000)
commit87e580a65982aa79d354cbbc0bcb927e0976e329
tree93a3f698215a5e05831b3d29fe3a64099cde9b17
parentc06b7fbfc3f169a34995bec98034eb19d608d3bb
[x86] Teach the 128-bit vector shuffle lowering routines to take
advantage of the existence of a reasonable blend instruction.

The 256-bit vector shuffle lowering has leveraged the general technique
of decomposed shuffles and blends for quite some time, but this never
made it back into the 128-bit code, and there are a large number of
patterns where this is substantially better. For example, this removes
almost all domain crossing in vector shuffles that involve some blend
and some permutation with SSE4.1 and later. See the massive reduction
in 'shufps' for integer test cases in this commit.

This isn't perfect yet for a few reasons:

1) The v8i16 shuffle lowering continues to plague me. We don't always
   form an unpack-based blend when that would be better. But the wins
   pretty drastically outstrip the losses here.
2) The v16i8 shuffle lowering is just a disaster here. I never went and
   implemented blend support here for some terrible reason. I'll do
   that next probably. I've not updated it for now.

More variations on this technique are coming as well -- we don't
shuffle-into-unpack or shuffle-into-palignr, both of which would also be
profitable.

Note that some test cases grow significantly in the number of
instructions, but I expect to actually be faster. We use
pshufd+pshufd+blendw instead of a single shufps, but the pshufd's are
very likely to pipeline well (two ports on most modern intel chips) and
the blend is a *very* fast instruction. The domain switch penalty will
essentially always be more than a blend instruction, which is the only
increase in tree height.

llvm-svn: 229350
13 files changed:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/SwizzleShuff.ll
llvm/test/CodeGen/X86/avx-trunc.ll
llvm/test/CodeGen/X86/combine-or.ll
llvm/test/CodeGen/X86/masked_memop.ll
llvm/test/CodeGen/X86/sse41.ll
llvm/test/CodeGen/X86/vector-idiv.ll
llvm/test/CodeGen/X86/vector-shuffle-128-v4.ll
llvm/test/CodeGen/X86/vector-shuffle-128-v8.ll
llvm/test/CodeGen/X86/vector-shuffle-256-v16.ll
llvm/test/CodeGen/X86/vector-shuffle-combining.ll
llvm/test/CodeGen/X86/vector-trunc.ll
llvm/test/CodeGen/X86/widen_shuffle-1.ll