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

            Bug ID: 108707
           Summary: suboptimal allocation with same memory op for many
                    different instructions.
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: crazylht at gmail dot com
  Target Milestone: ---

#include<immintrin.h>

void
foo (__m512* pv, float* __restrict ps, int n, __m512* pdest,
__m512* p1, __m512* p2, __m512* p3)
{
    __m512 a = _mm512_setzero_ps ();
    __m512 b = a;
    __m512 c = a;
    for (int i = 0; i != n ;i++)
    {
        a = _mm512_fmadd_ps (p1[i], pv[i], a);
        b = _mm512_fmadd_ps (p2[i], pv[i], b);
        c = _mm512_fmadd_ps (p3[i], pv[i], c);
    }
    pdest[0] = a;
    pdest[1] = b;
    pdest[2] = c;
}

g++ -O2 -mavx512f -S

got 

.L3:
        vmovaps (%r8,%rax), %zmm3
        vmovaps (%r9,%rax), %zmm4
        vmovaps (%rsi,%rax), %zmm5
        vfmadd231ps     (%rdi,%rax), %zmm3, %zmm2
        vfmadd231ps     (%rdi,%rax), %zmm4, %zmm1
        vfmadd231ps     (%rdi,%rax), %zmm5, %zmm0
        addq    $64, %rax
        cmpq    %rax, %rdx
        jne     .L3

It would be better to load (%rdi, %rax) into a zmm then

.L3:
        vmovaps (%rdi,%rax), %zmm0
        vfmadd231ps     (%r8,%rax), %zmm0, %zmm3
        vfmadd231ps     (%r9,%rax), %zmm0, %zmm2
        vfmadd231ps     (%rsi,%rax), %zmm0, %zmm1
        addq    $64, %rax
        cmpq    %rax, %rdx
        jne     .L3

Reply via email to