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

            Bug ID: 110503
           Summary: [13/14 Regression] Dead Code Elimination Regression at
                    -O3 since  r13-322-g7f04b0d786e
           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/h3G76EEW5

Given the following code:

void foo(void);
static int f = 10, g, h;
static int *i = &g, *j = &f, *k = &h;
static char(a)(int b) {
    if (!(((b) >= 1) && ((b) <= 3))) {
        __builtin_unreachable();
    }
    return 0;
}
static char(c)(char d, char e) { return d % e; }
static void l() {
    char m, n;
    unsigned o;
    int *p = &g;
    o = -19;
    for (; o > 22; o = o + 8) {
        int *q = &g;
        g = 30;
        unsigned char d = 60, e = o;
        m = d / e;
        if ((0 || *q) & m == 0)
            ;
        else {
            foo();
            n = c(0 != p, *p);
            a(n);
            *q = 0;
        }
    }
    *i = a(3);
    *k = 0 != *j;
}
int main() {
    l();
    a(h);
}

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

main:
        pushq   %rbx
        movl    $-19, %ebx
        jmp     .L5
        .p2align 4,,10
        .p2align 3
.L8:
        call    foo
        addl    $8, %ebx
.L5:
        movl    $30, g(%rip)
        cmpb    $60, %bl
        jbe     .L8
        addl    $8, %ebx
        cmpl    $5, %ebx
        jne     .L5
        movl    f(%rip), %edx
        xorl    %eax, %eax
        popq    %rbx
        movl    $0, g(%rip)
        testl   %edx, %edx
        setne   %al
        movl    %eax, h(%rip)
        xorl    %eax, %eax
        ret

gcc-12.3.0 -O3 eliminates the call to foo:

main:
        movl    f(%rip), %edx
        xorl    %eax, %eax
        movl    $0, g(%rip)
        testl   %edx, %edx
        setne   %al
        movl    %eax, h(%rip)
        xorl    %eax, %eax
        ret

Bisects to r13-322-g7f04b0d786e

Reply via email to