public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111786] New: No tail recursion for simple program
@ 2023-10-12 13:24 lukas.graetz@tu-darmstadt.de
  2023-10-12 13:40 ` [Bug c/111786] " jakub at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: lukas.graetz@tu-darmstadt.de @ 2023-10-12 13:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111786
           Summary: No tail recursion for simple program
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lukas.graetz@tu-darmstadt.de
  Target Milestone: ---

Created attachment 56096
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56096&action=edit
C code of expr_main

Follow up with nearly the same source file as 111643, only without the flatten
attribute. Sorry for taking so long for that. I learned the optimized compiler
should output a tail recursion. But this seams not to be the case: With "sub"
and "call", 16 bytes on the stack are used.

The file attached file contains:

---
int expr_main(int argc, char **argv)
{
    return expr_main_original(argc, argv);
}
---

And after cc1 -O3 on amd64, the output contains:

-- gcc 13.2.0 --
expr_main:
        subq    $8, %rsp
        call    expr_main_original
---

-- gcc 9.4.0 shipped with ubuntu 20.04 ---
expr_main:
        endbr64
        pushq   %rax
        popq    %rax
        pushq   %rax
        call    expr_main_original
---

-- Expected --
expr_main:
        jmp     expr_main_original
---

If I compile the above snippet only, I get the expected result. But not when
compiling the whole C file which also includes the body of
expr_main_original(). I also suspect there are some other factors I don't know,
since many other functions I tested yield the expected result.

In my case, the overhead seams to be negligible. However, I think it should be
possible to construct similar recursive programs where the overhead compared to
tail recursion is not negligible.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-12 21:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-12 13:24 [Bug c/111786] New: No tail recursion for simple program lukas.graetz@tu-darmstadt.de
2023-10-12 13:40 ` [Bug c/111786] " jakub at gcc dot gnu.org
2023-10-12 14:28 ` xry111 at gcc dot gnu.org
2023-10-12 21:18 ` lukas.graetz@tu-darmstadt.de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).