This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug optimization/14583] New: a switch statement can be converted to an array access
- From: "kazu at cs dot umass dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Mar 2004 16:11:48 -0000
- Subject: [Bug optimization/14583] New: a switch statement can be converted to an array access
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
>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