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

            Bug ID: 90554
           Summary: Missed vectorization with conditionally defined the
                    end of the loop
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david.bolvansky at gmail dot com
  Target Milestone: ---

int vectorize(int b, unsigned *x, unsigned *y, int N, int NN)
{
    int sum = 0;
    int end = b ? N : NN;
    unsigned *p = b ? x : y;
    for(int i = 0; i < end; ++i) {
         sum += p[i];
    }
    return sum;
}

Trunk -O3
vectorize:
        test    edi, edi
        cmovne  r8d, ecx
        cmovne  rdx, rsi
        test    r8d, r8d
        jle     .L5
        lea     eax, [r8-1]
        lea     rcx, [rdx+4+rax*4]
        xor     eax, eax
.L4:
        add     eax, DWORD PTR [rdx]
        add     rdx, 4
        cmp     rcx, rdx
        jne     .L4
        ret
.L5:
        xor     eax, eax
        ret


ICC or Clang vectorizes this code.

Reply via email to