public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108162] New: Missed optimization opportunity. Complex function that starts with if (param == 0) return 0;
@ 2022-12-17 23:01 levo.delellis at gmail dot com
  2022-12-17 23:08 ` [Bug middle-end/108162] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: levo.delellis at gmail dot com @ 2022-12-17 23:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108162
           Summary: Missed optimization opportunity. Complex function that
                    starts with if (param == 0) return 0;
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: levo.delellis at gmail dot com
  Target Milestone: ---

I had a lot of fun writing https://bolinlang.com/does-it-inline

I was intentionally trying to break the optimizer. I found a few cases in clang
and two cases I don't think should apply but I think both can gain from the
last one. Skipping a function call when the function starts with `if (param ==
0) return 0;`. I tested with a recursive fibonacci. If you scroll to the very
bottom you'll see it.

Cases that clang optimizes but gcc did not A) Round 3 a and b. I don't think
locale will affect it and clang optimizes it. All of round 4 clang optimizes. I
suspect there's something getting in the way of peeking through push and size.
I vaguely remember thinking std::forward may get in the way in the past but it
was long enough ago that I don't remember what I was doing to think that

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

* [Bug middle-end/108162] Missed optimization opportunity. Complex function that starts with if (param == 0) return 0;
  2022-12-17 23:01 [Bug c++/108162] New: Missed optimization opportunity. Complex function that starts with if (param == 0) return 0; levo.delellis at gmail dot com
@ 2022-12-17 23:08 ` pinskia at gcc dot gnu.org
  2022-12-17 23:13 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-17 23:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Gcc knows main is only called once and has heuristics not to inline as much
into it.

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

* [Bug middle-end/108162] Missed optimization opportunity. Complex function that starts with if (param == 0) return 0;
  2022-12-17 23:01 [Bug c++/108162] New: Missed optimization opportunity. Complex function that starts with if (param == 0) return 0; levo.delellis at gmail dot com
  2022-12-17 23:08 ` [Bug middle-end/108162] " pinskia at gcc dot gnu.org
@ 2022-12-17 23:13 ` pinskia at gcc dot gnu.org
  2022-12-17 23:47 ` levo.delellis at gmail dot com
  2022-12-17 23:53 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-17 23:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Round 4 is because of this heuriheuristics. Name the function something besides
main and try again.

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

* [Bug middle-end/108162] Missed optimization opportunity. Complex function that starts with if (param == 0) return 0;
  2022-12-17 23:01 [Bug c++/108162] New: Missed optimization opportunity. Complex function that starts with if (param == 0) return 0; levo.delellis at gmail dot com
  2022-12-17 23:08 ` [Bug middle-end/108162] " pinskia at gcc dot gnu.org
  2022-12-17 23:13 ` pinskia at gcc dot gnu.org
@ 2022-12-17 23:47 ` levo.delellis at gmail dot com
  2022-12-17 23:53 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: levo.delellis at gmail dot com @ 2022-12-17 23:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Levo DeLellis <levo.delellis at gmail dot com> ---
(In reply to Andrew Pinski from comment #2)
> Round 4 is because of this heuriheuristics. Name the function something
> besides main and try again.

I couldn't reproduce. fn has more than xor eax/ret. godbolt shows the same.
x86-64 12.2 https://gcc.godbolt.org/z/WdacrE788

#include <vector>
int fn() { std::vector<int> v; v.push_back(1000); return 0; }
int main(int argc, char *argv[]) { fn(); }


0000000000001160 <_Z2fnv>:
    1160:       48 83 ec 08             sub    rsp,0x8
    1164:       bf 04 00 00 00          mov    edi,0x4
    1169:       e8 c2 fe ff ff          call   1030 <_Znwm@plt>
    116e:       be 04 00 00 00          mov    esi,0x4
    1173:       48 89 c7                mov    rdi,rax
    1176:       c7 00 e8 03 00 00       mov    DWORD PTR [rax],0x3e8
    117c:       e8 bf fe ff ff          call   1040 <_ZdlPvm@plt>
    1181:       31 c0                   xor    eax,eax
    1183:       48 83 c4 08             add    rsp,0x8
    1187:       c3                      ret

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

* [Bug middle-end/108162] Missed optimization opportunity. Complex function that starts with if (param == 0) return 0;
  2022-12-17 23:01 [Bug c++/108162] New: Missed optimization opportunity. Complex function that starts with if (param == 0) return 0; levo.delellis at gmail dot com
                   ` (2 preceding siblings ...)
  2022-12-17 23:47 ` levo.delellis at gmail dot com
@ 2022-12-17 23:53 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-17 23:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Levo DeLellis from comment #3)
> (In reply to Andrew Pinski from comment #2)
> > Round 4 is because of this heuriheuristics. Name the function something
> > besides main and try again.
> 
> I couldn't reproduce. fn has more than xor eax/ret. godbolt shows the same.
> x86-64 12.2 https://gcc.godbolt.org/z/WdacrE788
> 
> #include <vector>
> int fn() { std::vector<int> v; v.push_back(1000); return 0; }
> int main(int argc, char *argv[]) { fn(); }

Right that is not inlining either. Anyways there are another bugs about not
removing operator new/operator delete in some cases.

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

end of thread, other threads:[~2022-12-17 23:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-17 23:01 [Bug c++/108162] New: Missed optimization opportunity. Complex function that starts with if (param == 0) return 0; levo.delellis at gmail dot com
2022-12-17 23:08 ` [Bug middle-end/108162] " pinskia at gcc dot gnu.org
2022-12-17 23:13 ` pinskia at gcc dot gnu.org
2022-12-17 23:47 ` levo.delellis at gmail dot com
2022-12-17 23:53 ` pinskia 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).