https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121852
Bug ID: 121852 Summary: wrong code at -O2 with "-fno-gcse" 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/6MrKz8cfr Note: - fails: 12.1 and later - works: 11.4 and earlier - -fno-tree-slsr and -fno-ivopts do not make it disappear [675] % 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 20250908 (experimental) (GCC) [676] % [676] % gcctk -O2 small.c; ./a.out [677] % gcctk -O2 -fno-gcse small.c [678] % ./a.out Floating point exception [679] % cat small.c int a[] = {0}, d, e, h, i, j, k, l, n[1], *o = n; volatile int m; int p(char q) { return a[e ^ (q & 5)]; } int s(int q[]) { int f, g = 0; unsigned b = 5; for (; g < d; ++g) { int c = p(q[g] >> 6); b = f = (c & 4095) ^ a[c & 5]; } return b; } int u(volatile int q) { k = 5 % q; int r[] = {h, i, k, j}; return s(r); } int main() { int t; do { if (u(5)) m = 4; l--; t = l - 1 % m + 1; } while (!u(5)); o[0] = 2 % t; return 0; }