http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54525

             Bug #: 54525
           Summary: Recognize (vec_)cond_expr in mask operation
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: gli...@gcc.gnu.org


Hello,

it would be nice to recognize cond_expr and vec_cond_expr in (a&mask)|(b&~mask)
where mask is (a vector of) 0 or -1. It would be particularly useful for
vectors, for which we don't have any explicit way (yet?) to ask for a
vec_cond_expr.

unsigned f(unsigned x,unsigned y,_Bool b){
  unsigned m=b?-1:0;
  return (x&m)|(y&~m);
}
unsigned g(unsigned x,unsigned y,_Bool b){
  return b?x:y;
}

typedef long vec __attribute__((vector_size(16)));
vec h(vec x, vec y, vec z, vec t){
  vec m=(z<t);
  return (x&m)|(y&~m);
}

compiled on x86_64 with -Ofast -mavx2, gives for f:

    movzbl    %dl, %edx
    negl    %edx
    movl    %edx, %eax
    andl    %edx, %edi
    notl    %eax
    andl    %esi, %eax
    orl    %edi, %eax

for g:

    movl    %edi, %eax
    testb    %dl, %dl
    cmove    %esi, %eax

and for h:

    vpcmpgtq    %xmm2, %xmm3, %xmm2
    vpcmpeqd    %xmm3, %xmm3, %xmm3
    vpxor    %xmm3, %xmm2, %xmm3
    vpand    %xmm0, %xmm2, %xmm2
    vpand    %xmm1, %xmm3, %xmm1
    vpor    %xmm2, %xmm1, %xmm0

(also notice that for some reason all comparisons (I tried < <= > >= and even
with a ~ in front) generate a combination of gt and eq, never just gt)

while avx has vpblendvb.

Reply via email to