public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105449] New: suspicious optimization since GCC 10.1.0 from -
@ 2022-05-01 23:41 gilles.gouaillardet at gmail dot com
2022-05-01 23:42 ` [Bug c/105449] " gilles.gouaillardet at gmail dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: gilles.gouaillardet at gmail dot com @ 2022-05-01 23:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105449
Bug ID: 105449
Summary: suspicious optimization since GCC 10.1.0 from -
Product: gcc
Version: 10.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: gilles.gouaillardet at gmail dot com
Target Milestone: ---
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/105449] suspicious optimization since GCC 10.1.0 from -
2022-05-01 23:41 [Bug c/105449] New: suspicious optimization since GCC 10.1.0 from - gilles.gouaillardet at gmail dot com
@ 2022-05-01 23:42 ` gilles.gouaillardet at gmail dot com
2022-05-01 23:52 ` [Bug c/105449] suspicious optimization since GCC 10.1.0 from -O2 gilles.gouaillardet at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: gilles.gouaillardet at gmail dot com @ 2022-05-01 23:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105449
--- Comment #1 from Gilles Gouaillardet <gilles.gouaillardet at gmail dot com> ---
Created attachment 52916
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52916&action=edit
a simple reproducer
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/105449] suspicious optimization since GCC 10.1.0 from -O2
2022-05-01 23:41 [Bug c/105449] New: suspicious optimization since GCC 10.1.0 from - gilles.gouaillardet at gmail dot com
2022-05-01 23:42 ` [Bug c/105449] " gilles.gouaillardet at gmail dot com
@ 2022-05-01 23:52 ` gilles.gouaillardet at gmail dot com
2022-05-02 0:00 ` pinskia at gcc dot gnu.org
2022-05-02 0:25 ` gilles.gouaillardet at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: gilles.gouaillardet at gmail dot com @ 2022-05-01 23:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105449
Gilles Gouaillardet <gilles.gouaillardet at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |gilles.gouaillardet at gmail dot c
| |om
Summary|suspicious optimization |suspicious optimization
|since GCC 10.1.0 from - |since GCC 10.1.0 from -O2
--- Comment #2 from Gilles Gouaillardet <gilles.gouaillardet at gmail dot com> ---
The attached reproducer works fine when using -O1 or less aggressive
optimization and on all GCC versions I tested.
However, starting from GCC 10.1.0 and when using -O2 or more aggressive
optimization, the local_pos() subroutine behaves differently compared to the
global_pos() and volatile_pos() subroutines. All these subroutines do virtually
the same things, but only the declaration of the bogus variable changes.
I suspect recent GCC versions perform some register inlining when the bogus
variable is declared as local and non volatile.
Can you please have a look at the reproducer and establish whether:
- this reproducer has an undefined behavior, and the recent optimizations are
legit
- this is a bug in GCC >= 10.1.0
For the record, here are my logs (on a x86_64 system, same behavior on aarch64.
Though I did not test, a different behavior is expected on a 64 bits big endian
processor).
$ gcc --version
gcc (GCC) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc bug.c && ./a.out
global: 0
local: 0
volatile: 0
$ gcc -O2 bug.c && ./a.out
global: 0
local: 2 <--- UNEXPECTED VALUE
volatile: 0
FWIW, a consequence of this optimization is an issue that has been reported at
https://github.com/open-mpi/ompi/issues/10339
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/105449] suspicious optimization since GCC 10.1.0 from -O2
2022-05-01 23:41 [Bug c/105449] New: suspicious optimization since GCC 10.1.0 from - gilles.gouaillardet at gmail dot com
2022-05-01 23:42 ` [Bug c/105449] " gilles.gouaillardet at gmail dot com
2022-05-01 23:52 ` [Bug c/105449] suspicious optimization since GCC 10.1.0 from -O2 gilles.gouaillardet at gmail dot com
@ 2022-05-02 0:00 ` pinskia at gcc dot gnu.org
2022-05-02 0:25 ` gilles.gouaillardet at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-02 0:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105449
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
You are violating C/C++ aliasing rules.
You have a store as "void*" but then access it as an "int*"
void * bogus = (void*) 1;
int *p = (int *) &bogus;
...
if (p[pos] == 1) {
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/105449] suspicious optimization since GCC 10.1.0 from -O2
2022-05-01 23:41 [Bug c/105449] New: suspicious optimization since GCC 10.1.0 from - gilles.gouaillardet at gmail dot com
` (2 preceding siblings ...)
2022-05-02 0:00 ` pinskia at gcc dot gnu.org
@ 2022-05-02 0:25 ` gilles.gouaillardet at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: gilles.gouaillardet at gmail dot com @ 2022-05-02 0:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105449
--- Comment #4 from Gilles Gouaillardet <gilles.gouaillardet at gmail dot com> ---
Thanks for the clarification!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-05-02 0:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-01 23:41 [Bug c/105449] New: suspicious optimization since GCC 10.1.0 from - gilles.gouaillardet at gmail dot com
2022-05-01 23:42 ` [Bug c/105449] " gilles.gouaillardet at gmail dot com
2022-05-01 23:52 ` [Bug c/105449] suspicious optimization since GCC 10.1.0 from -O2 gilles.gouaillardet at gmail dot com
2022-05-02 0:00 ` pinskia at gcc dot gnu.org
2022-05-02 0:25 ` gilles.gouaillardet at gmail dot com
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).