public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Richard Sandiford <richard.sandiford@arm.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] fold: Optimise fold_view_convert_expr
Date: Mon, 6 Dec 2021 08:58:05 +0100	[thread overview]
Message-ID: <CAFiYyc0BBWm8wLr+u7FKME7ikzcNcTHBVkb+SnUFuMHiFuT+wg@mail.gmail.com> (raw)
In-Reply-To: <mpt7dcisof6.fsf@arm.com>

On Sun, Dec 5, 2021 at 11:00 PM Richard Sandiford via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> When compiling an optabs.ii at -O2 with a release-checking build,
> there were 210,172 calls to fold_view_convert_expr.  99.8% of them
> were conversions of an INTEGER_CST to an ENUMERAL_TYPE, so this patch
> adds a fast(er) path for that case.
>
> Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?
>
> Richard
>
>
> gcc/
>         * fold-const.c (fold_view_convert_expr): Add a fast path for
>         conversions of INTEGER_CSTs to other integral types.
> ---
>  gcc/fold-const.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/gcc/fold-const.c b/gcc/fold-const.c
> index 0b9a42f764a..19613015ddb 100644
> --- a/gcc/fold-const.c
> +++ b/gcc/fold-const.c
> @@ -9128,6 +9128,13 @@ fold_view_convert_vector_encoding (tree type, tree expr)
>  static tree
>  fold_view_convert_expr (tree type, tree expr)
>  {
> +  /* Conversions of INTEGER_CSTs to ENUMERAL_TYPEs are very common,
> +     so handle them directly.  */
> +  if (INTEGRAL_TYPE_P (type)
> +      && TREE_CODE (expr) == INTEGER_CST
> +      && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr)))
> +    return wide_int_to_tree (type, wi::to_wide (expr));

I suppose that TREE_CODE (expr) == INTEGER_CST &&
tree_nop_conversion_p (type, TREE_TYPE (expr))
might be more complete?  In fact, it might be possible to do

  if (TREE_CODE (expr) == INTEGER_CST)
    {
       gcc_checking_assert (tree_nop_conversion_p (type, TREE_TYPE (expr));
       return wide_int_to_tree (type, wi::to_wide (expr));
    }

or at least

  if (TREE_CODE (expr) == INTEGER_CST)
    {
       gcc_checking_assert (operand_equal_p (TYPE_SIZE (type),
TYPE_SIZE (TREE_TYPE (expr)));
       return wide_int_to_tree (type, wi::zext (wi::to_widest (expr),
TYPE_PRECISION (TREE_TYPE (expr)));
    }

but I realize IL verification around VIEW_CONVERTs is incomplete and
the above case
likely mostly happens with match.pd unifying the vector/non-vector
sign conversion path.

That said, the intent was to not have VIEW_CONVERT between types with
different precision
since on GIMPLE/GENERIC the off-precision bits have no representation
and thus cannot be
"converted" as unchanging.

Richard.


> +
>    /* We support up to 512-bit values (for V8DFmode).  */
>    unsigned char buffer[64];
>    int len;
> --
> 2.31.1
>

      reply	other threads:[~2021-12-06  7:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-05 21:59 Richard Sandiford
2021-12-06  7:58 ` Richard Biener [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=CAFiYyc0BBWm8wLr+u7FKME7ikzcNcTHBVkb+SnUFuMHiFuT+wg@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.sandiford@arm.com \
    /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).