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

            Bug ID: 89820
           Summary: Returning empty type produces unnecessary instructions
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoshkka at gmail dot com
  Target Milestone: ---

Consider the following code


struct my_type_impl {};

my_type_impl foo0() { return {}; }
my_type_impl foo1() { my_type_impl tmp; return tmp; }


For `foo0` and `foo1` GCC generates the following assembly:

        xor     eax, eax
        ret


However xoring the `eax` seems unnecessary and some of the other compilers just
generate the `ret` instruction.

The additional `xor` instruction could significantly increase the code size for
generic C++ programs. For example in Bug 89819 and Bug 89816 each of he 36 jump
table entries has that additional instruction.

Reply via email to