public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redbeard0531 at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/104223] New: GCC unable to inline trivial functions passed to views::filter and transform unless lifted into types Date: Tue, 25 Jan 2022 13:11:22 +0000 [thread overview] Message-ID: <bug-104223-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104223 Bug ID: 104223 Summary: GCC unable to inline trivial functions passed to views::filter and transform unless lifted into types Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redbeard0531 at gmail dot com Target Milestone: --- I'm not sure if this is an issue with the optimizer or the way that the library code is written, or some combination of the two, but the end result seems unfortunate. with() and without() are logically the same function, the only difference is that with() lifts the function pointers into types using a templated lambda variable, while without() just passes the function names directly to the library. It seems interesting that the optimizer knows that they are "constant enough" to emit direct rather than indirect calls to t() and f(), however, it isn't constant enough to inline those calls. https://godbolt.org/z/EqWzzh916 Flags: -std=c++2b -O3 Reproduces on at least 11.2 and trunk #include <ranges> namespace views = std::views; void trace() noexcept; inline int f(int i) { trace(); return i; } inline bool t(int) { return true; } // for some reason gcc needs this in order to inline f() and t() template <auto f> auto typify = [] (int i) { return f(i); }; void with() { for (auto&& x : views::single(1) | views::transform(typify<f>) | views::filter(typify<t>)) {} } void without() { for (auto&& x : views::single(1) | views::transform(f) | views::filter(t)) {} } with(): sub rsp, 8 call trace() add rsp, 8 jmp trace() without(): sub rsp, 8 mov edi, 1 call f(int) mov edi, eax call t(int) test al, al jne .L10 add rsp, 8 ret .L10: mov edi, 1 add rsp, 8 jmp f(int)
next reply other threads:[~2022-01-25 13:11 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-01-25 13:11 redbeard0531 at gmail dot com [this message] 2022-01-25 17:22 ` [Bug ipa/104223] " pinskia at gcc dot gnu.org 2022-01-26 7:55 ` rguenth 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-104223-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).