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

--- Comment #2 from Zhendong Su <zhendong.su at inf dot ethz.ch> ---
The following might be the same/related. The dead call is eliminated if b is
changed to:

static int b(int *c) {
    foo();
    d++;
}

[623] % gcctk -O3 -S small.c
[624] %
[624] % cat small.c
extern void foo(void);

static int a, d;

static int b(int *c) {
  while (1) {
    foo();
    d++;
  }
}

int main () {
  a && b(&a);
  return 0;
}
[625] %
[625] % cat small.s
        .file   "small.c"
        .text
        .section        .text.startup,"ax",@progbits
        .p2align 4
        .globl  main
        .type   main, @function
main:
.LFB1:  
        .cfi_startproc
        movl    a(%rip), %edx
        testl   %edx, %edx
        jne     .L7
        xorl    %eax, %eax
        ret
.L7:
        pushq   %rax
        .cfi_def_cfa_offset 16
.L3:
        call    foo
        addl    $1, d(%rip)
        jmp     .L3
        .cfi_endproc
.LFE1:  
        .size   main, .-main
        .local  d
        .comm   d,4,4
        .local  a
        .comm   a,4,4
        .ident  "GCC: (GNU) 11.0.1 20210304 (experimental) [master revision
cdfc2f6a6dc:ab3cea6cccd:f3641ac70eb0ae9f8983b7ddb1660c92439565de]"
        .section        .note.GNU-stack,"",@progbits

Reply via email to