[X86][SSE] Add general memory folding for (V)INSERTPS instruction
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 4 Nov 2015 20:48:09 +0000 (20:48 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 4 Nov 2015 20:48:09 +0000 (20:48 +0000)
commit0a019f716257784959b9f05bcd31547194be79a6
tree7bbb33befb635e1ecc019e6c8a86e5804bfdb6c1
parentd13e995447c3a68104cd0f11ef66342c651e4c03
[X86][SSE] Add general memory folding for (V)INSERTPS instruction

This patch improves the memory folding of the inserted float element for the (V)INSERTPS instruction.

The existing implementation occurs in the DAGCombiner and relies on the narrowing of a whole vector load into a scalar load (and then converted into a vector) to (hopefully) allow folding to occur later on. Not only has this proven problematic for debug builds, it also prevents other memory folds (notably stack reloads) from happening.

This patch removes the old implementation and moves the folding code to the X86 foldMemoryOperand handler. A new private 'special case' function - foldMemoryOperandCustom - has been added to deal with memory folding of instructions that can't just use the lookup tables - (V)INSERTPS is the first of several that could be done.

It also tweaks the memory operand folding code with an additional pointer offset that allows existing memory addresses to be modified, in this case to convert the vector address to the explicit address of the scalar element that will be inserted.

Unlike the previous implementation we now set the insertion source index to zero, although this is ignored for the (V)INSERTPSrm version, anything that relied on shuffle decodes (such as unfolding of insertps loads) was incorrectly calculating the source address - I've added a test for this at insertps-unfold-load-bug.ll

Differential Revision: http://reviews.llvm.org/D13988

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252074 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86InstrInfo.cpp
lib/Target/X86/X86InstrInfo.h
test/CodeGen/X86/avx.ll
test/CodeGen/X86/insertps-unfold-load-bug.ll [new file with mode: 0644]
test/CodeGen/X86/sse41.ll
test/CodeGen/X86/stack-folding-fp-avx1.ll
test/CodeGen/X86/stack-folding-fp-sse42.ll