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

            Bug ID: 105832
           Summary: Dead Code Elimination Regression at -O3 (trunk vs.
                    12.1.0)
           Product: gcc
           Version: 13.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: ---

cat case.c #2
void foo(void);

static struct {
    short a;
    char b;
} c;

static char d;

int main() {
    char g = c.b > 4U ? c.b : c.b << 2;
    for (int h = 0; h < 5; h++) {
        d = (g >= 2 || 1 >> g) ? g : g << 1;
        if (d && 1 == g)
            foo();
        c.a = 0;
    }
}

`gcc-1982fe2692b6c3b7f969ffc4edac59f9d4359e91 (trunk) -O3` can not eliminate
`foo` but `gcc-releases/gcc-12.1.0 -O3` can.

`gcc-1982fe2692b6c3b7f969ffc4edac59f9d4359e91 (trunk) -O3 -S -o /dev/stdout
case.c`
--------- OUTPUT ---------
main:
.LFB0:
        .cfi_startproc
        movsbl  c+2(%rip), %edx
        movl    %edx, %eax
        sall    $2, %edx
        cmpb    $5, %al
        cmovb   %edx, %eax
        cmpb    $1, %al
        jle     .L3
.L13:
        xorl    %eax, %eax
        movw    %ax, c(%rip)
        xorl    %eax, %eax
        ret
.L3:
        movsbl  %al, %edx
        addl    %edx, %edx
        testb   %al, %al
        cmove   %eax, %edx
        testb   %dl, %dl
        je      .L13
        subb    $1, %al
        jne     .L13
        pushq   %rbx
        .cfi_def_cfa_offset 16
        .cfi_offset 3, -16
        movl    $5, %ebx
.L6:
        call    foo
        movw    $0, c(%rip)
        subl    $1, %ebx
        jne     .L6
        xorl    %eax, %eax
        popq    %rbx
        .cfi_def_cfa_offset 8
        ret
---------- END OUTPUT ---------


`gcc-releases/gcc-12.1.0 -O3 -S -o /dev/stdout case.c`
--------- OUTPUT ---------
main:
.LFB0:
        .cfi_startproc
        xorl    %eax, %eax
        movw    %ax, c(%rip)
        xorl    %eax, %eax
        ret
---------- END OUTPUT ---------


Bisects to:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=a1c9f779f75283427316b5c670c1e01ff8ce9ced

Reply via email to