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

            Bug ID: 111799
           Summary: [14 Regression] Missed Dead Code Elimination since
                    r14-2365-g2e406f0753e
           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/bqcvMcbqn

Given the following code:

void foo(void);
static struct d {
    short e;
} g = {205}, *h = &g;
static int i;
static int *j, *a = &i;
static int **k = &j;
static int ****l;
static int *****m;
static char(n)(char b, char c) { return b + c; }
static char(o)(char b, char c) { return b * c; }
static short(p)(short f) {
    if (!(((f) >= 1) && ((f) <= 65459))) {
        __builtin_unreachable();
    }
    return 0;
}
static int *q(short);
static void s(struct d) { *k = q(i); }
static int *q(short ad) {
    int b = *a;
    ad = -21;
    for (; ad; ad = n(ad, 7)) p((ad ^ b && *a) <= *a);
    return *k;
}
int main() {
    i = 0;
    for (;; i = 1) {
        q(3);
        char r = o(126 | 1, g.e);
        p(r);
        s(*h);
        if (i) break;
        m = &l;
    }
    if (m)
        ;
    else
        foo();
    ;
}

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

main:
        movl    $2, %esi
        xorl    %ecx, %ecx
        xorl    %r9d, %r9d
        movl    $8, %edi
        movl    $0, i(%rip)
        .p2align 4,,10
        .p2align 3
.L10:
        movl    $-21, %eax
.L2:
        testl   %ecx, %ecx
        je      .L29
        leal    7(%rax), %edx
        movsbw  %dl, %r8w
        testb   %dl, %dl
        je      .L23
.L5:
        movl    $8, %eax
        cmpb    $1, %dl
        je      .L2
        movl    %r8d, %eax
        leal    7(%rax), %edx
        movsbw  %dl, %r8w
        testb   %dl, %dl
        jne     .L5
        .p2align 4,,10
        .p2align 3
.L23:
        movl    $-21, %eax
        addb    $7, %al
        je      .L30
.L9:
        movsbl  %al, %edx
        cmpl    %edx, %ecx
        cmove   %edi, %eax
        cbtw
        addb    $7, %al
        jne     .L9
.L30:
        cmpl    $1, %esi
        je      .L31
        movl    $1, %esi
        movl    $1, %ecx
        movl    $1, %r9d
        jmp     .L10
        .p2align 4,,10
        .p2align 3
.L29:
        testb   $1, %al
        je      .L4
        leal    7(%rax), %edx
        movsbw  %dl, %ax
        testb   %dl, %dl
        je      .L23
.L4:
        leal    14(%rax), %edx
        movsbw  %dl, %ax
        testb   %dl, %dl
        jne     .L4
        jmp     .L23
        .p2align 4,,10
        .p2align 3
.L31:
        testb   %r9b, %r9b
        je      .L11
        movq    $l, m(%rip)
        movl    %ecx, i(%rip)
.L25:
        xorl    %eax, %eax
        ret
.L11:
        cmpq    $0, m(%rip)
        jne     .L25
        pushq   %rax
        call    foo
        xorl    %eax, %eax
        popq    %rdx
        ret

gcc-13.2.0 -O2 eliminates the call to foo:

main:
        movq    $l, m(%rip)
        xorl    %eax, %eax
        movl    $1, i(%rip)
        ret

Bisects to r14-2365-g2e406f0753e

Reply via email to