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

--- Comment #7 from Thibaut M. <dumoulin.thibaut at gmail dot com> ---
There are other regressions (in term of code size) but not sure if this is the
same.
For example, this code:

```C
#include <stdio.h>

void big_switch(int a) {
  switch (a) {
  default:
    printf("default a(%d)\n", a);
  case 0x1:
  case 0x2:
  // case 0x3:
  // case 0x4:
  case 0x5:
  case 0x6:
  // case 0x7:
  // case 0x8:
  // case 0x9:
  case 0xA:
  case 0xD:
  case 0xE:
  case 0xF:
  // case 0x10:
  case 0x11:
  case 0x12:
  // case 0x13:
  // case 0x14:
  case 0x15:
  case 0x17:
  case 0x18:
  case 0x19:
  case 0x1A:
  // case 0x1B:
  case 0x1C:
  case 0x1D: {
    printf("a(%d)\n", a);
  } break;
  }
}

int main(void) {
  big_switch(2);
  return 0;
}
```

with compile parameters `arm-none-eabi-gcc -Os -mcpu=cortex-m4 ./switch.c`
the asm is lighter with GCC7.3.1 than with GCC10.3.1.


While GCC7.3.1 (20 lines)
```asm
00008134 <big_switch>:
    cmp     r0, #29
    push    {r4, lr}
    mov     r4, r0
    bhi.n   8146 <big_switch+0x12>
    movs    r2, #1
    ldr     r3, [pc, #28]   ; (815c <big_switch+0x28>)
    lsls    r2, r0
    ands    r3, r2
    cbnz    r3, 814e <big_switch+0x1a>
    mov     r1, r4
    ldr     r0, [pc, #20]   ; (8160 <big_switch+0x2c>)
    bl      8264 <printf>
    mov     r1, r4
    ldr     r0, [pc, #16]   ; (8164 <big_switch+0x30>)
    ldmia.w sp!, {r4, lr}
    b.w     8264 <printf>
    nop
    .word   0x37a6e466
    .word   0x0000f5f8
    .word   0x0000f600
```

GCC10.3.1 (24 lines)
```asm
0000813c <big_switch>:
    subs    r3, r0, #1
    push    {r4, lr}
    mov     r4, r0
    cmp     r3, #28
    bhi.n   8168 <big_switch+0x2c>
    tbb     [pc, r3]
    .short  0x1313
    .word   0x13130f0f
    .word   0x130f0f0f
    .word   0x13130f0f
    .word   0x13130f13
    .word   0x0f130f0f
    .word   0x13131313
    .short  0x130f
    .byte   0x13
    .byte   0x00
    mov     r1, r0
    ldr     r0, [pc, #16]   ; (817c <big_switch+0x40>)
    bl      828c <printf>
    mov     r1, r4
    ldr     r0, [pc, #8]    ; (817c <big_switch+0x40>)
    ldmia.w sp!, {r4, lr}
    b.w     828c <printf>
    .word   0x0001011c
```

Not a big difference in term of instructions is this case but as much as the
switch increases, the difference becomes huge (in my case it switched from 75
to 94 lines)
Code size increases of about 10%.


@Martin, do you know if this is linked?

Reply via email to