public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111167] New: swapping around duplicated conditionals can produce better code
@ 2023-08-26 19:39 pinskia at gcc dot gnu.org
2023-08-26 19:39 ` [Bug tree-optimization/111167] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-26 19:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111167
Bug ID: 111167
Summary: swapping around duplicated conditionals can produce
better code
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take reduced from GCC's sources for lookup_attribute:
```
void f(int);
inline void canonicalize_attr_name(const char *&s, int l) {
if (l > 4 && s[0] == '_' && s[l - 1] == '_' )
s += 2;
}
void lookup_attribute(const char *attr_ns, int list, int t) {
if (attr_ns && attr_ns[0] != '_') {
canonicalize_attr_name(attr_ns, 5);
}
if (list == 0)
{
short attr_ns_len = attr_ns ? t : 0;
f(attr_ns_len);
}
}
```
In optimized we have:
```
if (attr_ns_25(D) != 0B)
goto <bb 4>; [70.00%]
else
goto <bb 3>; [30.00%]
<bb 3> [local count: 322122543]:
if (list_10(D) == 0)
goto <bb 6>; [50.00%]
else
goto <bb 7>; [50.00%]
<bb 4> [local count: 751619279]:
if (list_10(D) == 0)
goto <bb 5>; [50.00%]
else
goto <bb 7>; [50.00%]
```
But we should really just have:
if (list_10(D) == 0) goto bb7;
if (attr_ns_25(D) != 0B) goto bb5; else bb6;
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/111167] swapping around duplicated conditionals can produce better code
2023-08-26 19:39 [Bug tree-optimization/111167] New: swapping around duplicated conditionals can produce better code pinskia at gcc dot gnu.org
@ 2023-08-26 19:39 ` pinskia at gcc dot gnu.org
2023-08-26 19:55 ` pinskia at gcc dot gnu.org
2023-08-27 23:34 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-26 19:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111167
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/111167] swapping around duplicated conditionals can produce better code
2023-08-26 19:39 [Bug tree-optimization/111167] New: swapping around duplicated conditionals can produce better code pinskia at gcc dot gnu.org
2023-08-26 19:39 ` [Bug tree-optimization/111167] " pinskia at gcc dot gnu.org
@ 2023-08-26 19:55 ` pinskia at gcc dot gnu.org
2023-08-27 23:34 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-26 19:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111167
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
In this case the problem seems to be jump threading related.
If we did:
```
void f(int);
void lookup_attribute1(const char *attr_ns, int list, int t) {
short t1;
if (attr_ns) { if (list) {t1 = 0; goto L1;} return; }
if (list){t1 = t;goto L1;} else return;
L1:
f(t1);
}
```
I Notice clang does not do this either even though the original testcase seems
ok.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/111167] swapping around duplicated conditionals can produce better code
2023-08-26 19:39 [Bug tree-optimization/111167] New: swapping around duplicated conditionals can produce better code pinskia at gcc dot gnu.org
2023-08-26 19:39 ` [Bug tree-optimization/111167] " pinskia at gcc dot gnu.org
2023-08-26 19:55 ` pinskia at gcc dot gnu.org
@ 2023-08-27 23:34 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-27 23:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111167
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>Take reduced from GCC's sources for lookup_attribute:
Note it shows up even not in a reduced version of lookup_attribute too.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-27 23:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-26 19:39 [Bug tree-optimization/111167] New: swapping around duplicated conditionals can produce better code pinskia at gcc dot gnu.org
2023-08-26 19:39 ` [Bug tree-optimization/111167] " pinskia at gcc dot gnu.org
2023-08-26 19:55 ` pinskia at gcc dot gnu.org
2023-08-27 23:34 ` 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).