public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/111573] New: lambda functions often not inlined and optimized out
@ 2023-09-24 13:34 hubicka at gcc dot gnu.org
  2023-10-24  4:22 ` [Bug ipa/111573] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: hubicka at gcc dot gnu.org @ 2023-09-24 13:34 UTC (permalink / raw)
  To: gcc-bugs

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

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

* [Bug ipa/111573] lambda functions often not inlined and optimized out
  2023-09-24 13:34 [Bug middle-end/111573] New: lambda functions often not inlined and optimized out hubicka at gcc dot gnu.org
@ 2023-10-24  4:22 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-24  4:22 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-10-24
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Severity|normal                      |enhancement

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug ipa/111573] lambda functions often not inlined and optimized out
  2023-09-24 13:34 [Bug middle-end/111573] New: lambda functions often not inlined and optimized out hubicka at gcc dot gnu.org
  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
  2 siblings, 0 replies; 4+ messages in thread
From: jamborm at gcc dot gnu.org @ 2024-02-20 14:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Martin Jambor <jamborm at gcc dot gnu.org> ---
I cannot see any difference at -O3 with or without -fno-early-inlining.

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

* [Bug ipa/111573] lambda functions often not inlined and optimized out
  2023-09-24 13:34 [Bug middle-end/111573] New: lambda functions often not inlined and optimized out hubicka at gcc dot gnu.org
  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
  2 siblings, 0 replies; 4+ messages in thread
From: xry111 at gcc dot gnu.org @ 2024-03-25 10:35 UTC (permalink / raw)
  To: gcc-bugs

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

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |chfast at gmail dot com

--- Comment #3 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
*** Bug 114452 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2024-03-25 10:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-24 13:34 [Bug middle-end/111573] New: lambda functions often not inlined and optimized out hubicka at gcc dot gnu.org
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

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).