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

--- Comment #2 from Robert Obryk <robryk at gmail dot com> ---
Note that this optimization can not only be applied when the parameter is a
compile-time constant. The following function can also be compiled so as not to
touch the stack:

--snip--
struct foo {
  int a;
  int b;
  int c;
};

void bar(foo);

void baz(int x) {
  foo f;
  f.a = x;
  f.b = 5;
  f.c = 1;
  bar(f);
}
--snip--

According to godbolt, clang compiles this to:

--snip--
baz(int):                                # @baz(int)
        movl    %edi, %eax
        movabsq $21474836480, %rdi      # imm = 0x500000000
        orq     %rax, %rdi
        movl    $1, %esi
        jmp     bar(foo)              # TAILCALL
--snip--

Reply via email to