[Bug c++/97952] New: Poor optimization of closure-like construct in C++ as compared to C

eric-gcc at omnifarious dot org gcc-bugzilla@gcc.gnu.org
Mon Nov 23 14:40:29 GMT 2020


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

            Bug ID: 97952
           Summary: Poor optimization of closure-like construct in C++ as
                    compared to C
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eric-gcc at omnifarious dot org
  Target Milestone: ---

This code generates about 400+ lines of assembly:

https://gcc.godbolt.org/z/s9s9Mx

and this essentially equivalent C code generates only 100+ lines:

https://gcc.godbolt.org/z/5abWEe

This seems like poor optimization in C++. The C code makes use of nested
functions, a GCC specific feature. And the C++ code uses a class to simulate a
closure, thereby accomplishing essentially the same goal.


More information about the Gcc-bugs mailing list