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

            Bug ID: 110450
           Summary: [14 Regression] Dead Code Elimination Regression at
                    -O2 since r14-261-g0ef3756adf0
           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/KqcYxfevj

Given the following code:

void foo(void);
static int a = 1;
static int *b = &a, *c = &a;
static short d, e;
static char f = 11;
static char(g)(char h, int i) { return h << i; }
int main() {
    if (f) *c = g(0 >= a, 3);
    e = *c;
    d = e % f;
    if (d) {
        __builtin_unreachable();
    } else if (*b)
        foo();
    ;
}

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

main:
        movl    a(%rip), %eax
        xorl    %edx, %edx
        testl   %eax, %eax
        setle   %dl
        leal    0(,%rdx,8), %edx
        movl    %edx, a(%rip)
        jle     .L8
        xorl    %eax, %eax
        ret
.L8:
        pushq   %rax
        call    foo
        xorl    %eax, %eax
        popq    %rdx
        ret

gcc-13.1.0 -O2 eliminates the call to foo:

main:
        movl    a(%rip), %edx
        xorl    %eax, %eax
        testl   %edx, %edx
        setle   %al
        leal    0(,%rax,8), %eax
        movl    %eax, a(%rip)
        xorl    %eax, %eax
        ret

Bisects to r14-261-g0ef3756adf0

Reply via email to