https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100036

            Bug ID: 100036
           Summary: missed optimization for dead code elimination at -Os,
                    -O2 and -O3 (vs. -O1)
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhendong.su at inf dot ethz.ch
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

[562] % 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 20210411 (experimental) [master revision
1d54b138417:e83b9cf4549:936d500dfc17f58f2507ecd0f7f26e4f197052ee] (GCC) 
[563] % 
[563] % gcctk -O1 -S -o O1.s small.c
[564] % gcctk -O3 -S -o O3.s small.c
[565] % 
[565] % wc O1.s O3.s
  27   58  454 O1.s
  38   77  665 O3.s
  65  135 1119 total
[566] % 
[566] % grep foo O1.s
[567] % grep foo O3.s
        jmp     foo
[568] % 
[568] % cat small.c
extern void foo(void);
int a, *b;
static int c, f;
inline int *d() {
  int g[100] = {0};
  if (a) {
    int h = g[0];
    foo();
    return b;
  }
}
int main() {
  while (1) {
    if (!c)
      return f;
    d();
  }
  return 0;
}

Reply via email to