https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110327
Bug ID: 110327 Summary: [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-4790-g4b3a325f07a 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/eT1jqzrT5 Given the following code: void foo(void); static int a, c; static int *d, *e = &a; static int **f = &d, **g = &e; static int ***h = &g; static int ****i = &h; static short j; static char(k)(char b) { if (!(((b) >= -28) && ((b) <= -28))) { __builtin_unreachable(); } return 0; } static int l() { a = -28; for (; a != 2; a++) { j = c; c = 0; for (; c != 2; c = j) if (a) break; k(****i); if (****i >= 5 ^ 1) { ***i = *f; if (c < 1) return 1; if (a) foo(); ; } } return a; } int main() { l(); } gcc-trunk -O2 does not eliminate the call to foo: main: subq $8, %rsp movl $-28, %eax movl $-28, a(%rip) .p2align 4,,10 .p2align 3 .L10: movl c(%rip), %edx testl %eax, %eax jne .L19 cmpw $2, %dx je .L4 .L5: jmp .L5 .p2align 4,,10 .p2align 3 .L4: movl $2, c(%rip) movl $2, %esi .L3: movq h(%rip), %rdx movq (%rdx), %rdx movq (%rdx), %rcx cmpl $4, (%rcx) jg .L7 movq d(%rip), %rcx movq %rcx, (%rdx) testl %esi, %esi je .L16 testl %eax, %eax jne .L20 .L7: movl a(%rip), %eax addl $1, %eax movl %eax, a(%rip) cmpl $2, %eax jne .L10 .L16: xorl %eax, %eax addq $8, %rsp ret .p2align 4,,10 .p2align 3 .L20: call foo jmp .L7 .L19: xorl %edx, %edx xorl %esi, %esi movl %edx, c(%rip) jmp .L3 gcc-11.4.0 -O2 eliminates the call to foo: main: movl $-28, a(%rip) movq h(%rip), %rcx movl $-28, %edx .p2align 4,,10 .p2align 3 .L8: movzwl c(%rip), %eax movl $0, c(%rip) testl %edx, %edx jne .L2 .p2align 4,,10 .p2align 3 .L3: cmpw $2, %ax jne .L3 movl $2, c(%rip) movq (%rcx), %rax movq (%rax), %rdx cmpl $4, (%rdx) jg .L5 movq d(%rip), %rdx movq %rdx, (%rax) .L5: movl a(%rip), %eax leal 1(%rax), %edx movl %edx, a(%rip) cmpl $2, %edx jne .L8 .L13: xorl %eax, %eax ret .L2: movq (%rcx), %rax movq (%rax), %rdx cmpl $4, (%rdx) jg .L5 movq d(%rip), %rdx movq %rdx, (%rax) jmp .L13 Bisects to r12-4790-g4b3a325f07a