This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC] A new data structure for SWITCH_EXPR
Andrew Pinski <pinskia@physics.uc.edu> writes:
> On Nov 8, 2004, at 12:15 AM, Zack Weinberg wrote:
>> 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).
I think both your examples are artificial. I think the common case
(at least the common case where the switch is large enough to be a
bottleneck) is lots and lots of DISJOINT case labels. Think Yacc
parsers, or the bytecode interpreter in libjava.
zw