Bug 100082 - missed optimization for dead code elimination at -O3 (vs. -O2)
Summary: missed optimization for dead code elimination at -O3 (vs. -O2)
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-14 14:36 UTC by Zhendong Su
Modified: 2023-08-18 03:54 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 12.1.0
Known to fail:
Last reconfirmed: 2021-04-15 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-14 14:36:12 UTC
[528] % 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 20210414 (experimental) [master revision 006783f4b16:29da9c11552:0589be0c59767cf4cbb0ef0e7d918cf6aa3d606c] (GCC) 
[529] % 
[529] % gcctk -O2 -S -o O2.s small.c
[530] % gcctk -O3 -S -o O3.s small.c
[531] % 
[531] % wc O2.s O3.s
 101  229 1393 O2.s
 145  329 2038 O3.s
 246  558 3431 total
[532] % 
[532] % grep foo O2.s
[533] % grep foo O3.s
	call	foo
[534] % 
[534] % cat small.c
extern void foo(void);
volatile int a, b, h;
int *c, d[4], f, i, j;
long g;
static unsigned e() {
  int k;
  while (b) {
    for (k = 0; k < 4; k++) {
      d[k] && a;
      h = j ? 0 : i;
    }
    *c = 0;
  }
  return 0;
}
int main() {
  for (f = 0; f < 5; f++)
    g = 1;
  if (!e() ^ g)
    foo();
  return 0;
}
Comment 1 Richard Biener 2021-04-15 06:51:07 UTC
Confirmed.  At -O2 PRE manages to optimize the call to foo.  The difference starts at cunrolli where -O3 unrolls but -O2 not, disabling cunrolli restores
optimization.
Comment 2 Andrew Pinski 2023-05-05 07:53:10 UTC
Seems fixed in GCC 12
Comment 3 Andrew Pinski 2023-08-18 03:54:00 UTC
Looks like it is jump threading differences between GCC 11 and GCC 12 which fixes this.