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

            Bug ID: 107822
           Summary: Dead Code Elimination Regression at -Os (trunk vs.
                    12.2.0)
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yann at ywg dot ch
  Target Milestone: ---

Created attachment 53945
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53945&action=edit
Code

cat case.c #230636
int b;
void foo();
void(a)();
int main() {
  int c;
  int *d = &c;
  *d = a && 8;
  b = 0;
  for (; b < 9; ++b)
    *d ^= 3;
  if (*d)
    ;
  else
    foo();
}

`gcc-e4faee8d02ec5d65bf418612f7181823eb08c078 (trunk) -Os` can not eliminate
`foo` but `gcc-releases/gcc-12.2.0 -Os` can.

`gcc-e4faee8d02ec5d65bf418612f7181823eb08c078 (trunk) -Os -S -o /dev/stdout
case.c`
--------- OUTPUT ---------
main:
.LFB0:
        .cfi_startproc
        movl    $10, %edx
        xorl    %ecx, %ecx
        movl    $1, %eax
.L2:
        decl    %edx
        je      .L12
        xorl    $3, %eax
        movb    $1, %cl
        jmp     .L2
.L12:
        testb   %cl, %cl
        jne     .L4
        xorl    %esi, %esi
        movl    %esi, b(%rip)
        jmp     .L5
.L4:
        movl    $9, b(%rip)
.L5:
        testl   %eax, %eax
        jne     .L8
        pushq   %rdx
        .cfi_def_cfa_offset 16
        call    foo
        xorl    %eax, %eax
        popq    %rcx
        .cfi_def_cfa_offset 8
        ret
.L8:
        xorl    %eax, %eax
        ret
---------- END OUTPUT ---------


`gcc-releases/gcc-12.2.0 -Os -S -o /dev/stdout case.c`
--------- OUTPUT ---------
main:
.LFB0:
        .cfi_startproc
        movl    $9, b(%rip)
        xorl    %eax, %eax
        ret
---------- END OUTPUT ---------


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

Reply via email to