[SelectionDAG][x86] turn insertelement into undef with variable index into splat
authorSanjay Patel <spatel@rotateright.com>
Sun, 26 Aug 2018 18:20:41 +0000 (18:20 +0000)
committerSanjay Patel <spatel@rotateright.com>
Sun, 26 Aug 2018 18:20:41 +0000 (18:20 +0000)
commit113cac3b159214cb6ac28d527075eb1c250bca9f
tree534c32b57423b767e7fa5ab3ed69f0760e861498
parent5fdb81755f28fe69234454ca4b1158862ced56a7
[SelectionDAG][x86] turn insertelement into undef with variable index into splat

I noticed this along with the patterns in D51125, but when the index is variable,
we don't convert insertelement into a build_vector.

For x86, that means these get expanded at legalization time into the loading/spilling
code that we see in the tests. I think it's always better to avoid going to memory on
these, and we get the optimal 'broadcast' if it's available.

I suspect other targets may want to look at enabling the hook. AArch64 and AMDGPU have
regression tests that would be affected (although I did not check what would happen in
those cases). In the most basic cases shown here, AArch64 would probably do much
better with a splat.

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

llvm-svn: 340705
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86ISelLowering.h
llvm/test/CodeGen/X86/insertelement-var-index.ll