[X86] Improve the selection of SSE3/AVX addsub instructions.
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Thu, 26 Jun 2014 10:45:21 +0000 (10:45 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Thu, 26 Jun 2014 10:45:21 +0000 (10:45 +0000)
commit817812f61caa50ba3ce67ceb5a033cb69a3eea5c
tree3246ef4217ca3ed21a10573b856cc18a085035d4
parentc2b11baf5fdb26c2bf2c9b02dae9f0f0f61e9f1b
[X86] Improve the selection of SSE3/AVX addsub instructions.

This patch teaches the backend how to canonicalize a shuffle vectors
according to the rule:

 - (shuffle (FADD A, B), (FSUB A, B), Mask) ->
       (shuffle (FSUB A, -B), (FADD A, -B), Mask)

Where 'Mask' is:
  <0,5,2,7>            ;; for v4f32 and v4f64 shuffles.
  <0,3>                ;; for v2f64 shuffles.
  <0,9,2,11,4,13,6,15> ;; for v8f32 shuffles.

In general, ISel only knows how to pattern-match a canonical
'fadd + fsub + blendi' dag node sequence into an ADDSUB instruction.

This new rule allows to convert a non-canonical dag sequence into a
canonical one that will be matched by a single ADDSUB at ISel stage.

The idea of converting a non-canonical ADDSUB into a canonical one by
swapping the first two operands of the shuffle, and then negating the
second operand of the FADD and FSUB, was originally proposed by Hal Finkel.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211771 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/sse3-avx-addsub.ll