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

            Bug ID: 124583
           Summary: wrong code at -O2 when compiling with PGO on
                    x86_64-pc-linux-gnu
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xintong.zhou1 at uwaterloo dot ca
  Target Milestone: ---

Created attachment 63982
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63982&action=edit
The profile data for PGO compiling.

GCC generates wrong code when compiling using the profiled data with PGO. The
profile (a-small.gcda) is reduced to contain only one function to trigger the
issue.


$ 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/16.0.1/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 16.0.1 20260320 (experimental) (GCC)
$
$
$ gcc-trunk -O0 small.c && ./a.out
2
$ gcc-trunk -O2 small.c && ./a.out
2
$ gcc-trunk -O2 -fprofile-use -Wno-coverage-mismatch small.c && ./a.out
0
$
$ cat small.c
int printf(const char *, ...);
int a, b, c, d, f, g, h, j, k, m, p;
int l[6];
char n, o;
void e(int p1) {
  for (; a;)
    if (c)
      for (; b;)
        ;
}
void f1(int p1) {
  int ic = 6 & p1;
  for (int i = ic; i < ic + 1; i++)
    e(d);
}
int in(int *p1) {
  int *ip = p1, *is = &ip[1], *iu = &is[1];
  char *iw = (char *)iu + p1[0];
  if (p1[2])
    f = *(iw + p1[2] - 1);
  else
    f = *iw;
  return f;
}
int iy(int p1) {
  int jb[] = {p1, p1, 96, 9, p1, 355, p1, p1};
  int jc = in(jb);
  return jc;
}
int kk(int p1) {
  for (int kt = 0; kt < 1; kt++) {
    g = iy(p1 - 175);
    f1(h);
  }
  return g;
}
int main() {
  for (; p < 6; p++) {
    m = g = 8;
    for (; g; g--)
      if (p)
        m = 2;
    l[0] = m;
  }
  j = kk(33 + 60);
  k = k & 5 ^ l[k ^ j & 5];
  k = k & 5 ^ l[k ^ n];
  printf("", o, k ^ 5);
  printf("%X\n", k);
}

Reply via email to