From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A93F43858004; Mon, 13 Dec 2021 20:30:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A93F43858004 From: "imachug at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/103696] New: Lambda functions are not inlined under certain optimization pragmas Date: Mon, 13 Dec 2021 20:30:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: imachug at gmail dot com 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Dec 2021 20:30:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103696 Bug ID: 103696 Summary: Lambda functions are not inlined under certain optimization pragmas Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: imachug at gmail dot com Target Milestone: --- This seems like a very weird bug to me and I'm not even sure how to label i= t, so please fix the component if needed. Testcase (C++): #pragma GCC optimize("finite-math-only") #pragma GCC target("sse3") void fn() { } int global_var; int solve() { auto nested =3D []() { return global_var; }; return nested(); } When compiling this code via `g++ test.cpp -c -O2 -std=3Dc++17`, I get the following assembly: $ objdump -d test.o ... 0000000000000000 <_ZZ5solvevENKUlvE_clEv.constprop.0>: 0: 8b 05 00 00 00 00 mov 0x0(%rip),%eax # 6 <_ZZ5solvevENKUlvE_clEv.constprop.0+0x6> 6: c3 retq=20=20=20 7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1) e: 00 00=20 ... 0000000000000020 <_Z5solvev>: 20: f3 0f 1e fa endbr64=20 24: e8 d7 ff ff ff callq 0 <_ZZ5solvevENKUlvE_clEv.constprop.= 0> 29: c3 retq=20=20=20 As you can see, the nested() lambda call was not inlined into solve(). However, if I do any of the following, the lambda is inlined as expected: - Remove `fn` definition - Move `fn` definition under `solve` - Replace reading `global_var` with a constant - Make `nested` a global function - Remove either of the two pragmas (or both) - Add -ffinite-math-only or -msse3 or both to the compilation line (regardl= ess of whether the pragmas are still there) I have absolutely no idea why a floating point optimization affects inlinin= g or how a pragma is different from a compilation line option wrt. this bug.=