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

            Bug ID: 126403
           Summary: missed optimization: vectorization of simple loop
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: uecker at gcc dot gnu.org
  Target Milestone: ---

I am not sure whether this is covered by one of the existing bugs, but 


typedef struct { float values[4]; } v4;

v4 mul(v4 a, v4 b)
{
    v4 r;
    for (int i = 0; i < 4; i++)
        r.values[i] = a.values[i] * b.values[i];
    return r;
}

is optimized by clang to

mul:
        mulps   xmm0, xmm2
        mulps   xmm1, xmm3
        ret

while GCC generates

"mul":
        movaps  XMMWORD PTR [rsp-24], xmm4
        mov     rdx, QWORD PTR [rsp-16]
        movq    QWORD PTR [rsp-24], xmm0
        mov     QWORD PTR [rsp-16], rdx
        movdqa  xmm4, XMMWORD PTR [rsp-24]
        movaps  XMMWORD PTR [rsp-24], xmm5
        mov     rdx, QWORD PTR [rsp-16]
        movq    QWORD PTR [rsp-24], xmm2
        punpcklqdq      xmm4, xmm1
        mov     QWORD PTR [rsp-16], rdx
        movdqa  xmm5, XMMWORD PTR [rsp-24]
        movaps  xmm6, xmm4
        punpcklqdq      xmm5, xmm3
        mulps   xmm6, xmm5
        movaps  XMMWORD PTR [rsp-24], xmm6
        movq    xmm1, QWORD PTR [rsp-16]
        movq    xmm0, QWORD PTR [rsp-24]
        ret

Reply via email to