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

            Bug ID: 120521
           Summary: wrong code at -O3 with "-fno-tree-fre" on
                    x86_64-linux-gnu (generated code hangs)
           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/8W3Ec8TzK

It appears to be a regression from 13.*, and affects 14.* and later. 

[542] % 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 20250603 (experimental) (GCC) 
[543] % 
[543] % gcctk -O3 small.c; ./a.out
[544] % 
[544] % gcctk -O3 -fno-tree-fre small.c
[545] % timeout -s 9 10 ./a.out
Killed
[546] % 
[546] % cat small.c
int a, b, c = -2147483647;
int main() {
  int d = -2147483646, e = -2147483645, f = 0;
  goto g;
h:
  b -= 429496729;
  if (d + 858993461 >= b) {
    if (f + 2147483644 <= 0) {
      if (b - f >= 0)
        goto h;
      b = -1;
    }
    goto i;
  }
j:
  f -= 715827882;
  if (f - c >= 1431655765) {
    b = -e - 2147483647;
    if (b)
      goto h;
    goto i;
  }
  goto h;
i:
  a = -999 * b - 2147483647;
  if (a)
    return 0;
g:
  goto j;
  return 0;
}

Reply via email to