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

            Bug ID: 125739
           Summary: wrong code at -O{2,3} with "-fno-tree-dse
                    -fno-tree-pre -fno-expensive-optimizations
                    -fno-tree-sra -flto" on x86_64-linux-gnu
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhendong.su at inf dot ethz.ch
  Target Milestone: ---

Compiler Explorer: https://godbolt.org/z/eb8efsa33

Note:
- fails: 16.1 and trunk
- works: 15.2 and earlier

[555] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/home/suz/suz-local/software/local/gcc-trunk/bin/../libexec/gcc/x86_64-pc-linux-gnu/17.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --disable-bootstrap
--enable-checking=yes --prefix=/local/suz-local/software/local/gcc-trunk
--enable-sanitizers --enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 17.0.0 20260610 (experimental) (GCC) 
[556] % 
[556] % gcctk -O3 small.c; ./a.out
[557] % 
[557] % gcctk -O3 -fno-tree-dse -fno-tree-pre -fno-expensive-optimizations
-fno-tree-sra -flto small.c
[558] % ./a.out
Aborted
[559] % 
[559] % cat small.c
typedef struct {
  float a;
  float aa;
} d;
int e[256], m, n;
int f(int g, int h) {
  for (int i = 0; i < 256; ++i) {
    unsigned c = i;
    for (int j = 0; j < 8; ++j)
      c = c & 1 ? c >> 1 ^ 3988292384 : c >> 1;
    e[i] = c;
  }
  unsigned k = g;
  int l = h;
  for (int b = 0; b < 4; ++b) {
    char ab = l;
    l >>= 8;
    k = k >> 8 ^ e[(k ^ ab) & 255];
  }
  return k;
}
int o(char p, char q, char r, short s, char t, short u, short v) {
  char w, *ag = &w;
  d x;
  int y = 1;
  long z = 1;
  x.a = x.aa = 1.0f;
  m = 3 - 1073741824 - 3;
  *ag = z = z - 2 * m;
  z = -186621953 ^ (z + 4);
  if (s)
  ac:
    if (-16385 == y)
      x.aa = *ag = 0;
  if (s)
    y = y - 8193;
  m = 2 - 350224399;
  if (w)
    goto ad;
  goto ae;
ad:
  x.a = 0 + x.a;
  x.aa = 0 + x.aa;
  goto ac;
ae:
  n = f(0, x.a);
  n = f(n, x.aa);
  n = f(n, 1.0f);
  n = f(n, 1);
  n = f(n, (long)((unsigned long)y << 48) >> 48);
  n = f(n, z);
  n = f(n, 1.0);
  n = f(n, 1.0);
  n = f(n, 1.0);
  n = f(n, 1.0);
  n = f(n, 1.0);
  n = f(n, 1.0);
  n = f(n, 1.0);
  n = f(n, 0);
  n = f(n, m);
  n = f(n, 1);
  n = f(n, p);
  n = f(n, q);
  n = f(n, r);
  n = f(n, s);
  n = f(n, (long)((unsigned long)t << 56) >> 56);
  n = f(n, u);
  n = f(n, v);
  n = f(n, 1.0f);
  n = f(n, 0);
  return n;
}
int main() {
  int af = o(7, 2, 4, -1, -17, 16384, 1);
  if (103539439 != af)
    __builtin_abort();
  return 0;
}

Reply via email to