[PATCH] rtl: constm64_rtx..const64_rtx

Segher Boessenkool segher@kernel.crashing.org
Wed Jun 2 22:43:59 GMT 2021


Hi!

On Wed, Jun 02, 2021 at 06:07:28PM +0100, Richard Sandiford wrote:
> Segher Boessenkool <segher@kernel.crashing.org> writes:
> > Since times immemorial there has been const_int_rtx for all values from
> > -64 to 64, but only constm1_rtx..const2_rtx have been available for
> > convenient use.  Change this, so that we can use all values in
> > {-64,...,64} in RTL easily.  This matters, because then we we just say
> >   if (XEXP (x, 1) == const16_rtx)
> > and things like that, since all const_int in that range are unique.  We
> > already do for -1, 0, 1, 2, but we could for everything.

> No strong objection, but personally I'd rather not add something
> that is very specific to VOIDmode CONST_INTs.  I realise it's very
> unlikely that we'll ever be able to give CONST_INTs their proper mode
> (no-one has the kind of time needed to do that), but I don't think we
> should make the switch actively harder either.

How does this make that harder?

Having no mode for CONST_INTs makes some things significantly *easier*
btw.  Well you know that, that is what makes any conversion away from
this so much harder :-)

We have has const0_rtx etc. since forever, this patch just increases the
range (to those values that have had guaranteed unique RTXes since
decades as well).

> How about adding a new inline helper function that tests whether an
> rtx is a CONST_INT with a given value?  Then we could have a
> __builtin_constant_p shortcut for the [-64, 64] case.  That would
> also avoid hard-coding the range.

Currently you have to write the example as
  if (XEXP (x, 1) == const_int_rtx[MAX_SAVED_CONST_INT + 16])
and with your suggestion it will be
  if (is_const_int_with_value (XEXP (x, 1), 16))

I like
  if (XEXP (x, 1) == const16_rtx)
better: it is shorter and clearer (often you have something like this is
more complex conditionals, it matters), and this pattern is already very
well known (for -1, 0, 1, 2).

Do you like this patch a bit better if I also add such an
is_const_int_with_value function?


Segher


More information about the Gcc-patches mailing list