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

            Bug ID: 126313
           Summary: [16 Regression] Wrong code at -O2 -fprofile-use on
                    x86_64-pc-linux-gnu
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xintong.zhou1 at uwaterloo dot ca
  Target Milestone: ---

Compiler Explorer: https://godbolt.org/z/7z566f6P9

$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
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 20260718 (experimental) (GCC) 
$
$ gcc-trunk -O0 small.c && ./a.out              
0
$ gcc-trunk -O1 small.c && ./a.out              
0
$ gcc-trunk -O2 small.c && ./a.out              
0
$ gcc-trunk -O3 small.c && ./a.out              
0
$ gcc-trunk -O2 -fprofile-use small.c && ./a.out
3
$
$
$ cat small.c 
#include <stdio.h>
unsigned char a = 3;
short b, c, d;
int e;
char(f)(char g, char p2) {
  return p2 == 0 || g && p2 == 1 ? 0 : g % p2; 
}
unsigned i(short g) {
  d = g;
  return c;
}
void fn3(char g, int p2) {
  if (!(1 >= p2 && p2 <= g))
    e = b | i(f(1, p2) > 0xE151060F);
  else {
    { d = p2; }
  }
}
int main() {
  fn3(a, a);
  printf("%d\n", d);
}

Reply via email to