public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/101981] New: GCC10 produces bigger asm for simple switch than GCC7 - cortexM4
@ 2021-08-19 14:55 dumoulin.thibaut at gmail dot com
  2021-08-20  8:30 ` [Bug target/101981] " rguenth at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: dumoulin.thibaut at gmail dot com @ 2021-08-19 14:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101981
           Summary: GCC10 produces bigger asm for simple switch than GCC7
                    - cortexM4
           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 for very
simple switch statements.

Here is the C code example to trigger the regression:

*file: switch.c*
```C
int switchFunction(int foo) {
  switch (foo) {
  case 0:
    return 0;
  case 1:
    return 1;
  default:
    return -1;
  }
}

int main() {
  return 0;
}
```
To reproduce, I downloaded the toolchain from here
https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads

Compile command: `arm-none-eabi-gcc -Os -mcpu=cortex-m4 ./switch.c`

For GCC7 (arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors
7-2018-q2-update) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision
261907]) it produces this assembly code:
```asm
000080f8 <switchFunction>:
    80f8:       2801            cmp     r0, #1
    80fa:       bf88            it      hi
    80fc:       f04f 30ff       movhi.w r0, #4294967295 ; 0xffffffff
    8100:       4770            bx      lr
```

While GCC10 (arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.07) 10.3.1
20210621 (release)) produces one more line (25% bigger):
```asm
00008100 <switchFunction>:
    8100:       b118            cbz     r0, 810a <switchFunction+0xa>
    8102:       2801            cmp     r0, #1
    8104:       bf18            it      ne
    8106:       f04f 30ff       movne.w r0, #4294967295 ; 0xffffffff
    810a:       4770            bx      lr
```

Note: GCC10 produces the same code as if it was a simple `if`:
```C
int ifFunction(int foo) {
  if (foo == 0) {
    return 0;
  } else if (foo == 1) {
    return 1;
  } else {
    return -1;
  }
}
```

Shouldn't GCC10 produces the same code as GCC7?

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

end of thread, other threads:[~2021-11-04 12:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-19 14:55 [Bug c/101981] New: GCC10 produces bigger asm for simple switch than GCC7 - cortexM4 dumoulin.thibaut at gmail dot com
2021-08-20  8:30 ` [Bug target/101981] " rguenth at gcc dot gnu.org
2021-08-20 12:12 ` dumoulin.thibaut at gmail dot com
2021-08-20 13:13 ` marxin at gcc dot gnu.org
2021-08-20 14:20 ` [Bug target/101981] GCC10 produces bigger asm for simple switch than GCC7 - cortexM4 since r8-2701-g9dc3d6a96167b4c8 marxin at gcc dot gnu.org
2021-08-20 15:16 ` dumoulin.thibaut at gmail dot com
2021-08-25 14:01 ` marxin at gcc dot gnu.org
2021-09-09 12:51 ` dumoulin.thibaut at gmail dot com
2021-09-14 12:53 ` marxin at gcc dot gnu.org
2021-09-14 12:56 ` marxin at gcc dot gnu.org
2021-11-04 12:53 ` marxin 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).