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

            Bug ID: 120487
           Summary: wrong code at -Os 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/a33Mb7vfW

It affects 15.1 and trunk, and is a regression from 14.*. 

[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 20250530 (experimental) (GCC) 
[515] % 
[515] % gcctk -Os small.c
[516] % ./a.out
Aborted
[517] % 
[517] % cat small.c
int printf(const char *, ...);
int a, b, c, d, e;
static void f(int g, int h) {
  int i;
  b = -999 - 999 * g - 999 - 2147483647;
  d = -999 * b - 2147483647;
j:
  i = e - 999 * g - 2147483647;
  c = -999 * g - 999 * e - 2147483647;
  if (c <= -300)
    return;
m:
  g = h - 999 * g;
  i = -d - 999 * i - 2147483647;
  if (-999 * i - g - c - 1080117449 >= 0)
    goto j;
  while (1) {
    a = i;
    if (g + 36057402 * i)
      goto m;
  }
}
int main() {
  f(-2149633, -2147483647);
  if (a != 0)
    __builtin_abort();
  return 0;
}

Reply via email to