[Bug c++/110845] Function call when it should inline?

2023-07-29 Thread deco33000 at yandex dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110845

--- Comment #4 from KL  ---
My mistake indeed,

You are right everything is OK :+1

[Bug c++/110845] Function call when it should inline?

2023-07-29 Thread xry111 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110845

Xi Ruoyao  changed:

   What|Removed |Added

 CC||xry111 at gcc dot gnu.org
 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #3 from Xi Ruoyao  ---
(In reply to KL from comment #2)
> Changed main to foo:
> same behavior

It's because you don't have a return statement in foo, causing an undefined
behavior.  And GCC considers undefined behaviors highly improbable to be
executed, so the same logic (not to inline too much into "cold" code paths)
still applies.

If you add the return statement they are inlined:

https://godbolt.org/z/Ko9r4fn3d

[Bug c++/110845] Function call when it should inline?

2023-07-28 Thread deco33000 at yandex dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110845

--- Comment #2 from KL  ---
Changed main to foo:
same behavior

[Bug c++/110845] Function call when it should inline?

2023-07-28 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110845

--- Comment #1 from Andrew Pinski  ---
Gcc has an heuristic for main where gcc knows that main is called only once and
does not inline as much into a function that will ever be called exactly once.

My bet if you Rename main to foo, gcc will inline f and g into that.