public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/108707] New: suboptimal allocation with same memory op for many different instructions.
@ 2023-02-08  3:11 crazylht at gmail dot com
  2023-02-08  3:15 ` [Bug rtl-optimization/108707] " crazylht at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: crazylht at gmail dot com @ 2023-02-08  3:11 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-11-01  5:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-08  3:11 [Bug rtl-optimization/108707] New: suboptimal allocation with same memory op for many different instructions crazylht at gmail dot com
2023-02-08  3:15 ` [Bug rtl-optimization/108707] " crazylht at gmail dot com
2023-02-09 13:38 ` rguenth at gcc dot gnu.org
2023-03-09  5:58 ` crazylht at gmail dot com
2023-03-09  5:59 ` crazylht at gmail dot com
2023-03-09  5:59 ` crazylht at gmail dot com
2023-03-09  6:00 ` crazylht at gmail dot com
2023-04-23  1:57 ` cvs-commit at gcc dot gnu.org
2023-11-01  5:29 ` crazylht at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).