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

            Bug ID: 78664
           Summary: LRA must honor REG_ALLOC_ORDER to pick reload
                    registers
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ebotcazou at gcc dot gnu.org
  Target Milestone: ---

The SPARC port uses REG_ALLOC_ORDER to force the use of leaf registers in leaf
functions, which in turn enables the leaf function optimization.  For example:

long long *a, *b;

long long add (void)
{
  return *a + *b;
}

The generated code at -O2 (reload) is:

        sethi   %hi(a), %g1
        ld      [%g1+%lo(a)], %g2
        ldd     [%g2], %o0
        sethi   %hi(b), %g1
        ld      [%g1+%lo(b)], %g1
        ldd     [%g1], %g2
        addcc   %o1, %g3, %o5
        addx    %o0, %g2, %o4
        mov     %o5, %o1
        jmp     %o7+8
         mov    %o4, %o0

while at -O2 -mlra (LRA) it is:

        save    %sp, -96, %sp
        sethi   %hi(a), %g1
        ld      [%g1+%lo(a)], %g2
        ldd     [%g2], %i0
        sethi   %hi(b), %g1
        ld      [%g1+%lo(b)], %g1
        ldd     [%g1], %g2
        addcc   %i1, %g3, %o5
        addx    %i0, %g2, %o4
        mov     %o5, %i1
        jmp     %i7+8
         restore %g0, %o4, %o0

The additional save/restore pair means that LRA didn't pick leaf registers for
reload registers, as prescribed by the REG_ALLOC_ORDER for leaf functions.

Reply via email to