https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110414
Bug ID: 110414
Summary: [14 Regression] Dead Code Elimination Regression
since r14-1127-g9e2017ae6ac
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/5E795dPvY
Given the following code:
void foo(void);
static int a, b, e, l, m, n;
static int *c = &a, *j;
static int **d = &c;
static int ***f;
void __assert_fail(char *, char *, int, char *) __attribute__((__noreturn__));
static void g(char) {
if (c == &b || c == &a)
;
else
__assert_fail("", "", 3, __PRETTY_FUNCTION__);
}
static void h();
static int *i();
static short k() {
j = i();
h();
**f = &e;
if (c == &b || c == &a || c == 0)
__assert_fail("", "", 6, __PRETTY_FUNCTION__);
return 0;
}
static void h() {
if (l) {
for (; l; l = l - 8) *d = &m;
if (c == &a)
;
else
__assert_fail("", "", 9, __PRETTY_FUNCTION__);
}
if (c == &b || c == &a || c == 0)
;
else {
foo();
__assert_fail("", "", 8, __PRETTY_FUNCTION__);
}
}
static int *i() {
if (c == &b || c == &a)
;
else {
__builtin_unreachable();
__assert_fail("", "", 6, __PRETTY_FUNCTION__);
}
return &n;
}
int main() { g(a && k()); }
gcc-trunk -Os does not eliminate the call to foo:
main:
pushq %rcx
cmpl $0, a(%rip)
je .L2
movl l(%rip), %edx
testl %edx, %edx
je .L3
movl %edx, %eax
movl $__PRETTY_FUNCTION__.1, %ecx
movq $m, c(%rip)
shrl $3, %eax
imull $-8, %eax, %eax
addl %edx, %eax
movl $9, %edx
movl %eax, l(%rip)
jmp .L7
.L3:
movq c(%rip), %rax
cmpq $a, %rax
sete %dl
cmpq $b, %rax
sete %cl
orb %cl, %dl
jne .L4
testq %rax, %rax
je .L4
call foo
movl $__PRETTY_FUNCTION__.1, %ecx
movl $8, %edx
.L7:
movl $.LC0, %esi
movq %rsi, %rdi
call __assert_fail
.L4:
movl $__PRETTY_FUNCTION__.2, %ecx
movl $6, %edx
jmp .L7
.L2:
movq c(%rip), %rax
cmpq $a, %rax
je .L5
cmpq $b, %rax
je .L5
movl $__PRETTY_FUNCTION__.0, %ecx
movl $3, %edx
jmp .L7
.L5:
xorl %eax, %eax
popq %rdx
ret
gcc-13.1.0 -Os eliminates the call to foo:
main:
pushq %rcx
movq c(%rip), %rdx
cmpq $a, %rdx
sete %al
cmpq $b, %rdx
sete %dl
orl %edx, %eax
cmpl $0, a(%rip)
je .L2
movl l(%rip), %edx
testl %edx, %edx
je .L3
movl %edx, %eax
movl $__PRETTY_FUNCTION__.1, %ecx
movq $m, c(%rip)
shrl $3, %eax
imull $-8, %eax, %eax
addl %edx, %eax
movl $9, %edx
movl %eax, l(%rip)
jmp .L7
.L2:
testb %al, %al
jne .L5
movl $__PRETTY_FUNCTION__.0, %ecx
movl $3, %edx
.L7:
movl $.LC0, %esi
movq %rsi, %rdi
call __assert_fail
.L3:
movl $__PRETTY_FUNCTION__.2, %ecx
movl $6, %edx
jmp .L7
.L5:
xorl %eax, %eax
popq %rdx
ret
Bisects to r14-1127-g9e2017ae6ac