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

            Bug ID: 121370
           Summary: wrong code at -O{s,2,3} 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/e6snMKbE6

Notes:
* It seems to be a regression from 8.5 and affects 9.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 20250802 (experimental) (GCC) 
[515] % 
[515] % gcctk -O3 small.c
[516] % ./a.out
Illegal instruction
[517] % 
[517] % gcctk -O3 -fno-tree-slsr -fno-ivopts small.c
[518] % ./a.out
Illegal instruction
[519] % 
[519] % cat small.c
int a;
int main() {
  int c = -2147483647;
  int d = -2147483647;
  int e = 2147483647;
  if (0)
  f:
    e = d + e - 2;
g:
  if (d - c - e > 0) {
    a = -c;
    if (a + d) {
      d = 1;
      goto g;
    }
    return 0;
  }
  if (e)
    goto f;
  return 0;
}

Reply via email to