public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/104223] New: GCC unable to inline trivial functions passed to views::filter and transform unless lifted into types
@ 2022-01-25 13:11 redbeard0531 at gmail dot com
  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
  0 siblings, 2 replies; 3+ messages in thread
From: redbeard0531 at gmail dot com @ 2022-01-25 13:11 UTC (permalink / raw)
  To: gcc-bugs

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)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug ipa/104223] GCC unable to inline trivial functions passed to views::filter and transform unless lifted into types
  2022-01-25 13:11 [Bug libstdc++/104223] New: GCC unable to inline trivial functions passed to views::filter and transform unless lifted into types redbeard0531 at gmail dot com
@ 2022-01-25 17:22 ` pinskia at gcc dot gnu.org
  2022-01-26  7:55 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-25 17:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104223

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There are other bugs which have a similar issue where we figure out the
function call late but then don't have another inlining pass.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug ipa/104223] GCC unable to inline trivial functions passed to views::filter and transform unless lifted into types
  2022-01-25 13:11 [Bug libstdc++/104223] New: GCC unable to inline trivial functions passed to views::filter and transform unless lifted into types redbeard0531 at gmail dot com
  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
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-26  7:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104223

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
            Version|unknown                     |11.2.1
   Last reconfirmed|                            |2022-01-26
     Ever confirmed|0                           |1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-26  7:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-25 13:11 [Bug libstdc++/104223] New: GCC unable to inline trivial functions passed to views::filter and transform unless lifted into types redbeard0531 at gmail dot com
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

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).