[Bug tree-optimization/126403] New: missed optimization: vectorization of simple loop

"uecker at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.