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

            Bug ID: 69027
           Summary: SPARC: Missing optimization for fall through functions
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sebastian.hu...@embedded-brains.de
  Target Milestone: ---

Consider the following test case:

int i(void);

int f(void)
{
        return i();
}

int g(int (*j)(void))
{
        return (*j)();
}

GCC generates on SPARC something like this:

sparc-rtems4.12-gcc -O2 -S fallthrough.c && cat fallthrough.s
        .file   "fallthrough.c"
        .section        ".text"
        .align 4
        .global f
        .type   f, #function
        .proc   04
f:
        or      %o7, %g0, %g1
        call    i, 0
         or     %g1, %g0, %o7
        .size   f, .-f
        .align 4
        .global g
        .type   g, #function
        .proc   04
g:
        save    %sp, -96, %sp
        call    %i0, 0
         nop
        jmp     %i7+8
         restore %g0, %o0, %o0
        .size   g, .-g
        .ident  "GCC: (GNU) 6.0.0 20151221 (experimental)

For g() an superfluous stack frame is generated.

On PowerPC for example this is optimized to:
        .file   "fallthrough.c"
        .machine ppc
        .section        ".text"
        .align 2
        .globl f
        .type   f, @function
f:
        b i
        .size   f, .-f
        .align 2
        .globl g
        .type   g, @function
g:
        mtctr 3
        bctr
        .size   g, .-g
        .ident  "GCC: (GNU) 6.0.0 20151126 (experimental)

Reply via email to