public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "lukas.graetz@tu-darmstadt.de" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/111786] New: No tail recursion for simple program Date: Thu, 12 Oct 2023 13:24:46 +0000 [thread overview] Message-ID: <bug-111786-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2023-10-12 13:24 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-10-12 13:24 lukas.graetz@tu-darmstadt.de [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-111786-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).