This patch generates correct vector when visiting AND and OR SDNodes in DAGCombiner. When a BuildVectore SDNode which is one of the operands of AND/OR SDNOdes is checked to be all zero/ones, it just return this SDNode. But in this SDNode there may be some undef elements. These undef elements should be replaced with real ZEROS/ONES, because the undef elements have been regard as ZEROS/ONES in ISD::isBuildVectorAllZeros()/ISD::isBuildVectorAllOnes() function.
If these undef elements are not replaced, It will cause some bugs. For example,
define <8 x i16> @aarch64_tree_tests_and(<8 x i16> %a) {
entry:
%and = and <8 x i16> <i16 0, i16 undef, i16 undef, i16 0, i16 0, i16 undef, i16 undef, i16 0>, %a %ret = add <8 x i16> %and, <i16 -32768, i16 32767, i16 4664, i16 32767, i16 -32768, i16 -32768, i16 0, i16 0> ret <8 x i16> %ret
}
After visitAND,
%and = <8 x i16> <i16 0, i16 undef, i16 undef, i16 0, i16 0, i16 undef, i16 undef, i16 0>
%ret = <8 x i16> <i16 -32768, i16 undef, i16 undef, i16 32767, i16 -32768, i16 undef, i16 undef, i16 0>
The undef elements in %ret are regard as ZEROS in the end, but it should be i16 32767, i16 4664, i16 -32768 and i16 0.
This bug is found in the emperor test. This bug indicates that we should not deal with AND/OR and ADD/SUB in the same way, because visitAND/visitOR returns the AllZEROS/ONES SDNodes, while visitADD/visitSUB returns the other SDNodes.