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

            Bug ID: 110932
           Summary: [14 Regression] Dead Code Elimination Regression since
                    r14-2230-g7e904d6c7f2
           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/fs5obnhPP

Given the following code:

void foo(void);
static short a;
static int b, c, f, h, i, k;
static char d, m;
static int *j, *o = &f;
static int **l = &j, **n = &j;
static unsigned p(short g, short) { return g; }
static short(q)(unsigned e) {
    if (!(((e) >= 1) && ((e) <= 65531))) {
        __builtin_unreachable();
    }
    return 0;
}
static short r() {
    q(&k != 0 | f);
    *l = o;
    return h;
}
static int *s() {
    m = c ?: d ?: m;
    b = b ?: a;
    a = 0;
    return *l;
}
int main() {
    char t = 0;
    for (; t <= 4; t = t + 2) {
        int *u = &i;
        if (p(~(r() <= t), *u) > i == i) {
            **n = -5L;
            if (*u) continue;
            **n = 0;
            if (t) foo();
            break;
        }
        s();
        *u = u != 0;
    }
    s();
    h = 0;
}

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

main:
        subq    $8, %rsp
        movl    h(%rip), %ecx
        xorl    %edx, %edx
        movl    i(%rip), %eax
        movq    $f, j(%rip)
        testw   %cx, %cx
        setle   %dl
        notl    %edx
        movswl  %dx, %edx
        cmpl    %edx, %eax
        setb    %dl
        movzbl  %dl, %edx
        cmpl    %eax, %edx
        jne     .L22
        testl   %eax, %eax
        jne     .L23
        xorl    %edx, %edx
        movl    %edx, f(%rip)
        jmp     .L14
.L22:
        xorl    %eax, %eax
        call    s.isra.0
        movl    $1, %eax
        movl    $1, i(%rip)
.L6:
        movq    $f, j(%rip)
        xorl    %edx, %edx
        cmpw    $2, %cx
        setle   %dl
        notl    %edx
        movswl  %dx, %edx
        cmpl    %edx, %eax
        setb    %dl
        movzbl  %dl, %edx
        cmpl    %edx, %eax
        je      .L8
        xorl    %eax, %eax
        call    s.isra.0
        movl    $1, %eax
        movl    $1, i(%rip)
.L9:
        movq    $f, j(%rip)
        xorl    %edx, %edx
        cmpw    $4, %cx
        setle   %dl
        notl    %edx
        movswl  %dx, %edx
        cmpl    %edx, %eax
        setb    %dl
        movzbl  %dl, %edx
        cmpl    %edx, %eax
        jne     .L11
        testl   %eax, %eax
        je      .L10
        movl    $-5, f(%rip)
        jmp     .L14
.L8:
        testl   %eax, %eax
        jne     .L24
.L10:
        xorl    %eax, %eax
        movl    %eax, f(%rip)
        call    foo
.L14:
        xorl    %eax, %eax
        call    s.isra.0
        xorl    %eax, %eax
        movl    $0, h(%rip)
        addq    $8, %rsp
        ret
.L11:
        xorl    %eax, %eax
        call    s.isra.0
        movl    $1, i(%rip)
        jmp     .L14
.L23:
        movl    $-5, f(%rip)
        jmp     .L6
.L24:
        movl    $-5, f(%rip)
        jmp     .L9

gcc-13.2.0 -O3 eliminates the call to foo:

main:
        xorl    %eax, %eax
        cmpw    $0, h(%rip)
        movl    i(%rip), %edx
        movq    $f, j(%rip)
        setle   %al
        notl    %eax
        cwtl
        cmpl    %eax, %edx
        setb    %al
        movzbl  %al, %eax
        cmpl    %edx, %eax
        jne     .L11
        testl   %edx, %edx
        jne     .L6
.L7:
        xorl    %eax, %eax
        movl    %edx, f(%rip)
        call    s.isra.0
        xorl    %eax, %eax
        movl    $0, h(%rip)
        ret
.L11:
        xorl    %eax, %eax
        call    s.isra.0
        movl    $1, i(%rip)
.L6:
        movq    $f, j(%rip)
        movl    $-5, %edx
        jmp     .L7

Bisects to r14-2230-g7e904d6c7f2

Reply via email to