https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121347
Bug ID: 121347
Summary: wrong code at -O1 and above 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/z7bxE57z5
Note:
- it is a regression from 7.* and affects 8.1 and later
- -fno-tree-slsr makes it disappear
[534] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/home/suz/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 20250801 (experimental) (GCC)
[535] %
[535] % gcctk -O3 small.c
[536] % ./a.out
Aborted
[537] %
[537] % cat small.c
int a[] = {
0, 4, 8, 4, 7, 1886057615,
3915621685, 2657392035, 4, 2044508324, 0, 4,
162941995, 1, 7, 2428444049, 498536548, 1789927666,
4089016648, 4, 50548861, 1843258603, 107580753, 9,
0, 2, 2, 6, 7, 1661365465,
5, 7, 997073096, 6, 2, 2724688242,
1006888145, 607687, 101629, 3, 901097722, 9000684,
3686517206, 8065728, 853044451, 1, 705015759, 5,
0, 6, 4, 104598, 565507253, 1,
5, 3099436303, 4, 4, 30930, 70347812,
7, 5, 5, 3060149565, 2, 31158534,
2563907772, 4023717930, 907459465, 5, 3, 904427059,
2013776290, 6, 2517215374, 0, 3, 141376813,
9, 3865271297, 802195444, 6, 2238001368, 4066508878,
70925, 453092731, 5, 4111451223, 706088902, 4,
2344532202, 4240017532, 1658658271, 366619977, 2362670323, 224994405,
303535960, 6, 7007092, 9037538, 70817, 1,
3, 4079995, 6, 879679996, 909243462, 6,
1141124467, 7, 1, 3708648649, 8, 6,
3188396048, 4, 1466479909, 5, 10523913, 5,
1591671054, 702138776, 0, 2, 504918807, 3,
3082640443, 9, 4, 6, 62317068, 10842,
5, 1, 70997, 3, 0, 2489596804,
0, 2053790376, 5, 3, 3, 2097651377,
4027552580, 2265490386, 503444072, 1762050814, 5, 5,
5, 1852507879, 6, 2312317920, 6, 2,
708143, 5, 3, 7, 604390888, 8,
2, 340076626, 5, 2797360999, 1068828381, 9,
0, 2936675148, 906185462, 1090812512, 3, 2825379669,
829329135, 1181335161, 4, 60834842, 8085408, 6,
3423369109, 8078467, 570562233, 1426400815, 3317316542, 608,
4, 6, 1, 5, 3, 1,
607071920, 0, 2, 40735498, 5, 1,
3087877, 83908371, 2512341634, 803740692, 2075208622, 2,
3, 90285, 2094854071, 1, 2029012, 4057260610,
1759359992, 0, 1, 5, 1873836001, 7,
2282248934, 200368, 1711684554, 6, 405801727, 5,
1634467795, 1, 2685067896, 608007406, 1308918612, 956543938,
2808555105, 3, 1, 1047427035, 8, 703836,
1088359270, 936918000, 9, 3736837829, 202900863, 817233897,
3183342108, 0, 2, 0, 207493, 3,
1423857449, 1, 3009837614, 3294710456, 6, 711928724,
3020668471, 5, 1510334235, 755167117};
int d, e, g;
int h(int i, char j) { return (i >> 8 & 16777215) ^ a[(i ^ j) & 255]; }
int fn2(int i, int j[]) {
int k;
unsigned b = 4294967295;
for (int f = 0; f < i; ++f) {
int c;
k = b >> 8 ^ a[(b ^ j[f]) & 255];
c = k;
c = h(c, j[f] >> 8);
c = h(c, j[f] >> 6);
c = h(c, j[f] >> 24);
b = c;
}
b = (b ^ 4294967295) % 2147483647;
return b;
}
int r(int i, int j, int s, int t, int u, int v, int w) {
int l;
s = -v - s - 1;
if (j) {
j = -s - t - 1;
goto n;
}
while (8 * j + 501 * v > 0) {
n:
v = -i - s - 1;
}
l = -i - t - 1;
return fn2(8, (int[]){i, j, s, t, u, v, l, w});
}
static int y(int i, int j, int s, int t, int u) {
int l;
d = -999 - u;
do {
i = (r(-1, -1, -1, -1, -1, -1, -1) - 1946213370) * j +
(r(1, 4, -2, 0, 1, 1, 1) - 1215528698) * i - 9;
l = -99;
if ((r(-1, -1, -1, -1, -1, -1, -1) - 1946213372) * j +
(r(1, 3, -2, 0, -1, 0, -1) - 1683379045) * s)
s = 83380045;
j = -d;
} while ((r(1, 4, -2, 0, 1, 1, 1) - 1215527698) * j +
(r(-1, 1, -1, -1, -1, -1, -1) - 1946213370) * d +
(r(1, 4, -2, 0, 1, 1, 1) - 1215527698) * s +
(r(-1, 1, -1, -1, -1, -1, -1) - 1946213370) * u +
(r(1, 1, 1, 1, 1, -1, 1) - 1946214370) > 0);
return fn2(8, (int[]){i, j, 1, t, d, u, l, e});
}
int main() {
if (y(-2147483, -2147483647, -1, 5, -2147483647) - 3 > 0)
__builtin_abort();
return 0;
}