public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dumoulin.thibaut at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/101995] New: regression built-in memset missed-optimization arm -Os
Date: Fri, 20 Aug 2021 09:35:53 +0000	[thread overview]
Message-ID: <bug-101995-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 101995
           Summary: regression built-in memset missed-optimization arm -Os
           Product: gcc
           Version: 10.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dumoulin.thibaut at gmail dot com
  Target Milestone: ---

For cortex-m4 -Os, GCC10 produces bigger assembly code than GCC7 when memset is
called.

Here is the C code example to trigger the regression:

```C
#include <stdio.h>
#include <string.h>

struct foo_t {
  int a;
  int b;
  int c;
  int d;
};

/* Random function modifying foo with another value than 0 */
void doStuff(struct foo_t *foo) {
  foo->b = foo->a + foo->c;
}

void twoLinesFunction(struct foo_t *foo) {
  /* R0 is saved in GCC10 but not in GCC7 */
  memset(foo, 0x00, sizeof(struct foo_t));
  doStuff(foo);
}

int main(void) {
  struct foo_t foo;
  twoLinesFunction(&foo);
  return 0;
}
```

compile command: `gcc -Os -mcpu=cortex-m4`

GCC7.3.1 produces:
```asm
<twoLinesFunction>:
    push    {r3, lr}
    movs    r2, #16
    movs    r1, #0
    bl      8168 <memset>
    ldmia.w sp!, {r3, lr}
    b.w     8104 <doStuff>
```

While GCC10.3.0 produces:
```asm
<twoLinesFunction>:
    push    {r4, lr}
    movs    r2, #16
    mov     r4, r0        --> backup r0
    movs    r1, #0
    bl      8174 <memset>
    mov     r0, r4        --> restore r0
    ldmia.w sp!, {r4, lr}
    b.w     810c <doStuff>
```

Main function remains the same.

The builtin memset function does not change R0 so there is no need to save it
and restore it later. GCC7 is more efficient.
GCC10 should not backup R0 for this builtin function in this case, it produces
slower code.

There is this PR https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61241 which is
also referring to this behavior with a patch to implement the optimization but
I'm not sure when this optimization has been wiped out.

             reply	other threads:[~2021-08-20  9:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20  9:35 dumoulin.thibaut at gmail dot com [this message]
2021-08-20 12:21 ` [Bug middle-end/101995] " rguenth at gcc dot gnu.org
2021-08-20 21:45 ` [Bug rtl-optimization/101995] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
2021-08-21  2:53 ` pinskia at gcc dot gnu.org
2021-08-21  3:17 ` pinskia at gcc dot gnu.org
2021-08-21  3:26 ` pinskia at gcc dot gnu.org
2021-08-23  9:10 ` rguenth at gcc dot gnu.org
2021-12-08 14:10 ` [Bug rtl-optimization/101995] [9/10/11/12 Regression] regression built-in memset missed-optimization arm -Os since r9-3594 marxin at gcc dot gnu.org
2021-12-08 20:42 ` segher at gcc dot gnu.org
2021-12-08 20:44 ` segher at gcc dot gnu.org
2021-12-08 20:50 ` segher at gcc dot gnu.org
2021-12-09  8:18 ` pinskia at gcc dot gnu.org
2021-12-09 21:08 ` segher at gcc dot gnu.org
2022-01-20 10:46 ` rguenth at gcc dot gnu.org
2022-05-27  9:46 ` [Bug rtl-optimization/101995] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:46 ` jakub at gcc dot gnu.org
2023-07-07 10:40 ` [Bug rtl-optimization/101995] [11/12/13/14 " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-101995-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).