public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "hubicka at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/111573] New: lambda functions often not inlined and optimized out Date: Sun, 24 Sep 2023 13:34:57 +0000 [thread overview] Message-ID: <bug-111573-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111573 Bug ID: 111573 Summary: lambda functions often not inlined and optimized out Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: hubicka at gcc dot gnu.org Target Milestone: --- #include <functional> using namespace std; static int dosum(std::function<int(int,int)> fn) { return fn(5,6); } int test() { auto sum = [](int a, int b) { return a + b; }; int s; for (s = 0; s < 10; s++) s+= dosum(sum); return s; } Gets optimized well only with early inlining. compiled with -fno-early-inlining yields to: _Z4testv: .LFB2166: .cfi_startproc subq $56, %rsp .cfi_def_cfa_offset 64 xorl %ecx, %ecx .p2align 4,,10 .p2align 3 .L8: leaq 12(%rsp), %rdx leaq 8(%rsp), %rsi movl $5, 8(%rsp) leaq 16(%rsp), %rdi movl $6, 12(%rsp) call _ZNSt17_Function_handlerIFiiiEZ4testvEUliiE_E9_M_invokeERKSt9_Any_dataOiS6_ leal 1(%rcx,%rax), %ecx cmpl $9, %ecx jle .L8 movl %ecx, %eax addq $56, %rsp .cfi_def_cfa_offset 8 ret So we fail to inline since ipa-prop fails to track the constant function address. I think this is really common in typical lambda function usage
next reply other threads:[~2023-09-24 13:34 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-09-24 13:34 hubicka at gcc dot gnu.org [this message] 2023-10-24 4:22 ` [Bug ipa/111573] " pinskia at gcc dot gnu.org 2024-02-20 14:48 ` jamborm at gcc dot gnu.org 2024-03-25 10:35 ` xry111 at gcc dot gnu.org
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-111573-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).