[PATCH v6] Add QI vector mode support to by-pieces for memset

Richard Sandiford richard.sandiford@arm.com
Fri Jul 30 15:40:03 GMT 2021


"H.J. Lu via Gcc-patches" <gcc-patches@gcc.gnu.org> writes:
> +/* Callback routine for store_by_pieces.  Read GET_MODE_BITSIZE (MODE)
> +   bytes from constant string DATA + OFFSET and return it as target
> +   constant.  If PREV isn't nullptr, it has the RTL info from the
> +   previous iteration.  */
>  
> +rtx
> +builtin_memset_read_str (void *data, void *prev,
> +			 HOST_WIDE_INT offset ATTRIBUTE_UNUSED,
> +			 fixed_size_mode mode)
> +{
>    const char *c = (const char *) data;
> -  char *p = XALLOCAVEC (char, GET_MODE_SIZE (mode));
> +  unsigned int size = GET_MODE_SIZE (mode);
>  
> -  memset (p, *c, GET_MODE_SIZE (mode));
> +  rtx target = gen_memset_value_from_prev ((by_pieces_prev *) prev,
> +					   mode);
> +  if (target != nullptr)
> +    return target;
> +  rtx src = gen_int_mode (*c, QImode);
>  
> -  return c_readstr (p, mode);
> +  if (VECTOR_MODE_P (mode))
> +    {
> +      gcc_assert (GET_MODE_INNER (mode) == QImode);
> +
> +      rtx const_vec = gen_const_vec_duplicate (mode, src);
> +      if (prev == NULL)
> +	/* Return CONST_VECTOR when called by a query function.  */
> +	target = const_vec;
> +      else
> +	{
> +	  /* Use the move expander with CONST_VECTOR.  */
> +	  target = targetm.gen_memset_scratch_rtx (mode);
> +	  emit_move_insn (target, const_vec);
> +	}
> +
> +      return target;

I guess this is personal preference, sorry, but it seems more obvious
to me with an early return rather than an assignemnt to target:

      if (prev == NULL)
	/* Return CONST_VECTOR when called by a query function.  */
	return const_vec;

      /* Use the move expander with CONST_VECTOR.  */
      target = targetm.gen_memset_scratch_rtx (mode);
      emit_move_insn (target, const_vec);
      return target;

OK with that change, thanks, no need to repost.  (And thanks for
your patience.)

Richard


More information about the Gcc-patches mailing list