https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119040
--- Comment #7 from Jeevitha <jeevitha at gcc dot gnu.org> ---
(In reply to Segher Boessenkool from comment #6)
> Not only do mask1 and mask have to be non-overlapping, they have to be each
> other's complement, even. A select instruction takes every bit out of one
> of the two operands, always. If both inputs have that bit a zero always, it
> does not matter whether we pick 0 or 1 for the mask there, but we still have
> to pick one of the two :-)
Right, I'm checking whether the two constant vectors are exact bitwise
complements of each other.
For each lane, I verify the complement property as follows:
for (int i = 0; i < CONST_VECTOR_NUNITS (op3); i++)
{
HOST_WIDE_INT v3 = INTVAL (CONST_VECTOR_ELT (op3, i));
HOST_WIDE_INT v4 = INTVAL (CONST_VECTOR_ELT (op4, i));
if ((v3 ^ v4) != -1)
return false;
}
If all lanes satisfy (v3 ^ v4) == -1, then the two masks are perfect
complements.
This ensures there are no overlapping bits and that each bit position cleanly
selects either operand a or operand b, which is a requirement for forming a
valid vsel.
Is this fine?