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

            Bug ID: 127849
           Summary: different vectorization of AND reduction for a
                    single-bit set initial value
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: manu at gcc dot gnu.org
  Target Milestone: ---

Split from PR127824.

These two functions should produce the same vectorization, but the version with
unsigned seems worse?

__attribute__((optimize("no-trapping-math")))
bool
weakly_dominates_2(const double * restrict a, const double * restrict b, const
unsigned dim)
{
    unsigned a_leq_b = 1;
    for (unsigned d = 0; d < dim; d++)
        a_leq_b &= (a[d] <= b[d]);
    return (bool) a_leq_b;
}

__attribute__((optimize("no-trapping-math")))
bool
weakly_dominates_1(const double * restrict a, const double * restrict b, const
unsigned dim)
{
    bool a_leq_b = true;
    for (unsigned d = 0; d < dim; d++)
        a_leq_b &= (a[d] <= b[d]);
    return a_leq_b;
}

With -O3 -march=x86-64-v3 -fopt-info-vec,


weakly_dominates_2 produces:

        vmovupd ymm0, YMMWORD PTR [rdi+rax]
        vmovupd ymm1, YMMWORD PTR [rdi+32+rax]
        vcmplepd        ymm0, ymm0, YMMWORD PTR [rsi+rax]
        vcmplepd        ymm1, ymm1, YMMWORD PTR [rsi+32+rax]
        add     rax, 64
        vpand   ymm1, ymm4, ymm1
        vpand   ymm0, ymm4, ymm0
        vperm2i128      ymm2, ymm0, ymm1, 32
        vperm2i128      ymm0, ymm0, ymm1, 49
        vpshufd ymm0, ymm0, 216
        vpshufd ymm1, ymm2, 216
        vpunpcklqdq     ymm0, ymm1, ymm0
        vpand   ymm3, ymm3, ymm0

while weakly_dominates_1 produces:

        vmovupd ymm0, YMMWORD PTR [rdi+rax]
        vcmplepd        ymm0, ymm0, YMMWORD PTR [rsi+rax]
        add     rax, 32
        vpand   ymm1, ymm1, ymm0



See https://godbolt.org/z/rWccjdMvv

Reply via email to