[X86] Teach method 'isVectorClearMaskLegal' how to check for legal blend masks.
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Wed, 5 Nov 2014 13:04:14 +0000 (13:04 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Wed, 5 Nov 2014 13:04:14 +0000 (13:04 +0000)
commit042bee88f3ab5fec282b6b4e60e8dede9e4c1088
tree6487a95c134d3026b084a5b5ddc3973eeab40f25
parent6b418b297aeaafd12a44a514c771b9030e55113d
[X86] Teach method 'isVectorClearMaskLegal' how to check for legal blend masks.

This patch improves the folding of vector AND nodes into blend operations for
targets that feature SSE4.1. A vector AND node where one of the operands is
a constant build_vector with elements that are either zero or all-ones can be
converted into a blend.

This allows for example to simplify the following code:

define <4 x i32> @test(<4 x i32> %A, <4 x i32> %B) {
  %1 = and <4 x i32> %A, <i32 0, i32 0, i32 0, i32 -1>
  %2 = and <4 x i32> %B, <i32 -1, i32 -1, i32 -1, i32 0>
  %3 = or <4 x i32> %1, %2
  ret <4 x i32> %3
}

Before this patch llc (-mcpu=corei7) generated:
        andps  LCPI1_0(%rip), %xmm0, %xmm0
        andps  LCPI1_1(%rip), %xmm1, %xmm1
        orps   %xmm1, %xmm0, %xmm0
        retq

With this patch we generate a single 'vpblendw'.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221343 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/combine-and.ll [new file with mode: 0644]