public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/104574] New: GCC misses basic optimization for restricted pointers
@ 2022-02-16 18:54 marc@nieper-wisskirchen.de
2022-02-16 21:35 ` [Bug tree-optimization/104574] " pinskia at gcc dot gnu.org
2022-02-16 21:37 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: marc@nieper-wisskirchen.de @ 2022-02-16 18:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104574
Bug ID: 104574
Summary: GCC misses basic optimization for restricted pointers
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: marc@nieper-wisskirchen.de
Target Milestone: ---
The following TU
void g (void);
int
f (int *restrict p)
{
p[0] = 7;
g ();
return p[0];
}
is compiled by GCC at -O3 to
f:
pushq %rbx
movq %rdi, %rbx
movl $7, (%rdi)
call g
movl (%rbx), %eax
popq %rbx
ret
Obviously, GCC seems to think that g may modify the data reachable through p.
However, if g did that it would cause undefined behavior anyway.
So GCC misses a simple optimization opportunity here; it doesn't have to reload
the memory contents after the call to g; in fact, the function will always
return 7.
For comparison, Clang compiles the TU to
f:
pushq %rax
movl $7, (%rdi)
callq g
movl $7, %eax
popq %rcx
retq
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/104574] GCC misses basic optimization for restricted pointers
2022-02-16 18:54 [Bug tree-optimization/104574] New: GCC misses basic optimization for restricted pointers marc@nieper-wisskirchen.de
@ 2022-02-16 21:35 ` pinskia at gcc dot gnu.org
2022-02-16 21:37 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-16 21:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104574
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/104574] GCC misses basic optimization for restricted pointers
2022-02-16 18:54 [Bug tree-optimization/104574] New: GCC misses basic optimization for restricted pointers marc@nieper-wisskirchen.de
2022-02-16 21:35 ` [Bug tree-optimization/104574] " pinskia at gcc dot gnu.org
@ 2022-02-16 21:37 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-16 21:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104574
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 89479.
*** This bug has been marked as a duplicate of bug 89479 ***
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-16 21:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-16 18:54 [Bug tree-optimization/104574] New: GCC misses basic optimization for restricted pointers marc@nieper-wisskirchen.de
2022-02-16 21:35 ` [Bug tree-optimization/104574] " pinskia at gcc dot gnu.org
2022-02-16 21: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).