Bug 100113 - missed optimization for dead code elimination at -O3 (vs. -O1)
Summary: missed optimization for dead code elimination at -O3 (vs. -O1)
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization, needs-bisection
Depends on:
Blocks:
 
Reported: 2021-04-16 07:28 UTC by Zhendong Su
Modified: 2023-08-18 02:26 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 12.3.0, 13.1.0
Known to fail: 12.2.0
Last reconfirmed: 2021-04-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhendong Su 2021-04-16 07:28:12 UTC
[584] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/suz-local/software/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/11.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --disable-bootstrap --prefix=/local/suz-local/software/local/gcc-trunk --enable-languages=c,c++ --disable-werror --enable-multilib --with-system-zlib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.1 20210416 (experimental) [master revision 89c863488bc:10ed13839be:76c7e7d6b003a17d183d0571bf9b34c691819d25] (GCC) 
[585] % 
[585] % gcctk -O1 -S -o O1.s small.c
[586] % gcctk -O3 -S -o O3.s small.c
[587] % 
[587] % wc O1.s O3.s
  84  185 1140 O1.s
 120  254 1768 O3.s
 204  439 2908 total
[588] % 
[588] % grep foo O1.s
[589] % grep foo O3.s
	call	foo
[590] % 
[590] % cat small.c
extern void foo(void);
int a, b, d, *c = &a, e, k;
static int f(int *h, int i, int **l) {
  for (b = 0; b < 1; b++) {
    int *f = &d;
    for (; d < 1; d++)
      f = c;
    if (f != &a)
      __builtin_abort();
    if (k)
      *c = 0;
  }
  *c = 0;
  return **l;
}
int main() {
  int *j = &b;
  if (!f(j, e, &j))
    foo();
  return 0;
}
Comment 1 Richard Biener 2021-04-20 08:11:55 UTC
dom3 manages to optimize it with -O1 but it gets different input with -O3.
Comment 2 Andrew Pinski 2023-08-18 02:18:46 UTC
Looks to be fixed in GCC 12.3.0 and GCC 13.1.0 .
Comment 3 Andrew Pinski 2023-08-18 02:26:26 UTC
(In reply to Andrew Pinski from comment #2)
> Looks to be fixed in GCC 12.3.0 and GCC 13.1.0 .

A change in PRE which causes the IR to be different and allowed to be optimized away in DOM3