public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
[parent not found: <20040315161146.14583.kazu@gcc.gnu.org>]
* [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-08-12  1:51 ` [Bug rtl-optimization/14583] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 3+ 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] 3+ messages in thread

end of thread, other threads:[~2008-09-08 19:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-14583-5009@http.gcc.gnu.org/bugzilla/>
2008-09-08 19:53 ` [Bug rtl-optimization/14583] a switch statement can be converted to an array access pinskia at gcc dot gnu dot org
     [not found] <20040315161146.14583.kazu@gcc.gnu.org>
2005-09-02 11:24 ` steven at gcc dot gnu dot org
2004-03-15 16:11 [Bug optimization/14583] New: " 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).