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

            Bug ID: 126575
           Summary: Wrong code at -O3 on x86_64-pc-linux-gnu
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xintong.zhou1 at uwaterloo dot ca
  Target Milestone: ---

Compiler Explorer: https://godbolt.org/z/PfEeWs5vP

$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=/data/x27zhou/compiler-nightly/install/gcc/bin/gcc
COLLECT_LTO_WRAPPER=/data/x27zhou/compiler-nightly/install/gcc/libexec/gcc/x86_64-pc-linux-gnu/17.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /data/x27zhou/compiler-nightly/src/gcc/configure
--enable-checking=yes --disable-bootstrap --disable-multilib
--enable-languages=c,c++ --prefix=/data/x27zhou/compiler-nightly/install/gcc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 17.0.0 20260801 (experimental) (GCC)
$
$ gcc-trunk -O0 small.c && ./a.out
0
$ gcc-trunk -O3 small.c && ./a.out
2
$ cat small.c
#include <stdio.h>
int a, b;
long c;
int d(short f) {
  for (int g = 0; g < 24; g++) {
    int e = f + g;
    switch (e % 3) {
    case 1:
      a ^= e;
      break;
    case 0:
      a += e >> 1;
      break;
    default:
      a += e >> 1;
    }
  }
  c = 1 ? a + 1 : 0;
  return c;
}
long fn2(char f) {
  int i = f & 7;
  switch (d(i + 1476) + i + f - 14321 + i)
  case 4:
    return 0;
  return 2;
}
int main() {
  b = fn2(60);
  printf("%d\n", b);
}


Bisected to
https://gcc.gnu.org/cgit/gcc/commit/?id=c9ccc3961f5b8d333f5081b377cd9ee9e33079f7

Reply via email to