From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2D6653858D32; Sun, 24 Sep 2023 13:34:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D6653858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695562498; bh=Y20xfwvt/v+HyqjZNQsCoTmPK2dGMmR2Szj9/V1t9+Q=; h=From:To:Subject:Date:From; b=Cz73jmKJqXa7O7ni59qHMueq8Mv95cnbt7wZSsUN4W/y/nu89wMiQpCD3we4UxVlx PGoO3eFrvX4qPn74PKngZklsz1ygZcNQZ7xOtq4lCe9GeAhMShtc0Pq/D+wPMaqfnV psZKrihBHkYyg0kKCvMNRmCfSuYxDfRm+wPOtY0Q= From: "hubicka at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hubicka at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111573 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 using namespace std; static int dosum(std::function fn) { return fn(5,6); } int test() { auto sum =3D [](int a, int b) { return a + b; }; int s; for (s =3D 0; s < 10; s++) s+=3D dosum(sum); return s; } Gets optimized well only with early inlining. compiled with -fno-early-inli= ning 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=20=20=20 _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=