switch index optimization
Joe Buck
jbuck@synopsys.com
Sun Jan 25 23:02:00 GMT 1998
> The talk on linux-kernel about the bogus non-void function returns
> without a value warning you get from
>
> int foo(int x, int y) {
> switch (x & 3) {
> case 0: ...; return y;
> case 1: ...; return y;
> case 2: ...; return y;
> case 3: ...; return y;
> }
> }
>
> got me thinking. The following patch won't actually fix this case,
> since this is below the threshold for a tablejump, but it points the
> way, and does do some good.
[ patch deleted ]
Not a bad idea, but kind of an unclean implementation.
If you're going to start putting in recognizers for expressions that
have restricted ranges, I think it would be better to put them
in a separate function, and write it in a clean way so you can cover
more cases. The function would return the range (or an over-approximation
of the range) of the expression. You could then cleanly handle bitwise
and, modulo, branching on a char, etc.
But to do really well, range propagation needs to be done with dataflow
analysis (though in this case you can do it without).
More information about the Gcc
mailing list