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?