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;

}

Reply via email to