This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Optimize tablejumps for switch statements
- To: Richard Henderson <rth at redhat dot com>
- Subject: Re: [PATCH] Optimize tablejumps for switch statements
- From: Roger Sayle <roger at eyesopen dot com>
- Date: Wed, 24 Oct 2001 16:56:37 -0600 (MDT)
- cc: <gcc-patches at gcc dot gnu dot org>
On Wed, 24 Oct 2001, Richard Henderson wrote:
> > * stmt.c (expand_end_case): Index jumptables from zero for
> > suitably small values of minval.
>
> Applied.
Thanks.
> > + if (! optimize_size
> > + && compare_tree_int (minval, 0) > 0
> > + && compare_tree_int (minval, 3) < 0
> > + && compare_tree_int (maxval, 0) >= 0)
>
> I don't think there's any need to check maxval, since
> we know that maxval >= minval.
This test is only needed to be safe with very large ranges. The code
below this hunk requires that "range" fits in a HOST_WIDE_INT. This
was tested for earlier in the routine by handling very large ranges near
the code:
/* RANGE may be signed and really large ranges will show up as
negative numbers. */
|| compare_tree_int (range, 0) < 0
Hence if "minval=1" and "maxval=HOST_WIDE_INT_MAX+1" then the optimization
should not be applied, as the range would fit before the optimization but
not after. Admittedly, this would be almost impossible to trigger, but
I thought it best to avoid failing if it ever did encounter a 2^32 entry
jump table.
Roger
--