public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111739] New: incorrect code with PGO enabled
@ 2023-10-09 12:50 iamanonymous.cs at gmail dot com
2023-10-09 13:17 ` [Bug tree-optimization/111739] " rguenth at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: iamanonymous.cs at gmail dot com @ 2023-10-09 12:50 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/111739] incorrect code with PGO enabled
2023-10-09 12:50 [Bug tree-optimization/111739] New: incorrect code with PGO enabled iamanonymous.cs at gmail dot com
@ 2023-10-09 13:17 ` rguenth at gcc dot gnu.org
2023-10-09 13:34 ` iamanonymous.cs at gmail dot com
2023-10-19 1:37 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-09 13:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111739
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Last reconfirmed| |2023-10-09
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed with r14-4302 and also with the head of the GCC 13 branch.
It helps if you can produce proper ISO C without implicit int and like.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/111739] incorrect code with PGO enabled
2023-10-09 12:50 [Bug tree-optimization/111739] New: incorrect code with PGO enabled iamanonymous.cs at gmail dot com
2023-10-09 13:17 ` [Bug tree-optimization/111739] " rguenth at gcc dot gnu.org
@ 2023-10-09 13:34 ` iamanonymous.cs at gmail dot com
2023-10-19 1:37 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: iamanonymous.cs at gmail dot com @ 2023-10-09 13:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111739
--- Comment #2 from Anonymous <iamanonymous.cs at gmail dot com> ---
(In reply to Richard Biener from comment #1)
> Confirmed with r14-4302 and also with the head of the GCC 13 branch.
>
> It helps if you can produce proper ISO C without implicit int and like.
Thank you for confirming the bug. Moving forward, we will ensure that the code
does not rely on implicit integer types.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/111739] incorrect code with PGO enabled
2023-10-09 12:50 [Bug tree-optimization/111739] New: incorrect code with PGO enabled iamanonymous.cs at gmail dot com
2023-10-09 13:17 ` [Bug tree-optimization/111739] " rguenth at gcc dot gnu.org
2023-10-09 13:34 ` iamanonymous.cs at gmail dot com
@ 2023-10-19 1:37 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-19 1:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111739
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |INVALID
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The code is undefined for alias reasons:
union {
int f;
short g
} h;
*j = &h;
...
a = n(h.f++);
*j = 0;
...
for (; i < 2; i++)
d = k(h.g || 0, 59376);
short *b = &h;
*b ^= e;
printf("%d\n", h);
```
In the case of profiling, we are able to optimize away the short load from h
in:
*b ^= e;
and point it back to the store from `h.f++` and miss the store via *j.
Once you add -fno-strict-aliasing the testcase starts to work.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-10-19 1:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-09 12:50 [Bug tree-optimization/111739] New: incorrect code with PGO enabled iamanonymous.cs at gmail dot com
2023-10-09 13:17 ` [Bug tree-optimization/111739] " rguenth at gcc dot gnu.org
2023-10-09 13:34 ` iamanonymous.cs at gmail dot com
2023-10-19 1:37 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).