https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88547

            Bug ID: 88547
           Summary: missed optimization for vector comparisons
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rth at gcc dot gnu.org
  Target Milestone: ---

typedef signed svec __attribute__((vector_size(16)));
typedef unsigned uvec __attribute__((vector_size(16)));

svec les(svec x, svec y) {
    return x <= y;
}

uvec leu(uvec x, uvec y) {
    return x <= y;
}

currently assemble to 

les:
        vpcmpgtd  %xmm1, %xmm0, %xmm0
        vpcmpeqd  %xmm1, %xmm1, %xmm1
        vpandn    %xmm1, %xmm0, %xmm0

leu:
        vmovdqa64 .LC0(%rip), %xmm2
        vpsubd    %xmm2, %xmm1, %xmm1
        vpsubd    %xmm2, %xmm0, %xmm0
        vpcmpgtd  %xmm1, %xmm0, %xmm0
        vpcmpeqd  %xmm1, %xmm1, %xmm1
        vpandn    %xmm1, %xmm0, %xmm0

By using the transformation min(x, y) == x we can produce

les:
        vpminsd   %xmm1, %xmm0, %xmm1
        vpcmpeqd  %xmm1, %xmm0, %xmm0

leu:
        vpminud   %xmm1, %xmm0, %xmm1
        vpcmpeqd  %xmm0, %xmm1, %xmm0

This can be used to reduce unsigned comparisons without requiring
the use of a constant bias vector.  At least when the given min insn
is available in the architecture.

Reply via email to