https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110269
Bug ID: 110269
Summary: 13/14 Regression] Missed Dead Code Elimination when
using __builtin_unreachable since
r13-4607-g2dc5d6b1e7e
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/5qqPMsxEh
Given the following code:
void foo(void);
static int a = 1, c;
static int *b = &a;
static int **d = &b;
static int ***e = &d;
void __assert_fail() __attribute__((__noreturn__));
static int f() {
if (a) return a;
for (; c;) *e = 0;
if (b) __assert_fail();
return 6;
}
int main() {
if (f()) {
*d = 0;
if (b == 0)
;
else {
__builtin_unreachable();
__assert_fail();
}
}
if (b == 0)
;
else
foo();
;
}
gcc-trunk -O3 generates:
main:
subq $8, %rsp
movl a(%rip), %eax
testl %eax, %eax
jne .L2
cmpq $0, b(%rip)
jne .L6
.L2:
movq d(%rip), %rax
movq $0, (%rax)
cmpq $0, b(%rip)
je .L3
call foo
.L3:
xorl %eax, %eax
addq $8, %rsp
ret
.L6:
xorl %eax, %eax
call __assert_fail
gcc-12.3.0 -O3 generates:
main:
movl a(%rip), %edx
testl %edx, %edx
jne .L2
cmpq $0, b(%rip)
jne .L7
.L2:
movq d(%rip), %rax
movq $0, (%rax)
xorl %eax, %eax
ret
.L7:
pushq %rax
xorl %eax, %eax
call __assert_fail
Bisects to r13-4607-g2dc5d6b1e7e