https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110361
Bug ID: 110361 Summary: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b 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/qab3679sq Given the following code: void foo(void); static int a, b, d, p, k; static int *c, *e, *g; static short f; static unsigned h; static int **i = &c, **o = &g; void __assert_fail() __attribute__((__noreturn__)); static void j(char, unsigned r) { h = r == 0 ?: 2 % r; int l = h; if (!(((l) >= 1) && ((l) <= 1))) { __builtin_unreachable(); } int m; *i = &m; } static int *n(); static short q(short t) { *o = &p; return t; } static unsigned s() { int *j = n(); if (e == 0 || e == &a || e == &d) ; else __assert_fail(); return *j; } static int *n() { if (b) { if (c) __assert_fail(); e = 0; } return &k; } int main() { j(q(s()), f); if (e == 0 || e == &a || e == &d) ; else foo(); f = 0; } gcc-trunk -O2 does not eliminate the call to foo: main: subq $24, %rsp movq e(%rip), %rax movswl f(%rip), %edx testq %rax, %rax je .L2 cmpq $a, %rax je .L4 cmpq $d, %rax jne .L17 .L4: movq $p, g(%rip) testl %edx, %edx je .L18 leaq 12(%rsp), %rdx movq %rdx, c(%rip) cmpq $a, %rax je .L5 cmpq $d, %rax je .L5 call foo .L5: xorl %eax, %eax movw %ax, f(%rip) xorl %eax, %eax addq $24, %rsp ret .L18: leaq 12(%rsp), %rax movq %rax, c(%rip) jmp .L5 .L2: movq $p, g(%rip) leaq 12(%rsp), %rax movq %rax, c(%rip) jmp .L5 .L17: xorl %eax, %eax call __assert_fail gcc-12.3.0 -O2 eliminates the call to foo: main: subq $24, %rsp movq e(%rip), %rax testq %rax, %rax je .L2 cmpq $a, %rax je .L2 cmpq $d, %rax jne .L14 .L2: movq $p, g(%rip) leaq 12(%rsp), %rax movq %rax, c(%rip) xorl %eax, %eax movw %ax, f(%rip) xorl %eax, %eax addq $24, %rsp ret .L14: xorl %eax, %eax call __assert_fail Bisects to r13-2020-g16b013c9d9b