public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/100686] New: attribute optimize ("O2") doesn't inline lambda
@ 2021-05-19 17:20 msebor at gcc dot gnu.org
  2021-05-20  6:40 ` [Bug c++/100686] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-05-19 17:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100686
           Summary: attribute optimize ("O2") doesn't inline lambda
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Declaring with attribute optimize ("O2") a function that makes use of a trivial
lambda function with doesn't inline the lambda unless the whole translation
unit is compiled with optimization enabled.  I'm guessing this happens for the
same reason as pr100323, although here the problem seems more severe since the
lambda is defined fully in the scope of the called function.

$ cat t.C && gcc -S -Wall -fdump-tree-optimized=/dev/stdout t.C
__attribute__ ((optimize ("O2"))) int f ()
{
  return [](int x){ return x; }( 1 );
}


;; Function f()::<lambda(int)>::operator() (_ZZ1fvENKUliE_clEi, funcdef_no=1,
decl_uid=2352, cgraph_uid=1, symbol_order=0)

int f()::<lambda(int)>::operator() (const struct ._anon_0 * const __closure,
int x)
{
  <bb 2> [local count: 1073741824]:
  return x_1(D);

}



;; Function f (_Z1fv, funcdef_no=0, decl_uid=2346, cgraph_uid=4,
symbol_order=3)

__attribute__((optimize ("O2")))
int f ()
{
  struct ._anon_0 D.2371;
  int _2;

  <bb 2> [local count: 1073741824]:
  _2 = f()::<lambda(int)>::operator() (&D.2371, 1); [tail call]
  D.2371 ={v} {CLOBBER};
  return _2;

}

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

* [Bug c++/100686] attribute optimize ("O2") doesn't inline lambda
  2021-05-19 17:20 [Bug middle-end/100686] New: attribute optimize ("O2") doesn't inline lambda msebor at gcc dot gnu.org
@ 2021-05-20  6:40 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-20  6:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |c++

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Likely nested functions (aka lambdas in this case) do not inherit attributes
(and in this case in particular optimize attributes) from the containing
function.

That might be by design and correct, using the #pragma variant should
result in more obvious behavior here (I hope ;)).

So I'm not sure if this is a bug, esp. in the context of C nested functions,
but of course the C++ FE could decide it is and apply select attributes
also to lambdas contained in a function.

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

end of thread, other threads:[~2021-05-20  6:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-19 17:20 [Bug middle-end/100686] New: attribute optimize ("O2") doesn't inline lambda msebor at gcc dot gnu.org
2021-05-20  6:40 ` [Bug c++/100686] " 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).