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

            Bug ID: 112545
           Summary: [14 Regression] Size regression when using -Os
                    starting with r14-569-g21e2ef2dc25
           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/hcq8sKhvP

Given the following code:

static struct {
    int a;
    int b;
} c;
static int d, e, g;
static short f, i;
static void h(unsigned short j) {
    c.a = i;
    if (!(((j) >= 1) && ((j) <= 65535))) {
        __builtin_unreachable();
    }
}
int main1() {
    d = 6;
    for (; d != -7; d--) {
        h(d ^ d < (0 <= 6));
        if (d >= 12)
            if (e) {
                for (; f; ++f) g = c.b;
                if (g) e = 0;
            }
    }
}

gcc-trunk -Os generates significantly more complex code:

main1:
        movl    e(%rip), %ecx
        movl    $6, %eax
        xorl    %edi, %edi
        xorl    %r8d, %r8d
        movl    c+4(%rip), %r10d
        movl    g(%rip), %esi
        xorl    %r9d, %r9d
        movl    $6, d(%rip)
        movw    f(%rip), %dx
.L2:
        cmpl    $-7, %eax
        je      .L31
        xorl    %r11d, %r11d
        testl   %eax, %eax
        setle   %r11b
        cmpw    %ax, %r11w
        jne     .L3
        testb   %r8b, %r8b
        je      .L4
        movl    %eax, d(%rip)
.L4:
        testb   %dil, %dil
        je      .L5
        movl    %ecx, e(%rip)
.L5:
        xorl    %ecx, %ecx
        movw    %dx, f(%rip)
        movl    %ecx, c(%rip)
        movl    %esi, g(%rip)
.L3:
        cmpl    $11, %eax
        jle     .L6
        testl   %ecx, %ecx
        je      .L6
.L7:
        testw   %dx, %dx
        je      .L32
        incl    %edx
        movl    %r10d, %esi
        movb    $1, %r9b
        jmp     .L7
.L32:
        testl   %esi, %esi
        je      .L6
        movb    $1, %dil
        xorl    %ecx, %ecx
.L6:
        decl    %eax
        movb    $1, %r8b
        jmp     .L2
.L31:
        testb   %r8b, %r8b
        je      .L10
        movl    $-7, d(%rip)
        testb   %dil, %dil
        je      .L11
        movl    %ecx, e(%rip)
.L11:
        xorl    %eax, %eax
        movl    %eax, c(%rip)
.L12:
        testb   %r9b, %r9b
        je      .L13
        movw    %dx, f(%rip)
        movl    %esi, g(%rip)
        jmp     .L13
.L10:
        testb   %dil, %dil
        je      .L12
        movl    %ecx, e(%rip)
        jmp     .L12
.L13:
        xorl    %eax, %eax
        ret


than gcc-13.2.0 -Os:

main1:
        movl    $-7, d(%rip)
        xorl    %eax, %eax
        movl    %eax, c(%rip)
        ret



Bisects to r14-569-g21e2ef2dc25

Reply via email to