public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "imachug at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-103696-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103696 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 it, 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 = []() { return global_var; }; return nested(); } When compiling this code via `g++ test.cpp -c -O2 -std=c++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 7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1) e: 00 00 ... 0000000000000020 <_Z5solvev>: 20: f3 0f 1e fa endbr64 24: e8 d7 ff ff ff callq 0 <_ZZ5solvevENKUlvE_clEv.constprop.0> 29: c3 retq 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 (regardless of whether the pragmas are still there) I have absolutely no idea why a floating point optimization affects inlining or how a pragma is different from a compilation line option wrt. this bug.
next reply other threads:[~2021-12-13 20:30 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-13 20:30 imachug at gmail dot com [this message] 2021-12-13 20:33 ` [Bug target/103696] " imachug at gmail dot com 2021-12-14 1:14 ` [Bug c++/103696] pragma optimization is not applying to Lambdas pinskia at gcc dot gnu.org 2021-12-14 16:59 ` marxin at gcc dot gnu.org 2021-12-16 11:08 ` marxin at gcc dot gnu.org 2021-12-16 16:52 ` cvs-commit at gcc dot gnu.org 2021-12-16 16:53 ` marxin at gcc dot gnu.org 2024-04-17 7:12 ` pinskia 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-103696-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).