[RFC] A new data structure for SWITCH_EXPR

Andrew Pinski pinskia@physics.uc.edu
Mon Nov 8 05:52:00 GMT 2004


On Nov 8, 2004, at 12:15 AM, Zack Weinberg wrote:

> Kazu Hirata <kazu@cs.umass.edu> writes:
>> I've been thinking what to do with SWITCH_EXPR.  I came up with one
>> possible solution.
>
> Keep in mind that I'm not sure what the problems are - I gather that
> there are time and possibly space complexity concerns with the way it
> works now, but that's all I know.
> First, I'd like to point out that use of the "case A ... B:" feature
> is extremely rare, at least when it's via the GNU extension to C.
> Perhaps other languages use it more frequently.  As such, it might
> make sense to drop CASE_HIGH entirely, having front ends break up A
> ... B into individual CASE_LABEL_NODEs for all the values in the
> range.  Ranges would get more expensive, but each individual case
> would get cheaper.

Or are they.
For an example, look at the following:
  void f();
  void g();

  void a(int b) {
   switch (b) {
          case 1 ... 2000:
            f();

          case 2001 ... 4000:
            g();
      }
  }

We would have 4000 case statements in this case which is very 
inefficient as you would
then have to look through all 4000 case statements instead of just 
three (one for the
default). Yes this is a made up case but we do have cases where we have
"case '0' ... '9':" all the time (yes spelt out but we combine them to 
save
space and do expand tricks on them).  (For the '0' ... '9' case we 
would have to do
8 less compares which can help a lot as shown above in the made up 
case).

-- Pinski



More information about the Gcc mailing list