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

            Bug ID: 102648
           Summary: Dead Code Elimination Regression at -O3 (trunk vs
                    11.2.0)
           Product: gcc
           Version: 12.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   
void foo(void);
static int b, c, d = 40000;
static short e;
unsigned char f = 1;
static short a(short f, short g) { return f * g; }
int main() {
    for (; e; e++) {
        c = 0;
        while (c - 1)
            if (a(d, !f) > 1)
                foo();
    }
    return 0;
}

11.2.0 at -O3 can eliminate the call to foo but trunk at -O3 cannot:

gcc-11 -v
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)


gcc-11 -O3 case.c -S -o /dev/stdout
...
main:
.LFB1:
        .cfi_startproc
        cmpw    $0, e(%rip)
        je      .L2
        movl    $0, c(%rip)
.L3:
        jmp     .L3
        .p2align 4,,10
        .p2align 3
.L2:
        xorl    %eax, %eax
        ret

gcc-trunk -v
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++ 
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.0.0 20211008 (experimental) (GCC)

gcc-trunk -O3 case.c -S -o /dev/stdout
...
main:
.LFB1:
        .cfi_startproc
        cmpw    $0, e(%rip)
        movzbl  f(%rip), %edx
        je      .L12
        subq    $8, %rsp
        .cfi_def_cfa_offset 16
        .p2align 4,,10
        .p2align 3
.L5:
        movl    $0, c(%rip)
        xorl    %eax, %eax
        testb   %dl, %dl
        sete    %al
        imulw   $-25536, %ax, %ax
        cmpw    $1, %ax
        jg      .L15
.L3:
.L10:
        jmp     .L10
        .p2align 4,,10
        .p2align 3
.L15:
        call    foo
        cmpl    $1, c(%rip)
        movzbl  f(%rip), %edx
        jne     .L3
        addw    $1, e(%rip)
        jne     .L5
        xorl    %eax, %eax
        addq    $8, %rsp
        .cfi_def_cfa_offset 8
        ret
.L12:
        xorl    %eax, %eax
        ret


704e8a825c78b9a8424c291509413bbb48e602c7 introduced this regression

Reply via email to