Skip to content

musttail doesn't optimize sibling calls #147813

@brandtbucher

Description

@brandtbucher

For example, this code:

int bar(int);

int
foo_tail(int x)
{
    // Correct, compiles to a single jmp:
    return bar(x);
}

int
foo_musttail(int x)
{
    // Buggy, loads and re-spills all parameters:
    __attribute__((musttail)) return bar(x);
}

Compiles to:

_foo_tail:
  jmp _bar

_foo_musttail:
  movl 4(%esp), %eax
  movl %eax, 4(%esp)
  jmp _bar

Compiler Explorer

Adding more parameters to the function (and tail call) increases the number of redundant loads/spills, too.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions