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

            Bug ID: 67283
           Summary: GCC regression over inlining of returned structures
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roche at httrack dot com
  Target Milestone: ---

Created attachment 36219
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36219&action=edit
Sample test case (gcc -S -O3 -W -Wall)

An optimization bug regression appears to exist when dealing with structures
returned by inlined functions. This was working totally fine with GCC 4.4.7.
(see below)

A typical example is:

struct foo {
        int flags;
        /* Let it be enough NOT to be packed in registers */
        void *opaque[2];
};

static __inline__ struct foo add_flag(struct foo foo, int flag) {
        foo.flags |= flag;
        return foo;
}

Calls to "add_flag" are inlined, but the stack usage increases with latest GCC
versions (the code should be almost identical, except the flag in place in the
stack).

Tested the following GCC versions: (grep "addq.*%rsp" to get stack usage for
each function) ; tested architecture: x86-64

GCC 4.4.7: OK
        addq    $72, %rsp  # demo_1
        addq    $72, %rsp
        addq    $72, %rsp
        addq    $72, %rsp
        addq    $72, %rsp  # demo_5

GCC 4.5.3 to 4.6.4: NOK (UNTESTED between 4.4.8 to 4.5.2)
        addq    $72, %rsp   # demo_1
        addq    $136, %rsp
        addq    $168, %rsp
        addq    $200, %rsp
        addq    $232, %rsp  # demo_5

GCC 4.7.3 to 5.2.0: NOK (UNTESTED between 4.6.5 to 4.7.2)
        addq    $72, %rsp   # demo_1
        addq    $136, %rsp
        addq    $200, %rsp
        addq    $264, %rsp
        addq    $328, %rsp  # demo_5

Therefore, the test case was fine in GCC 4.4.7, first degraded between 4.4.8
and 4.5.3, and then again between 4.6.5 and 4.7.3

Note: code produced with http://gcc.godbolt.org/ with -O3 -W -Wall flags.
(same results with -01)

Reply via email to