public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function
@ 2023-02-15 12:21 pobrn at protonmail dot com
  2023-02-15 12:37 ` [Bug ipa/108802] " rguenth at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: pobrn at protonmail dot com @ 2023-02-15 12:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108802
           Summary: missed inlining of call via pointer to member function
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pobrn at protonmail dot com
  Target Milestone: ---

See https://gcc.godbolt.org/z/j833EGfGY

struct A {
    int f(int x) { return 2 * x; }
};

int f1() {
    A a;
    return [&](auto&& f) { return (a.*f)(42); } (&A::f);
}

clang optimizes `f1()` to `return 84`, but gcc does not do so. This seems to
have been changed somewhere between gcc 9 and 10 because 9.5 does the inlining
but 10.1 does not do it.

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

* [Bug ipa/108802] missed inlining of call via pointer to member function
  2023-02-15 12:21 [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function pobrn at protonmail dot com
@ 2023-02-15 12:37 ` rguenth at gcc dot gnu.org
  2023-02-15 12:42 ` jakub at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-02-15 12:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |ipa
                 CC|                            |hubicka at gcc dot gnu.org,
                   |                            |jamborm at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org
           Keywords|                            |missed-optimization

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
t.ii:7:49: missed:   will not early inline: int
f1()/2->f1()::<lambda(auto:1&&)> [with auto:1 = int (A::*)(int)]/1, growth 14
exceeds --param early-inlining-insns

the lambda is only IPA inlined which is then too late to figure the member
function inlining.  Maybe this is sth for IPA-CP?

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

* [Bug ipa/108802] missed inlining of call via pointer to member function
  2023-02-15 12:21 [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function pobrn at protonmail dot com
  2023-02-15 12:37 ` [Bug ipa/108802] " rguenth at gcc dot gnu.org
@ 2023-02-15 12:42 ` jakub at gcc dot gnu.org
  2023-02-15 16:30 ` [Bug ipa/108802] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-02-15 12:42 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This changed with r10-3542-g0b92cf305dcf34387a8e2564e55ca8948df3b47a

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

* [Bug ipa/108802] [10/11/12/13 Regression] missed inlining of call via pointer to member function
  2023-02-15 12:21 [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function pobrn at protonmail dot com
  2023-02-15 12:37 ` [Bug ipa/108802] " rguenth at gcc dot gnu.org
  2023-02-15 12:42 ` jakub at gcc dot gnu.org
@ 2023-02-15 16:30 ` pinskia at gcc dot gnu.org
  2023-02-21 12:39 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-15 16:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.5
            Summary|missed inlining of call via |[10/11/12/13 Regression]
                   |pointer to member function  |missed inlining of call via
                   |                            |pointer to member function

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

* [Bug ipa/108802] [10/11/12/13 Regression] missed inlining of call via pointer to member function
  2023-02-15 12:21 [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function pobrn at protonmail dot com
                   ` (2 preceding siblings ...)
  2023-02-15 16:30 ` [Bug ipa/108802] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
@ 2023-02-21 12:39 ` rguenth at gcc dot gnu.org
  2023-07-07 10:44 ` [Bug ipa/108802] [11/12/13/14 " rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-02-21 12:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
   Last reconfirmed|                            |2023-02-21
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
That means it was a conscious decision.

IPA function summary for f1()::<lambda(auto:1&&)> [with auto:1 = int
(A::*)(int)]/1 inlinable
  global time:     30.500000
  self size:       23
  global size:     25

the body is

  <bb 2> [local count: 1073741824]:
  _1 = f_18(D)->__pfn;
  _2 = (long int) _1;
  _3 = _2 & 1;
  if (_3 != 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 4>; [50.00%]

  <bb 3> [local count: 536870913]:
  _4 = __closure_19(D)->__a;
  _5 = f_18(D)->__delta;
  _6 = (sizetype) _5;
  _7 = _4 + _6;
  _8 = *_7;
  _9 = _2 + -1;
  _10 = (sizetype) _9;
  _11 = _8 + _10;
  iftmp.0_20 = *_11;

  <bb 4> [local count: 1073741824]:
  # iftmp.0_16 = PHI <iftmp.0_20(3), _1(2)>
  _12 = __closure_19(D)->__a;
  _13 = f_18(D)->__delta;
  _14 = (sizetype) _13;
  _15 = _12 + _14;
  _22 = iftmp.0_16 (_15, 42);
  return _22;

so it is quite large.

While we can give inline incentives in IPA inlining we do not discover the
inline target there - the above has it also well obfuscated.  Maybe we
can still compute the set of functions possibly called here and perform
speculative inlining in IPA?

Maybe the frontend can also improve the initial IL which looks like

  <<cleanup_point return <retval> = (((long int) f->__pfn & 1) != 0) ? (int
A::<T3f8> (struct A *, int) *) *(*((int (*) () * *) a + (sizetype) f->__delta)
+ (sizetype) ((long int) f->__pfn + -1)) : f->__pfn ((struct A *) a +
(sizetype) f->__delta, 42)>>;

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

* [Bug ipa/108802] [11/12/13/14 Regression] missed inlining of call via pointer to member function
  2023-02-15 12:21 [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function pobrn at protonmail dot com
                   ` (3 preceding siblings ...)
  2023-02-21 12:39 ` rguenth at gcc dot gnu.org
@ 2023-07-07 10:44 ` rguenth at gcc dot gnu.org
  2024-02-16 16:35 ` hubicka at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

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

* [Bug ipa/108802] [11/12/13/14 Regression] missed inlining of call via pointer to member function
  2023-02-15 12:21 [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function pobrn at protonmail dot com
                   ` (4 preceding siblings ...)
  2023-07-07 10:44 ` [Bug ipa/108802] [11/12/13/14 " rguenth at gcc dot gnu.org
@ 2024-02-16 16:35 ` hubicka at gcc dot gnu.org
  2024-02-19 17:51 ` jamborm at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: hubicka at gcc dot gnu.org @ 2024-02-16 16:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
I don't think we can reasonably expect every caller of lambda function to be
early inlined, so we need to extend ipa-prop to understand the obfuscated code.
 I disucussed that with Martin some time ago - I think this is quite common
problem with modern C++, so we will need to pattern match this, which is quite
unfortunate.

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

* [Bug ipa/108802] [11/12/13/14 Regression] missed inlining of call via pointer to member function
  2023-02-15 12:21 [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function pobrn at protonmail dot com
                   ` (5 preceding siblings ...)
  2024-02-16 16:35 ` hubicka at gcc dot gnu.org
@ 2024-02-19 17:51 ` jamborm at gcc dot gnu.org
  2024-02-21 14:55 ` jamborm at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jamborm at gcc dot gnu.org @ 2024-02-19 17:51 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Jambor <jamborm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jamborm at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #6 from Martin Jambor <jamborm at gcc dot gnu.org> ---
I think I know what to do.

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

* [Bug ipa/108802] [11/12/13/14 Regression] missed inlining of call via pointer to member function
  2023-02-15 12:21 [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function pobrn at protonmail dot com
                   ` (6 preceding siblings ...)
  2024-02-19 17:51 ` jamborm at gcc dot gnu.org
@ 2024-02-21 14:55 ` jamborm at gcc dot gnu.org
  2024-03-08 14:57 ` jamborm at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jamborm at gcc dot gnu.org @ 2024-02-21 14:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Martin Jambor <jamborm at gcc dot gnu.org> ---
I have proposed a patch on the mailing list:
https://inbox.sourceware.org/gcc-patches/ri6y1bdx3yg.fsf@virgil.suse.cz/T/#u

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

* [Bug ipa/108802] [11/12/13/14 Regression] missed inlining of call via pointer to member function
  2023-02-15 12:21 [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function pobrn at protonmail dot com
                   ` (7 preceding siblings ...)
  2024-02-21 14:55 ` jamborm at gcc dot gnu.org
@ 2024-03-08 14:57 ` jamborm at gcc dot gnu.org
  2024-03-19 21:38 ` cvs-commit at gcc dot gnu.org
  2024-03-20 16:18 ` [Bug ipa/108802] [11/12/13 " jamborm at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: jamborm at gcc dot gnu.org @ 2024-03-08 14:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Martin Jambor <jamborm at gcc dot gnu.org> ---
I have proposed an improved patch on the mailing list:
https://inbox.sourceware.org/gcc-patches/ri6r0gkzvi4.fsf@virgil.suse.cz/T/#u

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

* [Bug ipa/108802] [11/12/13/14 Regression] missed inlining of call via pointer to member function
  2023-02-15 12:21 [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function pobrn at protonmail dot com
                   ` (8 preceding siblings ...)
  2024-03-08 14:57 ` jamborm at gcc dot gnu.org
@ 2024-03-19 21:38 ` cvs-commit at gcc dot gnu.org
  2024-03-20 16:18 ` [Bug ipa/108802] [11/12/13 " jamborm at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-19 21:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Jambor <jamborm@gcc.gnu.org>:

https://gcc.gnu.org/g:bf838884fac573b4902a21bb82d9b6f777e32cb9

commit r14-9559-gbf838884fac573b4902a21bb82d9b6f777e32cb9
Author: Martin Jambor <mjambor@suse.cz>
Date:   Tue Mar 19 22:33:27 2024 +0100

    ipa: Fix C++ member ptr indirect inlining (PR 114254, PR 108802)

    Even though we have had code to handle creation of indirect call graph
    edges (so that these calls can than be made direct as part of IPA-CP
    and inlining and eventually also inlined) for C++ member pointers for
    many years, it turns out that it does not work for lambdas and that it
    has been severely broken since GCC 10 when the base class has virtual
    functions.

    Lambdas don't work because the code cannot work with structures
    representing member function pointers because they are passed by
    reference instead by value and the code was not ready for that.

    The presence of virtual methods broke thinks because at some point C++
    FE got clever and stopped emitting the check for virtual methods when
    the base class does not have any and that in turn made our existing
    testcases not test the necessary pattern matching code.  The pattern
    matcher had a small bug which did not matter before
    r10-917-g3b47da42de621c but did afterwards.

    This patch changes the pattern matcher to match both of these cases.

    gcc/ChangeLog:

    2024-03-06  Martin Jambor  <mjambor@suse.cz>

            PR ipa/108802
            PR ipa/114254
            * ipa-prop.cc (ipa_get_stmt_member_ptr_load_param): Fix case
looking
            at COMPONENT_REFs directly from a PARM_DECL, also recognize loads
from
            a pointer parameter.
            (ipa_analyze_indirect_call_uses): Also recognize loads from a
pointer
            parameter, also recognize the case when pfn pointer is loaded in
its
            own BB.

    gcc/testsuite/ChangeLog:

    2024-03-06  Martin Jambor  <mjambor@suse.cz>

            PR ipa/108802
            PR ipa/114254
            * g++.dg/ipa/iinline-4.C: New test.
            * g++.dg/ipa/pr108802.C: Likewise.

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

* [Bug ipa/108802] [11/12/13 Regression] missed inlining of call via pointer to member function
  2023-02-15 12:21 [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function pobrn at protonmail dot com
                   ` (9 preceding siblings ...)
  2024-03-19 21:38 ` cvs-commit at gcc dot gnu.org
@ 2024-03-20 16:18 ` jamborm at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: jamborm at gcc dot gnu.org @ 2024-03-20 16:18 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Jambor <jamborm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12/13/14 Regression]    |[11/12/13 Regression]
                   |missed inlining of call via |missed inlining of call via
                   |pointer to member function  |pointer to member function

--- Comment #10 from Martin Jambor <jamborm at gcc dot gnu.org> ---
Fixed on trunk.  I may consider backporting to GCC 13 but probably not to
earlier versions.

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

end of thread, other threads:[~2024-03-20 16:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-15 12:21 [Bug tree-optimization/108802] New: missed inlining of call via pointer to member function pobrn at protonmail dot com
2023-02-15 12:37 ` [Bug ipa/108802] " rguenth at gcc dot gnu.org
2023-02-15 12:42 ` jakub at gcc dot gnu.org
2023-02-15 16:30 ` [Bug ipa/108802] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
2023-02-21 12:39 ` rguenth at gcc dot gnu.org
2023-07-07 10:44 ` [Bug ipa/108802] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-02-16 16:35 ` hubicka at gcc dot gnu.org
2024-02-19 17:51 ` jamborm at gcc dot gnu.org
2024-02-21 14:55 ` jamborm at gcc dot gnu.org
2024-03-08 14:57 ` jamborm at gcc dot gnu.org
2024-03-19 21:38 ` cvs-commit at gcc dot gnu.org
2024-03-20 16:18 ` [Bug ipa/108802] [11/12/13 " jamborm 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).