https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110080
Bug ID: 110080 Summary: [13/14 Regression] Missed Dead Code Elimination at -Os when using __builtin_unreachable since r13-6945-g429a7a88438 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: --- Given: void foo(void); static unsigned char a = 131; static int *b; static int **c = &b; static void d(int e, unsigned f) { int *g; if (e){ for (; a; ++a) for (e = 0; 0;) ; g = &e; int **h = &g; if (**h) { foo(); } } *c = &e; } int main() { d(4 & a, a); } gcc trunk/13.1/12.3 at -Os generate: main: testb $4, a(%rip) je .L3 movb $0, a(%rip) .L3: leaq -4(%rsp), %rax movq %rax, b(%rip) xorl %eax, %eax ret a: .byte -125 If I include a __builtin_unreachable() to help the compiler: void foo(void); static unsigned char a = 131; static int *b; static int **c = &b; static void d(int e, unsigned f) { int *g; if (f != 131) { __builtin_unreachable(); // <- THIS } if (!e){ for (; a; ++a) for (e = 0; 0;) ; g = &e; int **h = &g; if (**h) { foo(); } } *c = &e; } int main() { d(4 & a, a); } gcc-12.3 at -Os generates better code: main: leaq -4(%rsp), %rax movb $0, a(%rip) movq %rax, b(%rip) xorl %eax, %eax ret a: .byte -125 But gcc-13.1/trunk at -Os generate worse code: main: subq $24, %rsp movb a(%rip), %al movl %eax, %edx andl $4, %edx movl %edx, 12(%rsp) xorl %edx, %edx .L2: testb %al, %al je .L8 incl %eax movb $1, %dl jmp .L2 .L8: testb %dl, %dl je .L4 movb $0, a(%rip) jmp .L5 .L4: cmpl $0, 12(%rsp) je .L5 call foo .L5: leaq 12(%rsp), %rax movq %rax, b(%rip) xorl %eax, %eax addq $24, %rsp ret a: .byte -125 https://godbolt.org/z/zvqshjEj3 Started with r13-6945-g429a7a88438