[DAGCombiner] Fix wrong folding of AND dag nodes.
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Sat, 7 Mar 2015 12:24:55 +0000 (12:24 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Sat, 7 Mar 2015 12:24:55 +0000 (12:24 +0000)
commit15d2c3fb00757119263b8ad39a29af26c056f228
treefd8040e5674a9afa154256e3bdb3d243f855cce2
parent5c12640642a110e8eb7c75060de80e4353c9287d
[DAGCombiner] Fix wrong folding of AND dag nodes.

This patch fixes the logic in the DAGCombiner that folds an AND node according
to rule: (and (X (load V)), C) -> (X (load V))

An AND between a vector load 'X' and a constant build_vector 'C' can be folded
into the load itself only if we can prove that the AND operation is redundant.
The algorithm implemented by 'visitAND' firstly computes the splat value 'S'
from C, and then checks if S has the lower 'B' bits set (where B is the size in
bits of the vector element type). The algorithm takes into account also the
'undef' bits in the splat mask.

Unfortunately, the algorithm only worked under the assumption that the size of S
is a multiple of the vector element type. With this patch, we conservatively
avoid folding the AND if the splat bits are not compatible with the vector
element type.

Added X86 test and-load-fold.ll

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

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