public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hubicka at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug ipa/59948] Optimize std::function
Date: Mon, 25 Sep 2023 09:04:51 +0000	[thread overview]
Message-ID: <bug-59948-4-Eyen3293E7@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-59948-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #8 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
Trunk optimized stuff return 0, but fails to optimize out functions which
becomes unused after indirect inlining.
With -fno-early-inlining we end up with:

int m ()
{
  void * D.48296;
  int __args#0;
  struct function h;
  int _12;
  bool (*<T3341>) (union _Any_data & {ref-all}, const union _Any_data &
{ref-all}, _Manager_operation) _24;
  bool (*<T3341>) (union _Any_data & {ref-all}, const union _Any_data &
{ref-all}, _Manager_operation) _27;
  long unsigned int _29;
  long unsigned int _35;
  vector(2) long unsigned int _37;
  void * _42;

  <bb 2> [local count: 1073741824]:
  _29 = (long unsigned int) _M_invoke;
  _35 = (long unsigned int) _M_manager;
  _37 = {_35, _29};
  h ={v} {CLOBBER};
  MEM <char[8]> [(struct _Function_base *)&h + 8B] = {};
  MEM[(int (*<T1841>) (int) *)&h] = f;
  MEM <vector(2) long unsigned int> [(void *)&h + 16B] = _37;
  __args#0 = 1;
  _12 = std::_Function_handler<int(int), int (*)(int)>::_M_invoke
(&h.D.47068._M_functor, &__args#0);

  <bb 3> [local count: 1073312329]:
  __args#0 ={v} {CLOBBER(eol)};
  _24 = MEM[(struct _Function_base *)&h]._M_manager;
  if (_24 != 0B)
    goto <bb 4>; [70.00%]
  else
    goto <bb 5>; [30.00%]

  <bb 4> [local count: 751318634]:
  _24 (&MEM[(struct _Function_base *)&h]._M_functor, &MEM[(struct
_Function_base *)&h]._M_functor, 3);

  <bb 5> [local count: 1073312329]:
  h ={v} {CLOBBER};
  h ={v} {CLOBBER(eol)};
  return _12;

  <bb 6> [count: 0]:
<L3>:
  _27 = MEM[(struct _Function_base *)&h]._M_manager;
  if (_27 != 0B)
    goto <bb 7>; [0.00%]
  else
    goto <bb 8>; [0.00%]

  <bb 7> [count: 0]:
  _27 (&MEM[(struct _Function_base *)&h]._M_functor, &MEM[(struct
_Function_base *)&h]._M_functor, 3);

  <bb 8> [count: 0]:
  h ={v} {CLOBBER};
  _42 = __builtin_eh_pointer (2);
  __builtin_unwind_resume (_42);

}

ipa-prop fails to track the pointer passed around:

IPA function summary for int m()/288 inlinable
  global time:     41.256800
  self size:       16
  global size:     41
  min size:       38
  self stack:      32
  global stack:    32
    size:19.000000, time:8.660000
    size:3.000000, time:2.000000,  executed if:(not inlined)
  calls:
    std::function<int(int)>::~function()/286 inlined
      freq:0.00
      Stack frame offset 32, callee self size 0
      std::_Function_base::~_Function_base()/71 inlined
        freq:0.00
        Stack frame offset 32, callee self size 0
        indirect call loop depth: 0 freq:0.00 size: 6 time: 18
    std::function<int(int)>::~function()/404 inlined
      freq:1.00
      Stack frame offset 32, callee self size 0
      std::_Function_base::~_Function_base()/405 inlined
        freq:1.00
        Stack frame offset 32, callee self size 0
        indirect call loop depth: 0 freq:0.70 size: 6 time: 18
    _Res std::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const
[with _Res = int; _ArgTypes = {int}]/304 inlined
      freq:1.00
      Stack frame offset 32, callee self size 0
      void std::__throw_bad_function_call()/374 function body not available
        freq:0.00 loop depth: 0 size: 1 time: 10
      _M_empty.isra/384 inlined 
        freq:1.00
        Stack frame offset 32, callee self size 0
      indirect call loop depth: 0 freq:1.00 size: 6 time: 18
    std::function<_Res(_ArgTypes ...)>::function(_Functor&&) [with _Functor =
int (&)(int); _Constraints = void; _Res = int; _ArgTypes = {int}]/302 inlined 
      freq:1.00
      Stack frame offset 32, callee self size 0
      std::function<_Res(_ArgTypes ...)>::function(_Functor&&) [with _Functor =
int (&)(int); _Constraints = void; _Res = int; _ArgTypes = {int}]/375 inlined
        freq:0.33
        Stack frame offset 32, callee self size 0
        static void
std::_Function_base::_Base_manager<_Functor>::_M_init_functor(std::_Any_data&,
_Fn&&) [with _Fn = int (&)(int); _Functor = int (*)(int)]/310 inlined
          freq:0.33
          Stack frame offset 32, callee self size 0
          _M_create.isra/383 inlined
            freq:0.33
            Stack frame offset 32, callee self size 0
            void* std::_Any_data::_M_access()/388 inlined
              freq:0.33
              Stack frame offset 32, callee self size 0
            operator new.isra/386 inlined
              freq:0.33
              Stack frame offset 32, callee self size 0
      static bool
std::_Function_base::_Base_manager<_Functor>::_M_not_empty_function(_Tp*) [with
_Tp = int(int); _Functor = int (*)(int)]/308 inlined
        freq:1.00
        Stack frame offset 32, callee self size 0
      constexpr std::_Function_base::_Function_base()/299 inlined
        freq:1.00
        Stack frame offset 32, callee self size 0

      parent reply	other threads:[~2023-09-25  9:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-26 11:31 [Bug ipa/59948] New: " glisse at gcc dot gnu.org
2014-01-26 13:24 ` [Bug ipa/59948] " glisse at gcc dot gnu.org
2014-01-29 13:27 ` rguenth at gcc dot gnu.org
2014-02-04  2:35 ` hubicka at gcc dot gnu.org
2014-02-04  3:00 ` hubicka at gcc dot gnu.org
2014-05-02 14:06 ` glisse at gcc dot gnu.org
2014-09-26 16:54 ` hubicka at gcc dot gnu.org
2015-02-26  0:09 ` glisse at gcc dot gnu.org
2023-09-25  9:04 ` hubicka at gcc dot gnu.org [this message]

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-59948-4-Eyen3293E7@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: link
Be 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).