public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>,
	Richard Biener <rguenther@suse.de>,
	Richard Sandiford <rdsandiford@googlemail.com>,
	Jason Merrill <jason@redhat.com>,
	"Joseph S. Myers" <joseph@codesourcery.com>,
	Jan Hubicka <jh@suse.cz>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Add __builtin_convertvector support (PR c++/85052)
Date: Thu, 03 Jan 2019 17:04:00 -0000	[thread overview]
Message-ID: <b82830f1-96d4-17be-fec7-7aa4ef9e3382@gmail.com> (raw)
In-Reply-To: <20190103100640.GM30353@tucnak>

> +/* Build a VEC_CONVERT ifn for __builtin_convertvector builtin.  */

Can you please document the function arguments and explain how they
are used?

> +
> +tree
> +c_build_vec_convert (location_t loc1, tree expr, location_t loc2, tree type,
> +		     bool complain)
> +{
> +  if (error_operand_p (type))
> +    return error_mark_node;
> +  if (error_operand_p (expr))
> +    return error_mark_node;
> +
> +  if (!VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr))
> +      && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (expr)))
> +    {
> +      if (complain)
> +	error_at (loc1, "%<__builtin_convertvector%> first argument must "
> +			"be an integer or floating vector");
> +      return error_mark_node;
> +    }
> +
> +  if (!VECTOR_INTEGER_TYPE_P (type) && !VECTOR_FLOAT_TYPE_P (type))
> +    {
> +      if (complain)
> +	error_at (loc2, "%<__builtin_convertvector%> second argument must "
> +			"be an integer or floating vector type");
> +      return error_mark_node;
> +    }
> +
> +  if (maybe_ne (TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)),
> +		TYPE_VECTOR_SUBPARTS (type)))
> +    {
> +      if (complain)
> +	error_at (loc1, "%<__builtin_convertvector%> number of elements "
> +			"of the first argument vector and the second argument "
> +			"vector type should be the same");
> +      return error_mark_node;
> +    }

Just a few wording suggestions for the errors:

1) for the first two errors consider using a single message
    parameterized on the argument number to reduce translation effort
    (both styles are in use but the more concise form seems preferable
    to me)
2) in the last error use "must" instead of "should" as in the first
    two ("must" is imperative rather than just suggestive)
3) consider simplifying the third message to "%<...%> argument
    vectors must have the same size" (or "the same number of
    elements") along the same lines as in c_build_vec_perm_expr.

> +
> +  if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (expr)))
> +       == TYPE_MAIN_VARIANT (TREE_TYPE (type)))
> +      || (VECTOR_INTEGER_TYPE_P (TREE_TYPE (expr))
> +	  && VECTOR_INTEGER_TYPE_P (type)
> +	  && (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (expr)))
> +	      == TYPE_PRECISION (TREE_TYPE (type)))))
> +    return build1_loc (loc1, VIEW_CONVERT_EXPR, type, expr);

The conditional above is very difficult to read, and without
a comment explaining its purpose, difficult to understand.
Introducing named temporaries for the repetitive subexpressions
would help with the readability (not just here but in rest of
the function as well).  A comment explaining what the conditional
handles would help with the latter.

> +
> +  bool wrap = true;
> +  bool maybe_const = false;
> +  tree ret;

Moving maybe_const to the conditional block where it's used and ret
to the point of its initialization just after that block would improve
readability.

> +  if (!c_dialect_cxx ())
> +    {
> +      /* Avoid C_MAYBE_CONST_EXPRs inside of VEC_CONVERT argument.  */
> +      expr = c_fully_fold (expr, false, &maybe_const);
> +      wrap &= maybe_const;
> +    }
> +
> +  ret = build_call_expr_internal_loc (loc1, IFN_VEC_CONVERT, type, 1, expr);
> +
> +  if (!wrap)
> +    ret = c_wrap_maybe_const (ret, true);
> +
> +  return ret;
>   }

Martin

      parent reply	other threads:[~2019-01-03 17:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-03 10:06 Jakub Jelinek
2019-01-03 10:48 ` Marc Glisse
2019-01-03 11:04   ` Jakub Jelinek
2019-01-03 17:32     ` Marc Glisse
2019-01-03 22:24       ` [PATCH] Add __builtin_convertvector support (PR c++/85052, take 2) Jakub Jelinek
2019-01-07  8:27         ` Richard Biener
2019-01-03 11:16 ` [PATCH] Add __builtin_convertvector support (PR c++/85052) Richard Biener
2019-01-03 12:11   ` Jakub Jelinek
2019-01-03 13:06 ` Richard Sandiford
2019-01-03 17:04 ` Martin Sebor [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b82830f1-96d4-17be-fec7-7aa4ef9e3382@gmail.com \
    --to=msebor@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jason@redhat.com \
    --cc=jh@suse.cz \
    --cc=joseph@codesourcery.com \
    --cc=rdsandiford@googlemail.com \
    --cc=rguenther@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).