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

            Bug ID: 110177
           Summary: [12/13/14 Regression] Missed Dead Code Elimination
                    when using __builtin_unreachable since
                    r12-2305-g398572c1544
           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/d6zscbYYh

void foo(void);
static int c, *d = &c, *f, *i;
static unsigned e;
static int **g = &d, **j = &f,***h = &g;
static short k;
void __assert_fail() __attribute__((__noreturn__));
static short(a)(short b) {
    if (b != 0) {
        __builtin_unreachable();
    }
    return 0;
}
int main() {
    c = 0;
    for (; c <= 20; c = c + 9) {
        k = c << e;
        c &&a(c >> k);
        i = **h;
        *j = i;
        if (f)
            ;
        else
            __assert_fail();
    }
    e = 0;
    if (f);
    else
        foo();
}

gcc-11.4 -Os generates:

main:
        movq    g(%rip), %rax
        movl    $0, c(%rip)
        movq    (%rax), %rdx
        movq    %rdx, f(%rip)
        testq   %rdx, %rdx
        je      .L2
        movq    (%rax), %rax
        movq    %rax, f(%rip)
        testq   %rax, %rax
        jne     .L8
        movl    $9, c(%rip)
.L2:
        pushq   %rax
        xorl    %eax, %eax
        call    __assert_fail
.L8:
        movl    $27, c(%rip)
        xorl    %eax, %eax
        movl    $0, e(%rip)
        ret

gcc-trunk -Os generates:

main:
        xorl    %edi, %edi
        pushq   %rsi
        movq    g(%rip), %r8
        xorl    %eax, %eax
        movl    %edi, c(%rip)
        movl    e(%rip), %edi
        xorl    %edx, %edx
.L2:
        movl    %eax, %esi
        cmpl    $27, %eax
        je      .L23
        testl   %eax, %eax
        je      .L3
        movl    %edi, %ecx
        movl    %eax, %r9d
        movl    %eax, %r10d
        sall    %cl, %r9d
        movl    %r9d, %ecx
        sarl    %cl, %r10d
        testl   %r10d, %r10d
        je      .L3
        movl    %eax, c(%rip)
.L3:
        movq    (%r8), %rcx
        addl    $9, %eax
        movq    %rcx, f(%rip)
        testq   %rcx, %rcx
        jne     .L8
        testb   %dl, %dl
        je      .L4
        movl    %esi, c(%rip)
.L4:
        xorl    %eax, %eax
        call    __assert_fail
.L8:
        movb    $1, %dl
        jmp     .L2
.L23:
        testb   %dl, %dl
        je      .L6
        movl    $27, c(%rip)
.L6:
        xorl    %ecx, %ecx
        cmpq    $0, f(%rip)
        movl    %ecx, e(%rip)
        jne     .L7
        call    foo
.L7:
        xorl    %eax, %eax
        popq    %rdx
        ret

Bisects to r12-2305-g398572c1544

Reply via email to