https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119040
--- Comment #6 from Segher Boessenkool <segher at gcc dot gnu.org> ---
(In reply to Jeevitha from comment #5)
> To handle this situation, we could introduce a split pattern that checks
> whether the two vector values have non-overlapping bits and, if so, rewrites
> the operation into a single vsel. I am preparing a patch based on this
> approach like below, Is this fine?
>
> (define_insn_and_split "new_merge_pattern"
> [(set (match_operand:VM 0 "register_operand" "=wa,v")
> (ior:VM
> (and:VM (match_operand:VM 1 "register_operand" "wa,v") ;; a
> (match_operand:VM 2 "register_operand" "wa,v")) ;; mask1
> (and:VM (match_operand:VM 3 "register_operand" "wa,v") ;; b
> (match_operand:VM 4 "register_operand" "wa,v"))))] ;; mask2
> "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)
> && rs6000_vector_masks_overlap_p (operands[2], operands[4])" /* ensure
> operand 2 and 4 has non overlapping bits */
> "#"
> {
> /* emit vsel here */
> DONE;
> })
Please don't say things in comments that the code already says.
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 :-)