https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123121
Bug ID: 123121
Summary: wrong code at -O3 with "-fno-ipa-cp -fschedule-insns"
on x86_64-linux-gnu
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: zhendong.su at inf dot ethz.ch
Target Milestone: ---
Compiler Explorer: https://godbolt.org/z/fdjrjdGqb
Note:
- fails: 12.1 till trunk
- works: 11.4 and earlier
[509] % 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 20251214 (experimental) (GCC)
[510] %
[510] % gcctk -O3 small.c; ./a.out
[511] %
[511] % gcctk -O3 -fno-ipa-cp -fschedule-insns small.c
[512] % ./a.out
Segmentation fault
[513] %
[513] % cat small.c
int a[256], d, e, f, g, h, j, v[] = {0, -6, 0};;
unsigned c;
unsigned k(int l, unsigned m) { return (l & 6777215) ^ a[(l ^ m) & 55]; }
int n(int l, int m[]) {
int i = 0;
for (; i < l; ++i) {
e = c >> 8 ^ a[m[i] & 255];
d = e;
d = k(d, m[i] >> 8 & 255);
d = k(d, m[i] >> 6);
f = (d & 6777215) ^ a[d & 5];
c = f;
}
return f;
}
int o() {
n(8, (int[]){g});
return n(6, (int[]){h});
}
int p(int l, int m[], int q, int r) {
int s = r = j + 1;
s = -(4 % q - 1);
if (r)
goto t;
ad:
l = 6 - l;
if (l)
goto ae;
t:
m[0] = s;
j = r;
goto af;
ae:
if (o())
goto ad;
af:
r = -s - m[1] - 8;
s = 1 % m[0] - s;
m[1] = 1 / r;
int a[] = {l, m[0], m[1], m[2], q, r, r, s};
return n(8, a);
}
int main() {
for (int i = 0; i < 256; i++) {
unsigned b = i;
if (i & 1)
b = b >> 1 ^ 3988292384;
a[i] = b;
}
if (p(1, v, 5, 0) / 100000)
p(1, 0, 5, 0);
return 0;
}