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

            Bug ID: 102983
           Summary: [12 Regression] 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 test.c
void foo(void);

static int a = 1;

int main() {
  int c = 0;
  for (int b = 0; b <= 0; b++) {
    if (!a)
      foo();
    if (b > c){
      if (c)
        continue;
      a = 0;
    }
    c = 1;
  }
}

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

gcc-11 test.c -O3 -S -o /dev/stdout
...
main:
.LFB0:
        .cfi_startproc
        xorl    %eax, %eax
        ret
        .cfi_endproc


gcc-trunk test.c -O3 -S -o /dev/stdout
...
main:
.LFB0:
        .cfi_startproc
        movl    a(%rip), %ecx
        testl   %ecx, %ecx
        je      .L8
        xorl    %eax, %eax
        ret
.L8:
        pushq   %rax
        .cfi_def_cfa_offset 16
        call    foo
        xorl    %eax, %eax
        popq    %rdx
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc


gcc-trunk  -v
Using built-in specs.
Target: x86_64-pc-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.0.0 20211028 (experimental) (GCC)


Started with
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=398572c1544d8b7541862401b985ae7e855cb8fb

Reply via email to