public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: liuhongt <hongtao.liu@intel.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Restrict the two sources of vect_recog_cond_expr_convert_pattern to be of the same type when convert is extension.
Date: Wed, 16 Feb 2022 15:15:40 +0100	[thread overview]
Message-ID: <20220216141540.GZ2646553@tucnak> (raw)
In-Reply-To: <20220216090309.82939-1-hongtao.liu@intel.com>

On Wed, Feb 16, 2022 at 05:03:09PM +0800, liuhongt via Gcc-patches wrote:
> > > +(match (cond_expr_convert_p @0 @2 @3 @6)
> > > + (cond (simple_comparison@6 @0 @1) (convert@4 @2) (convert@5 @3))
> > > +  (if (types_match (TREE_TYPE (@2), TREE_TYPE (@3))
> >
> > But in principle @2 or @3 could safely differ in sign, you'd then need to ensure
> > to insert sign conversions to @2/@3 to the signedness of @4/@5.
> >
> It turns out differ in sign is not suitable for extension(but ok for truncation),
> because it's zero_extend vs sign_extend.
> 
> The patch add types_match check when convert is extension.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}.
> And native Bootstrapped and regtested on CLX.
> 
> Ok for trunk?
> 
> gcc/ChangeLog:
> 
> 	PR tree-optimization/104551
> 	PR tree-optimization/103771
> 	* match.pd (cond_expr_convert_p): Add types_match check when
> 	convert is extension.
> 	* tree-vect-patterns.cc
> 	(gimple_cond_expr_convert_p): Adjust comments.
> 	(vect_recog_cond_expr_convert_pattern): Ditto.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.target/i386/pr104551.c: New test.
> ---
>  gcc/match.pd                             |  8 +++++---
>  gcc/testsuite/gcc.target/i386/pr104551.c | 24 ++++++++++++++++++++++++
>  gcc/tree-vect-patterns.cc                |  6 ++++--
>  3 files changed, 33 insertions(+), 5 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr104551.c
> 
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 05a10ab6bfd..8e80b9f1576 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -7692,11 +7692,13 @@ and,
>    (if (INTEGRAL_TYPE_P (type)
>         && INTEGRAL_TYPE_P (TREE_TYPE (@2))
>         && INTEGRAL_TYPE_P (TREE_TYPE (@0))
> -       && INTEGRAL_TYPE_P (TREE_TYPE (@3))
>         && TYPE_PRECISION (type) != TYPE_PRECISION (TREE_TYPE (@0))
>         && TYPE_PRECISION (TREE_TYPE (@0))
>  	  == TYPE_PRECISION (TREE_TYPE (@2))
> -       && TYPE_PRECISION (TREE_TYPE (@0))
> -	  == TYPE_PRECISION (TREE_TYPE (@3))
> +       && (types_match (TREE_TYPE (@2), TREE_TYPE (@3))
> +	   || ((TYPE_PRECISION (TREE_TYPE (@0))
> +		== TYPE_PRECISION (TREE_TYPE (@3)))
> +	       && INTEGRAL_TYPE_P (TREE_TYPE (@3))
> +	       && TYPE_PRECISION (TREE_TYPE (@3)) > TYPE_PRECISION (type)))
>         && single_use (@4)
>         && single_use (@5))))

I find this quite unreadable, it looks like if @2 and @3 are treated
differently.  I think keeping the old 3 lines and just adding
      && (TYPE_PRECISION (TREE_TYPE (@0)) >= TYPE_PRECISION (type)
	  || (TYPE_UNSIGNED (TREE_TYPE (@2))
	      == TYPE_UNSIGNED (TREE_TYPE (@3))))
after it ideally with a comment why would be better.
Note, if the precision of @0 and type is the same, I think signedness can
still differ, no?

	Jakub


  reply	other threads:[~2022-02-16 14:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24 13:01 [PATCH] [vect] Add vect_recog_cond_expr_convert_pattern liuhongt
2022-02-08  8:48 ` Richard Biener
2022-02-10  6:59   ` liuhongt
2022-02-11 12:29     ` Richard Biener
2022-02-16  9:03       ` [PATCH] Restrict the two sources of vect_recog_cond_expr_convert_pattern to be of the same type when convert is extension liuhongt
2022-02-16 14:15         ` Jakub Jelinek [this message]
2022-02-17  1:30           ` Hongtao Liu
2022-02-17  5:31             ` [PATCH V2] " liuhongt
2022-02-17  9:48               ` Richard Biener

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=20220216141540.GZ2646553@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hongtao.liu@intel.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).