[Bug tree-optimization/99357] New: Missed Dead Code Elimination Opportunity

2021-03-03 Thread theodoridisgr at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99357

Bug ID: 99357
   Summary: Missed Dead Code Elimination Opportunity
   Product: gcc
   Version: 11.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: theodoridisgr at gmail dot com
  Target Milestone: ---

Compiling the following code with -O3 -S

static int a = 0;
extern void bar(void);
int main() {
if (a)
bar();
a = 0;
return 0;
}

results in the following asm:

main:
.LFB0:
.cfi_startproc
movla(%rip), %ecx
testl   %ecx, %ecx
jne .L8
movl$0, a(%rip)
xorl%eax, %eax
ret
.L8:
pushq   %rax
.cfi_def_cfa_offset 16
callbar
xorl%eax, %eax
movl$0, a(%rip)
popq%rdx
.cfi_def_cfa_offset 8
ret
.cfi_endproc


Even though the branch calling bar is never executed, code for it is still
generated. If the a=0 assignment is removed, then the generated code is
simplified to:

main:
.LFB0:
.cfi_startproc
xorl%eax, %eax
ret
.cfi_endproc

gcc -v:
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: ../gcc_source/configure
Thread model: posix
gcc version 11.0.1 20210302 (experimental) (GCC)

[Bug tree-optimization/102540] New: Dead Code Elimination Regression at -O3 (trunk vs 11.2.0)

2021-09-30 Thread theodoridisgr at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102540

Bug ID: 102540
   Summary: Dead Code Elimination Regression at -O3 (trunk vs
11.2.0)
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: theodoridisgr at gmail dot com
  Target Milestone: ---

cat test.c
static long a;
static unsigned b;
void foo(void);
int main() {
long c, e;
c = b = a;
e = c ? 2 / (c + 1) : 0;
if (e && !b)
foo();
a = 0;
}

11.2.0 at -O3 can eliminate the call to foo but trunk at -O3 cannot:

gcc-11 -v
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)

gcc-11 test.c -S -O3
cat test.s
.file   "test.c"
.text
.section.text.startup,"ax",@progbits
.p2align 4
.globl  main
.type   main, @function
main:
.LFB0:
.cfi_startproc
movq$0, a(%rip)
xorl%eax, %eax
ret
.cfi_endproc
.LFE0:
.size   main, .-main
.local  a
.comm   a,8,8
.ident  "GCC: (GNU) 11.2.0"
.section.note.GNU-stack,"",@progbits


gcc-trunk -v
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 test.c -S -O3
cat test.s
.file   "test.c"
.text
.section.text.startup,"ax",@progbits
.p2align 4
.globl  main
.type   main, @function
main:
.LFB0:
.cfi_startproc
movqa(%rip), %rcx
movq%rcx, %rsi
andl$4294967295, %esi
je  .L13
movl$2, %eax
addq$1, %rsi
cqto
idivq   %rsi
testb   $1, %al
je  .L13
testl   %ecx, %ecx
je  .L17
.L13:
movq$0, a(%rip)
xorl%eax, %eax
ret
.L17:
pushq   %rax
.cfi_def_cfa_offset 16
callfoo
xorl%edx, %edx
xorl%eax, %eax
movq%rdx, a(%rip)
popq%rcx
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE0:
.size   main, .-main
.local  a
.comm   a,8,8
.ident  "GCC: (GNU) 12.0.0 20210930 (experimental)"
.section.note.GNU-stack,"",@progbits