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

            Bug ID: 127588
           Summary: wrong code at -O{2,3} with -fno-vect-cost-model 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/hnWPPvebY

Note:
- fails: trunk
- works: 16.2 and earlier

[529] % 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++,lto --disable-werror
--disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 17.0.0 20260924 (experimental) [master r17-1628-gd1c12591336] (GCC) 
[530] % 
[530] % gcctk -O3 small.c; ./a.out
[531] % 
[531] % gcctk -O3 -fno-vect-cost-model small.c
[532] % ./a.out
Segmentation fault
[533] % 
[533] % cat small.c
struct {
  long d[1];
} h, *n;
int e[256];
long l, m, p, q;
long *o;
int r, s, d, f;
int *v, *a;
int w(int x, int y) {
  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 = x;
  for (int b = 0; b < 4; ++b)
    k = k >> 8 ^ e[(k ^ y) & 255];
  return k;
}
int z() {
  n = &h;
  l = 3678985 + 138;
  o = &h.d[0];
t:
  m = *o;
  h.d[0] = l + m;
  p = *n->d;
  if (m)
    goto u;
  goto t;
u:
  r = w(r, p);
  return r;
}
int main() {
  int g = z() + 206940396;
  s = g - 15;
aa:
  v = &s;
  *v = 1074790400 + s;
  if (0 < (-1073741824 & s))
    goto t;
  goto aa;
t:
  q = s >> 2;
  f = q;
  f = w(f, d);
  if (-f < 0)
    *a = 0;
}

Reply via email to