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

            Bug ID: 121704
           Summary: wrong code at -O3 with "-fno-gcse -fno-ipa-cp" on
                    x86_64-linux-gnu
           Product: gcc
           Version: unknown
            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/T9f835368

Note:
- works: 13.* and earlier
- fails: 14.1 and later
- -fno-tree-slsr and -fno-ivopts do not make it disappear

[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/16.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 16.0.0 20250828 (experimental) (GCC) 
[515] % 
[515] % gcctk -O3 small.c; ./a.out
[516] % gcctk -O3 -fno-gcse -fno-ipa-cp small.c
[517] % ./a.out
Segmentation fault
[518] % 
[518] % cat small.c
int a[] = {
    0,          4,          8,          4,          124634137,  5,
    5,          5,          4,          2044508324, 0,          4,
    5,          1,          7,          2428444049, 498536548,  6,
    4089016648, 4,          50548861,   1843258603, 107580753,  2211677639,
    5883990,    2,          2,          6,          335633487,  5,
    5,          7,          7073096,    1281953886, 2,          2724688242,
    1006888145, 1258607687, 3524101629, 3,          901097722,  1119000684,
    6,          8065728,    1,          1172266101, 705015759,  5,
    651767980,  1373503546, 4,          104598,     3,          1,
    5,          3099436303, 4,          4,          3322730930, 2970347812,
    795835527,  1483230225, 5,          3060149565, 2,          31158534,
    2563907772, 4023717930, 907459465,  5,          3,          904427059,
    2013776290, 251722036,  4,          0,          3,          3,
    439277719,  7,          802195444,  6,          8001368,    4066508878,
    70925,      3092731,    2181625025, 4111451223, 706088902,  314042704,
    2344532202, 2,          1658658271, 7,          2362670323, 5,
    303535960,  6,          7007092,    3569037538, 70817,      1037604311,
    3,          3554079995, 6,          79679996,   909243462,  3663771856,
    1141124467, 7,          1,          3708648649, 8,          6,
    3188396048, 4,          909,        5,          3110523913, 3462522015,
    4,          702138776,  2966460450, 3352799412, 1504918807, 783551873,
    3082640443, 3233442989, 4,          6,          7068,       10842,
    5,          1,          70997,      3,          0,          2489596804,
    225274430,  2053790376, 5,          3,          3,          2097651377,
    4027552580, 90386,      2,          1762050814, 5,          5,
    5,          507879,     4275313526, 0,          282753626,  2,
    708143,     2394877945, 397917763,  7,          604390888,  2714866558,
    2,          6,          5,          60999,      1068828381, 9,
    3624741850, 8,          906185462,  1090812512, 3,          9,
    5,          1181335161, 4,          60834842,   8085408,    1382605366,
    109,        3138078467, 3,          400815,     3317316542, 608,
    733239954,  6,          1,          5,          3,          1,
    607071920,  3965973030, 2,          40735498,   2617837225, 1,
    1913087877, 83908371,   2512341634, 803740692,  2075208622, 2,
    3,          3855990285, 2094854071, 198958881,  2262029012, 0,
    1759359992, 534414190,  1,          4139329115, 1,          414664567,
    4,          4279200368, 1684554,    6,          2405801727, 5,
    5,          1,          5067896,    3608007406, 308918612,  8,
    808555105,  3,          1,          5,          59818,      3654703836,
    1088359270, 0,          9,          3736837829, 202900863,  817233897,
    108,        0,          1404277552, 0,          207493,     3,
    9,          1,          3009837614, 3294710456, 6,          4,
    3020668471, 5,          510334235,  755167117};
int b, c, d, e, f;
int g(int h, char k) { return (h >> 8 & 16777215) ^ a[(h ^ k) & 255]; }
int l(int h, int k[]) {
  int j = 4294967295, i = 0;
  for (; i < h; ++i) {
    b = (j >> 8 & 16777215) ^ a[(j ^ k[i]) & 255];
    c = b;
    c = g(c, k[i] >> 8);
    c = g(c, k[i] >> 6);
    c = g(c, k[i] >> 4);
    j = c;
  }
  j = j ^ 4294967295;
  return j;
}
int m(volatile int h[], int k, volatile int n[][1], int o, int p, int q,
      int r[][3], int s[][1], volatile int t) {
  d = p + 5;
  e = 5 / t - 1;
  s[2][0] = -2;
  if (e)
    h[1] = -(1 % n[2][0]) + 1;
  p = 1 - o;
  n[2][0] = 1 - s[0][0] - r[1][2];
  return l(25, (int[]){h[0],    h[1],    k,       n[0][0], n[1][0],
                       n[2][0], o,       p,       q,       r[0][0],
                       r[0][1], r[0][2], r[1][0], r[1][1], r[1][2],
                       r[2][0], r[2][1], r[2][2], s[0][0], s[1][0],
                       s[2][0], 0,       d,       e,       t});
}
void u(volatile int h[][1]) {
  f = -1;
  do {
    m((int[]){1, 1}, 1, (int(*)[])(int[]){1, 1, 2}, 1, 2, 1,
      (int(*)[])(int[9]){1}, (int(*)[])(int[]){2, 1, 1}, -2) -
        h[m((int[]){-1, 1}, -1, (int(*)[])(int[]){-1, -1, 2}, -1, -2, -1,
            (int(*)[])(int[]){-1, -1, -1, -1, -1, -1, -1, -1, -1},
            (int(*)[])(int[]){-2, -1, 1}, -2) -
          1316653008][0];
  } while (m((int[]){1, 1}, 1, (int(*)[])(int[]){1, 1, 2}, 1, 2, 1,
            (int(*)[])(int[9]){1}, (int(*)[])(int[]){2, 1, 1}, 2) /
             f < 0);
}
int main() { u((int(*)[])(int[]){0}); }

Reply via email to