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

            Bug ID: 111739
           Summary: incorrect code with PGO enabled
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamanonymous.cs at gmail dot com
  Target Milestone: ---

*******************************************************************************
OS and Platform:
$ uname -a:
Linux ubuntu 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023
x86_64 x86_64 x86_64 GNU/Linux
*******************************************************************************
gcc version:
$ gcc -v
Using built-in specs.
COLLECT_GCC=/root/gcc_set/new_gcc/bin/gcc
COLLECT_LTO_WRAPPER=/root/gcc_set/new_gcc/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/root/gcc_set/new_gcc
--with-gmp=/root/build_essential --with-mpfr=/root/build_essential
--with-mpc=/root/build_essential --enable-languages=c,c++ --disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230719 (experimental) (GCC)

git version:85da0b40538fb0d17d89de1e7905984668e3dfef
*******************************************************************************
Program:
$ cat a.c
c, d, e, a;
union {
  int f;
  short g
} h;
*j = &h;
k(short l, short m) { return m == 0 || l && m == 1 ?: l / m; }
n(l) { return c == 0 ?: l / c; }
main() {
  a = n(h.f++);
  *j = 0;
  int i = 0;
  for (; i < 2; i++)
    d = k(h.g || 0, 59376);
  short *b = &h;
  *b ^= e;
  printf("%d\n", h);
}

*******************************************************************************
Command Lines:
# The profile directory is used to save profile information.
$ gcc -O3 -w -fprofile-generate=profile a.c -o a.out
$ ./a.out
0
$ gcc -O3 -w -fprofile-use=profile -Wno-missing-profile -fprofile-correction
a.c  
 -o a.out
$ ./a.out
1

We can found that, the output of the executable is incorrect when the profile
guided optimization is enabled.

Reply via email to