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

            Bug ID: 110891
           Summary: [14 Regression] Dead Code Elimination Regression since
                    r14-2674-gd0de3bf9175
           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/njdE3xof4

Given the following code:

void foo(void);
static int a, c = 7, d, o, q;
static int *b = &a, *f, *j = &d, *n = &c, *ae;
static short e, m;
static short *i = &e;
static char r;
void __assert_fail(char *, char *, int, char *) __attribute__((__noreturn__));
static const short g();
static void h();
static int *k(int) {
    (*i)++;
    *j ^= *b;
    return &a;
}
static void l(unsigned p) {
    int *aa = &o;
    h();
    o = 5 ^ g() && p;
    if (f == &d || f == &c || f == &a)
        ;
    else {
        foo();
        __assert_fail("", "", 3, __PRETTY_FUNCTION__);
    }
    *aa ^= *n;
    if (*aa)
        if (!(((p) >= 0) && ((p) <= 0))) {
            __builtin_unreachable();
        }
    k(p);
}
static const short g() { return q; }
static void h() {
    unsigned ag = c;
    d = ag > r ? ag : 0;
    ae = k(c);
    f = ae;
    if (ae == &d || ae == &c || ae == &a)
        ;
    else
        __assert_fail("", "", 4, __PRETTY_FUNCTION__);
}
int main() {
    l(a);
    m || (*b |= 64);
    *b &= 5;
}

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

main:
        subq    $8, %rsp
        movl    c(%rip), %eax
        movl    %eax, d(%rip)
        call    k.isra.0
        cmpq    $c, %rax
        movq    %rax, f(%rip)
        sete    %cl
        cmpq    $a, %rax
        sete    %dil
        cmpq    $d, %rax
        sete    %dl
        orb     %cl, %dl
        jne     .L4
        testb   %dil, %dil
        je      .L15
.L4:
        cmpq    $d, %rax
        je      .L6
        testb   %cl, %cl
        jne     .L6
        testb   %dil, %dil
        je      .L16
.L6:
        call    k.isra.0
        andl    $5, a(%rip)
        xorl    %eax, %eax
        addq    $8, %rsp
        ret
.L16:
        call    foo
        movl    $.LC0, %esi
        movl    $__PRETTY_FUNCTION__.1, %ecx
        movl    $3, %edx
        movq    %rsi, %rdi
        call    __assert_fail
.L15:
        movl    $.LC0, %esi
        movl    $__PRETTY_FUNCTION__.0, %ecx
        movl    $4, %edx
        movq    %rsi, %rdi
        call    __assert_fail

gcc-13.2.0 -O2 eliminates the call to foo:

main:
        subq    $8, %rsp
        movl    c(%rip), %eax
        movl    %eax, d(%rip)
        call    k.isra.0
        cmpq    $c, %rax
        movq    %rax, f(%rip)
        sete    %dl
        cmpq    $d, %rax
        sete    %cl
        orb     %cl, %dl
        jne     .L4
        cmpq    $a, %rax
        jne     .L6
.L4:
        call    k.isra.0
        andl    $5, a(%rip)
        xorl    %eax, %eax
        addq    $8, %rsp
        ret
.L6:
        movl    $.LC0, %esi
        movl    $__PRETTY_FUNCTION__.0, %ecx
        movl    $4, %edx
        movq    %rsi, %rdi
        call    __assert_fail

Bisects to r14-2674-gd0de3bf9175

Reply via email to