This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Canonicalising truncated shift counts


> The bug comes from two separate places.  First, nonzero_bits
> unconditionally applies the full shift count, regardless of the
> shift mode:
>
>       if (GET_CODE (XEXP (x, 1)) == CONST_INT
> 	  && INTVAL (XEXP (x, 1)) >= 0
> 	  && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT)
> 	{
> 	  int count = INTVAL (XEXP (x, 1));
>           [...]
> 	  if (code == LSHIFTRT)
> 	    inner >>= count;
>           [...etc...]
>
> And combine.c:force_to_mode does the same:
>
>     case LSHIFTRT:
>       [...]
>       if (GET_CODE (XEXP (x, 1)) == CONST_INT
> 	  && INTVAL (XEXP (x, 1)) < HOST_BITS_PER_WIDE_INT
> 	  && GET_MODE_BITSIZE (op_mode) <= HOST_BITS_PER_WIDE_INT)
> 	{
>           [...]
> 	  /* Select the mask of the bits we need for the shift operand.  */
> 	  inner_mask = mask << INTVAL (XEXP (x, 1));
>
> (with ASHIFT and ASHIFTRT cases being similarly affected).

I cannot believe that the problem doesn't seem to have arised before and 
that simultaneously the 2 above transformations would be so blatantly broken 
wrt SHIFT_COUNT_TRUNCATED targets.  In other words...

> It seems easierto just declare that, on SHIFT_COUNT_TRUNCATED targets, the
> canonical form of a constant shift count is to be truncated. 

...I think this is the implicit canonical form, see e.g. expand_shift.

> Regression-tested on mipsisa32-elf.  OK to install?

Almost. :-)

> 	* simplify-rtx.c (simplify_binary_operation_1): Canonicalize
> 	truncated shift counts.

Did you consider doing this canonicalization in simplify_gen_binary instead,
where the canonicalization for the commutative case is done?

-- 
Eric Botcazou


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]