[Bug tree-optimization/126415] New: Wrong code at -O2/3/s on x86_64-pc-linux-gnu

"xintong.zhou1 at uwaterloo dot ca via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126415

            Bug ID: 126415
           Summary: Wrong code at -O2/3/s 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/6G68E88hE

$ 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 20260724 (experimental) (GCC) 
$
$ gcc-trunk -O0 small.c && ./a.out                                              
0
$ gcc-trunk -O2 small.c && ./a.out                                              
75
$ gcc-trunk -O3 small.c && ./a.out                                              
75
$ gcc-trunk -Os small.c && ./a.out                                              
75
$
$ cat small.c
int printf(const char *, ...);
long d(short p1, unsigned e, char f) {
  if (246 >= 149u - f)
    return 0;
  return f;
}
int g(char p1) { return d(0, 0, p1); }
int fn3(char p1) {
  long i = g(p1 + 159);
  return i;
}
int main() {
  int j = fn3(-84);
  printf("%d\n", j);
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.