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

            Bug ID: 125918
           Summary: wrong code at -O{2,3} with "-fno-tree-pre
                    -fselective-scheduling2 -fsel-sched-pipelining" 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/bY8Pxaqb7

Note:
- fails: 9.1 till trunk
- works: 8.5 and earlier


[514] % 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 20260621 (experimental) (GCC) 
[515] % 
[515] % gcctk -O2 small.c; ./a.out
[516] % 
[516] % gcctk -O2 -fno-tree-pre -fselective-scheduling2 -fsel-sched-pipelining
small.c
[517] % ./a.out
Aborted
[518] % 
[518] % cat small.c
long a = 1;
char l, m, n, o;
short ab;
__attribute__((noinline)) int d(int e, int f) {
  static int g[256];
  for (int h = 0; h < 256; ++h) {
    unsigned c = h;
    for (int i = 0; i < 8; ++i)
      c = c & 1 ? c >> 1 ^ 3988292384 : c >> 1;
    g[h] = c;
  }
  unsigned j = e;
  int k = f;
  for (int b = 0; b < 4; ++b) {
    char aa = k;
    k >>= 8;
    j = j >> 8 ^ g[(j ^ aa) & 255];
  }
  return j;
}
int p(long q, long r, short s, int t) {
  long u = 1;
  char v = 1;
  int w = 1;
  __attribute__((__vector_size__(32))) int x;
  x[0] = x[2] = x[3] = x[6] = x[7] = 1;
  int y = 0, ag = 0;
  char *ac, *ad = 0, **ae = 0, **af;
ah:
  af = &ac;
  if ((2 ^ s) > -(v ? s : 20118))
    ae = &ac;
  x[4] = 806817005 & w;
  if (!u)
    goto aj;
  goto ai;
ai:
  v = u;
  if (3 * u > -2147483647 / a)
    goto am;
  goto al;
aj:
  d(ag, 0);
  if (30515234032229701 / r)
    goto an;
al:
  v = 31 + a;
  af = ae;
  if (a - 91744131447 >= -w)
    goto ao;
  goto ap;
ao:
  ag = d(0, 0);
  x[6] = 0;
am:
  *af = 0;
  u = -1073742718 - a;
  y = -1073742686 + 805116034;
  a = u + r;
  w = -1610753156;
  goto ah;
ap:
  ad = &l;
  ab = ((unsigned long)-1031 << 52 >> 52) + 800 - r;
  *ae = ad;
  l = 31 - 4 * v;
an:
  v = -67 + *ac;
  m = v - 128 / v;
  *ac = -5 - ~v - 120;
  v = 78;
  u = 2147218726 - (-1609827410 | r) - q;
  ag = d(0, a);
  ag = d(ag, u);
  ag = d(ag, v);
  ag = d(ag, w);
  ag = d(ag, x[0]);
  ag = d(ag, 1);
  ag = d(ag, x[2]);
  ag = d(ag, x[3]);
  ag = d(ag, x[4]);
  ag = d(ag, 0);
  ag = d(ag, x[6]);
  ag = d(ag, x[7]);
  ag = d(ag, y);
  ag = d(ag, (long)((unsigned long)l << 56) >> 56);
  ag = d(ag, 1);
  ag = d(ag, m);
  ag = d(ag, ab);
  ag = d(ag, 0);
  ag = d(ag, 0);
  ag = d(ag, q);
  ag = d(ag, r);
  ag = d(ag, s);
  ag = d(ag, t);
  n = *ac;
  ag = d(ag, (long)((unsigned long)n << 56) >> 56);
  o = *ad;
  ag = d(ag, (long)((unsigned long)o << 56) >> 56);
  return ag;
}
int main() {
  int aq = p(-3758096384, 3187673944, 1, 1);
  if (1437659478 != aq)
    __builtin_abort();
  return 0;
}

Reply via email to