public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/103799] New: switch expansion could be smarter
@ 2021-12-22 7:44 pinskia at gcc dot gnu.org
2021-12-22 7:44 ` [Bug tree-optimization/103799] " pinskia at gcc dot gnu.org
2021-12-22 8:56 ` marxin at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-22 7:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103799
Bug ID: 103799
Summary: switch expansion could be smarter
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: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
auto f(char c)
{
int t1;
switch (c)
{
case '1':
t1 = 1;
break;
case '2':
t1 = 2;
break;
case '3':
t1 = 3;
break;
case '\0':
t1 = 4;
break;
default:
t1 = -1;
}
return t1;
}
auto f1(char c)
{
int t1;
switch (c)
{
case '1':
t1 = 1;
break;
case '2':
t1 = 2;
break;
case '3':
t1 = 3;
break;
default:
if (c == '\0') t1 = 4; else t1 = -1;
}
return t1;
}
f1 produces better code than f.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/103799] switch expansion could be smarter
2021-12-22 7:44 [Bug tree-optimization/103799] New: switch expansion could be smarter pinskia at gcc dot gnu.org
@ 2021-12-22 7:44 ` pinskia at gcc dot gnu.org
2021-12-22 8:56 ` marxin at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-22 7:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103799
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=95821
Severity|normal |enhancement
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I found this while looking into PR 95821.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/103799] switch expansion could be smarter
2021-12-22 7:44 [Bug tree-optimization/103799] New: switch expansion could be smarter pinskia at gcc dot gnu.org
2021-12-22 7:44 ` [Bug tree-optimization/103799] " pinskia at gcc dot gnu.org
@ 2021-12-22 8:56 ` marxin at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-12-22 8:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103799
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2021-12-22
Status|UNCONFIRMED |NEW
CC| |marxin at gcc dot gnu.org
--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #0)
> Take:
> auto f(char c)
> {
> int t1;
> switch (c)
> {
> case '1':
> t1 = 1;
> break;
> case '2':
> t1 = 2;
> break;
> case '3':
> t1 = 3;
> break;
> case '\0':
> t1 = 4;
> break;
> default:
> t1 = -1;
> }
> return t1;
> }
Confirmed. Here we have:
switch (_1) <default: <D.1986>, case 0: <D.1985>, case 49: <D.1982>, case 50:
<D.1983>, case 51: <D.1984>>
that's rejected by switch conversion [0, 51] range is quite sparse.
>
>
> auto f1(char c)
> {
> int t1;
> switch (c)
> {
> case '1':
> t1 = 1;
> break;
> case '2':
> t1 = 2;
> break;
> case '3':
> t1 = 3;
> break;
Here the first part is transformed by switch conversion as:
Linear transformation with A = 1 and B = -48
> default:
> if (c == '\0') t1 = 4; else t1 = -1;
And this is a classical
# t1_2 = PHI <4(4), -1(5), t1_5(3)>
So the idea of the transformation is basically to remove cases that "block"
and interesting switch optimization and handle these in default. Smart,
but not easy to achieve :P
> }
> return t1;
> }
>
> f1 produces better code than f.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-12-22 8:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-22 7:44 [Bug tree-optimization/103799] New: switch expansion could be smarter pinskia at gcc dot gnu.org
2021-12-22 7:44 ` [Bug tree-optimization/103799] " pinskia at gcc dot gnu.org
2021-12-22 8:56 ` marxin 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).