public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: "Kewen.Lin" <linkw@linux.ibm.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	 "Andre Vieira (lists)" <andre.simoesdiasvieira@arm.com>,
	 Segher Boessenkool <segher@kernel.crashing.org>,
	Richard Sandiford <richard.sandiford@arm.com>
Subject: Re: [PATCH] vect: Try folding first for shifted value generation [PR107240]
Date: Wed, 19 Oct 2022 09:43:33 +0200	[thread overview]
Message-ID: <CAFiYyc3=3RNQEi+qN+3-XKNwOp5JnNyHz4FMDX7Q8eZo+Asihg@mail.gmail.com> (raw)
In-Reply-To: <31c05be7-64bf-8d93-934c-63262e082e68@linux.ibm.com>

On Wed, Oct 19, 2022 at 5:18 AM Kewen.Lin <linkw@linux.ibm.com> wrote:
>
> Hi,
>
> As PR107240 shows, when both the value to be shifted and the
> count used for shifting are constants, it doesn't actually
> requires a target to support vector shift operations.
>
> This patch is to try fold_build2 for the generation of the
> shifted value first, if it's folded, the shift is gone,
> otherwise it's the same as before.
>
> It can help to make the failures of vect-bitfield-write-{2,3}.c
> gone on Power.
>
> Bootstrapped and regtested on x86_64-redhat-linux,
> aarch64-linux-gnu and powerpc64{,le}-linux-gnu.
>
> Is it ok for trunk?
>
> BR,
> Kewen
> -----
>         PR tree-optimization/107240
>
> gcc/ChangeLog:
>
>         * tree-vect-patterns.cc (vect_recog_bit_insert_pattern): Attempt to
>         fold shifted value.
> ---
>  gcc/tree-vect-patterns.cc | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
> index 6afd57a50c4..3beda774ec3 100644
> --- a/gcc/tree-vect-patterns.cc
> +++ b/gcc/tree-vect-patterns.cc
> @@ -2098,9 +2098,11 @@ vect_recog_bit_insert_pattern (vec_info *vinfo, stmt_vec_info stmt_info,
>    tree shifted = value;
>    if (shift_n)
>      {
> +      tree shifted_tmp
> +       = fold_build2 (LSHIFT_EXPR, container_type, value, shift);
>        pattern_stmt
>         = gimple_build_assign (vect_recog_temp_ssa_var (container_type),
> -                              LSHIFT_EXPR, value, shift);
> +                              shifted_tmp);

The canonical way would be to use

         gimple_seq stmts = NULL;
         shifted = gimple_build (&stmts, LSHIFT_EXPR, container_type,
value, shift);
         if (!gimple_seq_empty_p (stmts))
           append_pattern_def_seq (vinfo, stmt_info,
gimple_seq_first_stmt (stmts));

That also avoids the spurious val = constant; with your patch.

OK if that works.

thanks,
Richard.

>        append_pattern_def_seq (vinfo, stmt_info, pattern_stmt);
>        shifted = gimple_get_lhs (pattern_stmt);
>      }
> --
> 2.27.0

  reply	other threads:[~2022-10-19  7:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-19  3:18 Kewen.Lin
2022-10-19  7:43 ` Richard Biener [this message]
2022-10-19  8:51   ` Kewen.Lin

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='CAFiYyc3=3RNQEi+qN+3-XKNwOp5JnNyHz4FMDX7Q8eZo+Asihg@mail.gmail.com' \
    --to=richard.guenther@gmail.com \
    --cc=andre.simoesdiasvieira@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=linkw@linux.ibm.com \
    --cc=richard.sandiford@arm.com \
    --cc=segher@kernel.crashing.org \
    /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).