From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8EF253858D35; Tue, 25 Jan 2022 13:11:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EF253858D35 From: "redbeard0531 at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redbeard0531 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: Tue, 25 Jan 2022 13:11:22 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104223 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 lib= rary 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=3Dc++2b -O3 Reproduces on at least 11.2 and trunk #include namespace views =3D 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 typify =3D [] (int i) { return f(i); }; void with() { for (auto&& x : views::single(1) | views::transform(typify) | views::filter(typify)) {} } 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)=