[PATCH] Implement switch statements with bit tests

Roger Sayle roger@www.eyesopen.com
Fri Jan 24 14:09:00 GMT 2003


> I don't see why you're stuck on SImode.  If I'm on a 64-bit target,
> then I ought to be able to use DImode as well.

I was originally thinking that SImode represented the natural
word size of the target.  I don't suppose you would consider
extending this strategy to DImode as the basis for a follow-up
patch, rather than a show stopper for this one?

> Recall that this is
>
> 	1UL << (int)X
> not
> 	1 << (long)X
>
This is a tricky one.  I wasn't sure if the distinction that you
make above is preserved by the time you reach RTL.  Do target
descriptions define ashlsi2qi?

It seems more a feature of front-ends with the undefined behaviour
beyond word size that "1UL << (int)X" is effectively written in RTL
as "1UL << (long)X", and "1 << (long)X" becomes "1 << (int)(long)X".
Notice on x86, ashlsi3 generates "sall %cl, %eax", yet %cl can't
hold an SImode value.


> I also think you ought to find the narrowest mode that fits the
> arguments.  If MAXVAL is 15, there's no reason we couldn't use
> HImode.

But this point is true.  In the same way that we should be able
to detect that the host is 64-bit and can use DImode, we should
also be able to use "ashlhi3" and "ashlqi3" for narrower ranges
of arguments.

I was already expecting some of this to happen with GCC's
transformations for reducing the mode of the bit-wise AND,
if the only the low bits are set in the constant.

Roger
--



More information about the Gcc-patches mailing list