https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102546
Bug ID: 102546
Summary: Missed Dead Code Elimination regression (trunk vs
11.2.0) at -O3
Product: gcc
Version: 12.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: ---
cat missed_case.c
static int a;
static char b, c, d;
void bar(void);
void foo(void);
int main() {
int f = 0;
for (; f <= 5; f++) {
bar();
b = b && f;
d = f << f;
if (!(a >= d || f))
foo();
c = 1;
for (; c; c = 0)
;
}
}
11.2.0 at -O3 can eliminate the call to foo but trunk at -O3 cannot:
gcc-trunk -v
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.0.0 20210930 (experimental) (GCC)
gcc-trunk -O3 -S missed_case.c
main:
.LFB0:
.cfi_startproc
pushq %rbx
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
xorl %ebx, %ebx
.L6:
call bar
cmpb $0, b(%rip)
je .L2
testl %ebx, %ebx
jne .L5
movb $0, b(%rip)
movl $1, %ebx
movb $0, c(%rip)
call bar
cmpb $0, b(%rip)
je .L4
.L5:
movb $1, b(%rip)
.L4:
addl $1, %ebx
movb $0, c(%rip)
cmpl $6, %ebx
jne .L6
xorl %eax, %eax
popq %rbx
.cfi_remember_state
.cfi_def_cfa_offset 8
ret
.p2align 4,,10
.p2align 3
.L2:
.cfi_restore_state
movl %ebx, %eax
movl %ebx, %ecx
sall %cl, %eax
testb %al, %al
jle .L4
testl %ebx, %ebx
jne .L4
call foo
movb $0, c(%rip)
movl $1, %ebx
call bar
cmpb $0, b(%rip)
jne .L5
jmp .L2
.cfi_endproc
gcc-11 -v
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)
cat missed_case.s
main:
.LFB0:
.cfi_startproc
pushq %rbx
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
movl $5, %ebx
call bar
movb $0, b(%rip)
movb $0, c(%rip)
.p2align 4,,10
.p2align 3
.L2:
call bar
cmpb $0, b(%rip)
movb $0, c(%rip)
setne b(%rip)
subl $1, %ebx
jne .L2
xorl %eax, %eax
popq %rbx
.cfi_def_cfa_offset 8
ret
.cfi_endproc