public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/14583] New: a switch statement can be converted to an array access
@ 2004-03-15 16:11 kazu at cs dot umass dot edu
2004-03-15 16:57 ` [Bug optimization/14583] " pinskia at gcc dot gnu dot org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-03-15 16:11 UTC (permalink / raw)
To: gcc-bugs
>From reverse_condition() from jump.c
enum rtx_code
reverse_condition (enum rtx_code code)
{
switch (code)
{
case EQ:
return NE;
case NE:
return EQ;
case GT:
return LE;
:
:
:
case LTGT:
return UNKNOWN;
default:
abort ();
}
}
All the cases except the last one returns a value, so the compiler
should be able to convert this switch statement to something like
code -= LOWER_BOUND;
if ((unsigned) code > UPPER_BOUND)
abort ();
tem = cases[code];
if (tem == DEFAULT_CASE)
abort ();
return tem;
I think this is a win for both code size and speed on most, if not
all, platforms.
This kind of switch should be fairly common, and people may not like
to use an array themselves if the switch condition is an enum, just
like reverse_condition() in jump.c.
tree-ssa may be a good place to detect this. I don't know if the
implementation should be done in tree-ssa or at expand time. One
thing we can do is that just like CALL_EXPR_TAILCALL, we could flag
this kind of switch statement in tree-ssa and then emit an optimized
switch statement at the expand time.
--
Summary: a switch statement can be converted to an array access
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: kazu at cs dot umass dot edu
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14583
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug optimization/14583] a switch statement can be converted to an array access
2004-03-15 16:11 [Bug optimization/14583] New: a switch statement can be converted to an array access kazu at cs dot umass dot edu
@ 2004-03-15 16:57 ` pinskia at gcc dot gnu dot org
2004-03-25 17:22 ` kazu at cs dot umass dot edu
2004-08-12 1:51 ` [Bug rtl-optimization/14583] " pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-15 16:57 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-03-15 16:57 -------
Confirmed, one thing that needs to be done to do this optimization is combine all the return
statements into one block for the switch statement, I think I can add that to tree-ssa-return.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |pessimizes-code
Last reconfirmed|0000-00-00 00:00:00 |2004-03-15 16:57:51
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14583
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug optimization/14583] a switch statement can be converted to an array access
2004-03-15 16:11 [Bug optimization/14583] New: a switch statement can be converted to an array access kazu at cs dot umass dot edu
2004-03-15 16:57 ` [Bug optimization/14583] " pinskia at gcc dot gnu dot org
@ 2004-03-25 17:22 ` kazu at cs dot umass dot edu
2004-08-12 1:51 ` [Bug rtl-optimization/14583] " pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-03-25 17:22 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From kazu at cs dot umass dot edu 2004-03-25 17:22 -------
Some hope of getting this fixed:
http://gcc.gnu.org/ml/gcc-patches/2004-03/msg02097.html
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14583
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug rtl-optimization/14583] a switch statement can be converted to an array access
2004-03-15 16:11 [Bug optimization/14583] New: a switch statement can be converted to an array access kazu at cs dot umass dot edu
2004-03-15 16:57 ` [Bug optimization/14583] " pinskia at gcc dot gnu dot org
2004-03-25 17:22 ` kazu at cs dot umass dot edu
@ 2004-08-12 1:51 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-12 1:51 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
OtherBugsDependingO| |16996
nThis| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14583
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-08-12 1:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-15 16:11 [Bug optimization/14583] New: a switch statement can be converted to an array access kazu at cs dot umass dot edu
2004-03-15 16:57 ` [Bug optimization/14583] " pinskia at gcc dot gnu dot org
2004-03-25 17:22 ` kazu at cs dot umass dot edu
2004-08-12 1:51 ` [Bug rtl-optimization/14583] " pinskia at gcc dot gnu dot 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).