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

            Bug ID: 112508
           Summary: [14 Regression] Size regression when using -Os
                    starting with r14-4089-gd45ddc2c04e
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: theodort at inf dot ethz.ch
  Target Milestone: ---

https://godbolt.org/z/qE79f7qvW

Given the following code:

static int b, c = 8, d, e, f, g = 9;
static char h = 3;
static void(a)(int, unsigned i) {
    if (!(((i) >= 1) && ((i) <= 3421036188))) {
        __builtin_unreachable();
    }
}
int main1() {
    for (; h; --h) {
        for (; f <= 9; f++) {
            if (d) g = 0;
            if (e) continue;
            a(b, g && c);
        }
        e = d = 0;
        a(0, 3421036188);
    }
}

gcc-trunk -Os generates more and more complex code:

main1:
        movl    d(%rip), %edi
        movl    g(%rip), %esi
        xorl    %edx, %edx
        xorl    %ecx, %ecx
        movb    h(%rip), %r8b
        movl    e(%rip), %r9d
        xorl    %r10d, %r10d
        movl    f(%rip), %eax
        testb   %r8b, %r8b
        jne     .L49
        testb   %r10b, %r10b
        je      .L37
        movb    $0, h(%rip)
        testb   %dl, %dl
        je      .L41
        movl    %eax, f(%rip)
        jmp     .L41
.L37:
        testb   %dl, %dl
        je      .L44
        movl    %eax, f(%rip)
        jmp     .L44
.L41:
        movl    %r9d, e(%rip)
        testb   %cl, %cl
        je      .L45
        movl    %esi, g(%rip)
.L45:
        movl    %edi, d(%rip)
        jmp     .L47
.L44:
        testb   %cl, %cl
        je      .L47
        movl    %esi, g(%rip)
.L47:
        xorl    %eax, %eax
        ret
.L49:
        pushq   %rbx
.L35:
        movl    %eax, %r11d
.L4:
        movl    %r11d, %eax
        cmpl    $9, %r11d
        jg      .L51
        testl   %edi, %edi
        je      .L3
        movb    $1, %cl
        xorl    %esi, %esi
.L3:
        movl    %esi, %ebx
        incl    %r11d
        orl     %r9d, %ebx
        jne     .L22
        testb   %r10b, %r10b
        je      .L5
        movb    %r8b, h(%rip)
        testb   %dl, %dl
        je      .L7
        movl    %eax, f(%rip)
        jmp     .L7
.L5:
        testb   %dl, %dl
        je      .L8
        movl    %eax, f(%rip)
        jmp     .L8
.L7:
        xorl    %esi, %esi
        movl    %esi, e(%rip)
        testb   %cl, %cl
        je      .L9
        xorl    %edx, %edx
        movl    %edx, g(%rip)
.L9:
        movl    %edi, d(%rip)
.L19:
.L22:
        movb    $1, %dl
        jmp     .L4
.L51:
        decl    %r8d
        xorl    %r9d, %r9d
        movb    $1, %r10b
        xorl    %edi, %edi
        testb   %r8b, %r8b
        jne     .L35
        testb   %r10b, %r10b
        je      .L12
        movb    $0, h(%rip)
        testb   %dl, %dl
        je      .L14
        movl    %r11d, f(%rip)
        jmp     .L14
.L12:
        testb   %dl, %dl
        je      .L16
        movl    %r11d, f(%rip)
        jmp     .L16
.L14:
        movl    %r9d, e(%rip)
        testb   %cl, %cl
        je      .L17
        movl    %esi, g(%rip)
.L17:
        movl    %edi, d(%rip)
        jmp     .L18
.L8:
        xorl    %eax, %eax
        movl    %eax, g(%rip)
        jmp     .L19
.L16:
        testb   %cl, %cl
        je      .L18
        movl    %esi, g(%rip)
.L18:
        xorl    %eax, %eax
        popq    %rbx
        ret


gcc-13 -Os -o 13.o test.c -c
gcc-trunk -Os -o 14.o test.c -c
size 13.o 14.o
   text    data     bss     dec     hex filename
    235       8      12     255      ff 13.o
    422       8      12     442     1ba 14.o



gcc-13.2.0 -Os:

main1:
        movb    h(%rip), %dil
        xorl    %r8d, %r8d
        xorl    %esi, %esi
        xorl    %ecx, %ecx
        movl    d(%rip), %edx
        movl    f(%rip), %eax
        movb    $1, %r9b
        xorl    %r11d, %r11d
        movl    $10, %r10d
.L2:
        testb   %dil, %dil
        je      .L5
        movl    %eax, %ecx
.L6:
        cmpl    $9, %ecx
        jg      .L25
        testl   %edx, %edx
        movb    $1, %r8b
        cmovne  %r9d, %esi
        incl    %ecx
        jmp     .L6
.L25:
        movl    %r10d, %edx
        movb    $1, %cl
        subl    %eax, %edx
        cmpl    $10, %eax
        cmovg   %r11d, %edx
        decl    %edi
        addl    %edx, %eax
        xorl    %edx, %edx
        jmp     .L2
.L5:
        testb   %cl, %cl
        je      .L7
        xorl    %edi, %edi
        movb    $0, h(%rip)
        movl    %edi, e(%rip)
.L7:
        testb   %r8b, %r8b
        je      .L8
        movl    %eax, f(%rip)
.L8:
        testb   %sil, %sil
        je      .L9
        xorl    %eax, %eax
        movl    %eax, g(%rip)
.L9:
        testb   %cl, %cl
        je      .L10
        movl    %edx, d(%rip)
.L10:
        ret


Bisects to r14-4089-gd45ddc2c04e

Reply via email to