public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110519] New: Optimize loop that only assigns to a local variable
@ 2023-07-02 9:28 roland.illig at gmx dot de
2023-07-02 13:11 ` [Bug tree-optimization/110519] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: roland.illig at gmx dot de @ 2023-07-02 9:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110519
Bug ID: 110519
Summary: Optimize loop that only assigns to a local variable
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: roland.illig at gmx dot de
Target Milestone: ---
~~~c
struct symbol {
struct symbol *next;
};
void f(const struct symbol *sym)
{
for (const struct symbol *s = sym; s != (void *)0; s = s->next)
do { } while (0);
}
~~~
The above code was extracted from
<https://github.com/NetBSD/src/blob/f74666e8d086952b27d76155223a5d497e69f5a8/usr.bin/xlint/lint1/decl.c#L1319>.
Several other compilers know that this loop has no side effects, even at low
optimization levels, see <https://godbolt.org/z/Y85EGcW3d>.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/110519] Optimize loop that only assigns to a local variable
2023-07-02 9:28 [Bug tree-optimization/110519] New: Optimize loop that only assigns to a local variable roland.illig at gmx dot de
@ 2023-07-02 13:11 ` pinskia at gcc dot gnu.org
2023-07-02 16:40 ` [Bug c/110519] " pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-02 13:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110519
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It is already done when compiling with c++ frontend ...
For C, it can only done for for loops. Which makes it hard to do with the way
gcc handles loops at this point.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/110519] Optimize loop that only assigns to a local variable
2023-07-02 9:28 [Bug tree-optimization/110519] New: Optimize loop that only assigns to a local variable roland.illig at gmx dot de
2023-07-02 13:11 ` [Bug tree-optimization/110519] " pinskia at gcc dot gnu.org
@ 2023-07-02 16:40 ` pinskia at gcc dot gnu.org
2023-07-02 16:45 ` pinskia at gcc dot gnu.org
2023-07-02 16:50 ` [Bug c/110519] Optimize for " pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-02 16:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110519
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|tree-optimization |c
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/110519] Optimize loop that only assigns to a local variable
2023-07-02 9:28 [Bug tree-optimization/110519] New: Optimize loop that only assigns to a local variable roland.illig at gmx dot de
2023-07-02 13:11 ` [Bug tree-optimization/110519] " pinskia at gcc dot gnu.org
2023-07-02 16:40 ` [Bug c/110519] " pinskia at gcc dot gnu.org
@ 2023-07-02 16:45 ` pinskia at gcc dot gnu.org
2023-07-02 16:50 ` [Bug c/110519] Optimize for " pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-02 16:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110519
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
See bug 94392 comment #3 on why the general case does not apply to C and why we
decided not enable it when using the C front-end.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/110519] Optimize for loop that only assigns to a local variable
2023-07-02 9:28 [Bug tree-optimization/110519] New: Optimize loop that only assigns to a local variable roland.illig at gmx dot de
` (2 preceding siblings ...)
2023-07-02 16:45 ` pinskia at gcc dot gnu.org
@ 2023-07-02 16:50 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-02 16:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110519
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Optimize loop that only |Optimize for loop that only
|assigns to a local variable |assigns to a local variable
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2023-07-02
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. As mentioned the general rule does not apply for C, only applies to
`for` loops.
That is it would be invalid to remove the following loop in C:
```
struct symbol {
struct symbol *next;
};
void f(const struct symbol *sym)
{
const struct symbol *s = sym;
{
start_loop:
if (s != (void *)0)
{
do { } while (0);
s = s->next;
goto start_loop;
}
}
}
```
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-07-02 16:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-02 9:28 [Bug tree-optimization/110519] New: Optimize loop that only assigns to a local variable roland.illig at gmx dot de
2023-07-02 13:11 ` [Bug tree-optimization/110519] " pinskia at gcc dot gnu.org
2023-07-02 16:40 ` [Bug c/110519] " pinskia at gcc dot gnu.org
2023-07-02 16:45 ` pinskia at gcc dot gnu.org
2023-07-02 16:50 ` [Bug c/110519] Optimize for " 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).