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

            Bug ID: 111801
           Summary: [14 Regression] Missed Dead Code Elimination since
                    r14-4141-gbf6b107e2a3
           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/47fbssWd3

Given the following code:

void foo(void);
static struct {
    signed a;
} b, c, *e = &b;
static struct {
    unsigned d;
} g = {109};
static int f;
static int *h;
static int **i = &h;
int main() {
    f = 1;
    if (b.a) f = 8;
    int *j = *i;
    if (j == &g == 0)
        if (!(((g.d) >= 109) && ((g.d) <= 109))) {
            __builtin_unreachable();
        }
    if (f)
        ;
    else {
        c = *e;
        foo();
    }
}

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

main:
        movl    $1, f(%rip)
        movl    b(%rip), %esi
        testl   %esi, %esi
        je      .L10
        movl    $8, f(%rip)
.L10:
        cmpq    $g, h(%rip)
        je      .L7
        movl    f(%rip), %ecx
        testl   %ecx, %ecx
        je      .L12
.L7:
        xorl    %eax, %eax
        ret
.L12:
        pushq   %rax
        call    foo
        xorl    %eax, %eax
        popq    %rdx
        ret

gcc-13.2.0 -O2 eliminates the call to foo:

main:
        movl    $1, f(%rip)
        movl    b(%rip), %eax
        testl   %eax, %eax
        je      .L2
        movl    $8, f(%rip)
.L2:
        xorl    %eax, %eax
        ret

Bisects to r14-4141-gbf6b107e2a3

Reply via email to