https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109588
Bug ID: 109588 Summary: [13 Regression] Missed Dead Code Elimination when using __builtin_unreachable Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: theodort at inf dot ethz.ch Target Milestone: --- void foo(void); static int a, b; static int *c = &b; static int **d, **e = &c; int main() { if (b) { int *f = &a; if (a) *e = f = *d; if (f == &a) ; else foo(); } } both gcc trunk and 12.2 at -O3 generate: main: movl b(%rip), %eax testl %eax, %eax je .L2 cmpl $0, a(%rip) je .L2 movq 0, %rax ud2 .L2: xorl %eax, %eax ret Annotating a dead branch with __builting_unreachable(): void foo(void); static int a, b; static int *c = &b; static int **d, **e = &c; int main() { if (b) { int *f = &a; if (a) *e = f = *d; if (f == &a) __builtin_unreachable(); else foo(); } } gcc trunk -O3 now generates: main: movl b(%rip), %ecx testl %ecx, %ecx je .L5 cmpl $0, a(%rip) je .L3 movq 0, %rax ud2 .L3: pushq %rax call foo xorl %eax, %eax popq %rdx ret .L5: xorl %eax, %eax ret but gcc 12 generates: main: movl b(%rip), %eax testl %eax, %eax je .L2 movq 0, %rax ud2 .L2: xorl %eax, %eax ret