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

            Bug ID: 129055
           Summary: [rs6000-power10] Missing optimization opportunity
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kishan at gcc dot gnu.org
                CC: jskumari at gcc dot gnu.org, meissner at gcc dot gnu.org
  Target Milestone: ---
            Target: power*-linux-gnu

For Power10 testcase below, gcc generates at -O3

#include <altivec.h>

typedef vector unsigned char vec_t;

void
foo (__vector_quad *dst, vec_t *a, vec_t *b)
{
  __vector_quad z, d0, d1;
  __builtin_mma_xxsetaccz (&z);
  d0 = z;
  d1 = z;
  __builtin_mma_xvbf16ger2pp (&d0, a[0], b[0]);
  __builtin_mma_xvbf16ger2pp (&d1, a[1], b[1]);
  dst[0] = d0;
  dst[1] = d1;
}

foo:
        xxsetaccz 0
        xxmfacc 0
        lxv %vs45,0(%r4)
        lxv %vs44,0(%r5)
        lxv %vs32,16(%r4)
        lxv %vs33,16(%r5)
        xxlor %vs11,%vs3,%vs3
        xxlor %vs10,%vs2,%vs2
        xxlor %vs9,%vs1,%vs1
        xxlor %vs8,%vs0,%vs0
        xvbf16ger2pp 0,%vs32,%vs33
        xxmtacc 2
        xxmfacc 0
        xvbf16ger2pp 2,%vs45,%vs44
        xxmfacc 2
        etc...

Whereas clang generates at -O3,
foo:
        lxv %vs8, 0(%r4)
        lxv %vs9, 0(%r5)
        xxsetaccz acc1
        xxsetaccz acc0
        xvbf16ger2pp acc1, %vs8, %vs9
        lxv %vs8, 16(%r4)
        lxv %vs9, 16(%r5)
        xvbf16ger2pp acc0, %vs8, %vs9
        xxmfacc acc1
        xxmfacc acc0

GCC appears to be copying the four VSX registers to initialize the second
accumulator. If the intention is to ensure that the other accumulator is also
zero-initialized, GCC should be able to emit a single xxsetaccz instruction
instead of generating four xxlor instructions to copy the VSX registers.

Reply via email to