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

            Bug ID: 110963
           Summary: [14 Regression] Dead Code Elimination Regression since
                    r14-2946-g46c8c225455
           Product: gcc
           Version: 14.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: ---

https://godbolt.org/z/devdMf1qd

Given the following code:

void foo(void);
static int c = 76, f, g;
static int *h, *j, *k = &g;
static int **i = &h;
static short a;
static char(l)(char b) {
    if (!(((b) >= 77) && ((b) <= 77))) {
        __builtin_unreachable();
    }
    return 0;
}
static short(m)(short d, short e) { return d + e; }
static short n(char) {
    j = *i;
    if (j == 0)
        ;
    else
        *i = 0;
    *k = 0;
    return 0;
}
static char o() {
    l(0);
    return 0;
}
static char p(int ad) {
    a = m(!0, ad);
    l(a);
    if (f) {
        *i &&n(o());
        *i = 0;
    } else
        n(0);
    if (h == &f || h == 0)
        ;
    else
        foo();
    return 0;
}
int main() {
    p(c);
    c = 8;
}

gcc-trunk -O3 does not eliminate the call to foo:

main:
        movl    f(%rip), %edi
        testl   %edi, %edi
        je      .L11
.L7:
        movl    $8, c(%rip)
        xorl    %eax, %eax
        ret
.L11:
        cmpq    $0, h(%rip)
        je      .L4
        xorl    %esi, %esi
        movq    %rsi, h(%rip)
.L4:
        movq    h(%rip), %rax
        xorl    %ecx, %ecx
        movl    %ecx, g(%rip)
        testq   %rax, %rax
        je      .L7
        cmpq    $f, %rax
        je      .L7
        pushq   %rax
        call    foo
        xorl    %eax, %eax
        movl    $8, c(%rip)
        popq    %rdx
        ret

gcc-13.2.0 -O3 eliminates the call to foo:

main:
        movl    f(%rip), %ecx
        movq    h(%rip), %rax
        testl   %ecx, %ecx
        jne     .L3
        testq   %rax, %rax
        je      .L4
        xorl    %edx, %edx
        movq    %rdx, h(%rip)
.L4:
        xorl    %eax, %eax
        movl    %eax, g(%rip)
.L3:
        movl    $8, c(%rip)
        xorl    %eax, %eax
        ret

Bisects to r14-2946-g46c8c225455

Reply via email to