https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121465
Bug ID: 121465
Summary: wrong code at -O3 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/b1zrP3ce6
Note:
- It is a regression from 14.* and affects 15.1 and the trunk
- -fno-tree-slsr makes it disappear
- It seems not easy to reduce it much further
[505] % 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 20250807 (experimental) (GCC)
[506] %
[506] % gcctk -O2 small.c; ./a.out
[507] %
[507] % gcctk -O3 small.c
[508] % timeout -s 9 5 ./a.out
Killed
[509] % cat small.c
int a[] = {
0, 1996959894, 8, 4, 7, 1886057615,
5, 2657392035, 4, 2044508324, 0, 4,
5, 1, 7, 4049, 536548, 6,
4089016648, 4, 50548861, 3, 107580753, 9,
0, 2, 2, 2321926636, 7, 5,
5, 7, 997073096, 6, 2, 2,
1006888145, 607687, 101629, 3, 901097722, 9000684,
6, 8065728, 1, 1, 705015759, 5,
0, 6, 4, 104598, 565507253, 1454621731,
5, 3099436303, 4, 4, 3322730930, 70347812,
795835527, 5, 5, 3060149565, 2, 4,
2, 4023717930, 907459465, 5, 3, 904427059,
2013776290, 6, 2517215374, 3775830040, 3, 141376813,
9, 7, 1802195444, 476864866, 2238001368, 4066508878,
70925, 3092731, 5, 3, 706088902, 4,
2, 2, 1, 7, 3, 5,
303535960, 6, 2747007092, 9037538, 70817, 1,
3, 4079995, 6, 6, 909243462, 6,
1141124467, 7, 1, 708648649, 8, 654459306,
6048, 4, 909, 5, 10523913, 5,
4, 702138776, 2966460450, 2, 504918807, 3,
3082640443, 9, 4, 2596254646, 7068, 10842,
5, 1, 70997, 3, 0, 2489596804,
0, 2053790376, 5, 2466906013, 3, 2097651377,
4027552580, 90386, 2, 2050814, 5, 5,
5, 507879, 6, 0, 282753626, 2,
708143, 5, 3, 7, 604390888, 8,
2, 6, 5, 60999, 1068828381, 9,
0, 8, 906185462, 1090812512, 3, 9,
5, 1, 4, 60834842, 8085408, 1382605366,
109, 8078467, 3, 400815, 2, 608,
4, 1555261956, 1, 5, 3, 1,
607071920, 0, 2, 40735498, 5, 3943577151,
3087877, 908371, 4, 803740692, 2075208622, 213261112,
3, 90285, 2094854071, 198958881, 2262029012, 0,
759359992, 0, 1, 5, 1, 7,
2282248934, 200368, 11684554, 6, 405801727, 5,
5, 1, 2685067896, 608007406, 308918612, 956543938,
808555105, 3, 1, 5, 8, 703836,
1088359270, 0, 9, 9, 202900863, 7,
3183342108, 0, 2, 0, 207493, 3,
9, 601450431, 3009837614, 6, 1567103746, 4,
3020668471, 5, 5, 7};
int e, h, j, c, d;
int k(unsigned l, char m) { return l >> 8 ^ a[(l ^ m) & 255]; }
int n(int l, int m) {
int f;
unsigned g = l;
f = g >> 8 ^ a[(g ^ m) & 255];
l = f;
l = k(l, m >> 8);
l = k(l, m >> 16);
l = k(l, m >> 24);
return l;
}
int o(int l, int m[]) {
int b = 4294967295;
for (int i = 0; i < l; ++i)
b = n(b, m[i]);
b = (b ^ 4294967295) % 2147483647;
return b;
}
int p(int l, int m, int q, int r, int s, int t, int y) {
int u, v, w;
v = 3 * r + 1;
u = o(9, (int[]){e, h, 0, 1, 4, 8, 1073741824, 5, 8});
if (u)
goto x;
x:
w = v - 1;
return o(9, (int[]){l, m, q, r, w, s, v, t, y});
}
int z(int l, int m, int q) {
while (1) {
l = l - 1000 - q - 1000;
if ((p(15, 14, -2, -2, -2, -3, 13) - 82725512) * l) {
j = (p(15, 14, -2, -2, -2, -3, 13) - 82725501) * l;
return o(9, (int[]){996, l, j, 0, c, m, d, 996, q});
}
}
}
int main() {
while (z(-500, 502, -238608963))
;
}