public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: liuhongt <hongtao.liu@intel.com>
To: gcc-patches@gcc.gnu.org
Cc: jakub@redhat.com
Subject: [PATCH V2] Restrict the two sources of vect_recog_cond_expr_convert_pattern to be of the same type when convert is extension.
Date: Thu, 17 Feb 2022 13:31:26 +0800	[thread overview]
Message-ID: <20220217053126.49814-1-hongtao.liu@intel.com> (raw)
In-Reply-To: <CAMZc-bwEBxYuhNeqmThaYm_p9HWNyGdtq6kFC8X6gs5J0-ud+Q@mail.gmail.com>

> 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.
Update patch.

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                             |  6 ++++++
 gcc/testsuite/gcc.target/i386/pr104551.c | 24 ++++++++++++++++++++++++
 gcc/tree-vect-patterns.cc                |  6 ++++--
 3 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr104551.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 05a10ab6bfd..8b6f22f1065 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -7698,5 +7698,11 @@ and,
 	  == TYPE_PRECISION (TREE_TYPE (@2))
        && TYPE_PRECISION (TREE_TYPE (@0))
 	  == TYPE_PRECISION (TREE_TYPE (@3))
+       /* For vect_recog_cond_expr_convert_pattern, @2 and @3 can differ in
+	  signess when convert is truncation, but not ok for extension since
+	  it's sign_extend vs zero_extend.  */
+       && (TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (type)
+	   || (TYPE_UNSIGNED (TREE_TYPE (@2))
+	       == TYPE_UNSIGNED (TREE_TYPE (@3))))
        && single_use (@4)
        && single_use (@5))))
diff --git a/gcc/testsuite/gcc.target/i386/pr104551.c b/gcc/testsuite/gcc.target/i386/pr104551.c
new file mode 100644
index 00000000000..6300f25c0d5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr104551.c
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+/* { dg-options "-O3 -mavx2" } */
+/* { dg-require-effective-target avx2 } */
+
+unsigned int
+__attribute__((noipa))
+test(unsigned int a, unsigned char p[16]) {
+  unsigned int res = 0;
+  for (unsigned b = 0; b < a; b += 1)
+    res = p[b] ? p[b] : (char) b;
+  return res;
+}
+
+int main ()
+{
+  unsigned int a = 16U;
+  unsigned char p[16];
+  for (int i = 0; i != 16; i++)
+    p[i] = (unsigned char)128;
+  unsigned int res = test (a, p);
+  if (res != 128)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index a8f96d59643..217bdfd7045 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -929,8 +929,10 @@ vect_reassociating_reduction_p (vec_info *vinfo,
    with conditions:
    1) @1, @2, c, d, a, b are all integral type.
    2) There's single_use for both @1 and @2.
-   3) a, c and d have same precision.
+   3) a, c have same precision.
    4) c and @1 have different precision.
+   5) c, d are the same type or they can differ in sign when convert is
+   truncation.
 
    record a and c and d and @3.  */
 
@@ -952,7 +954,7 @@ extern bool gimple_cond_expr_convert_p (tree, tree*, tree (*)(tree));
    TYPE_PRECISION (TYPE_E) != TYPE_PRECISION (TYPE_CD);
    TYPE_PRECISION (TYPE_AB) == TYPE_PRECISION (TYPE_CD);
    single_use of op_true and op_false.
-   TYPE_AB could differ in sign.
+   TYPE_AB could differ in sign when (TYPE_E) A is a truncation.
 
    Input:
 
-- 
2.18.1


  reply	other threads:[~2022-02-17  5:31 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
2022-02-17  1:30           ` Hongtao Liu
2022-02-17  5:31             ` liuhongt [this message]
2022-02-17  9:48               ` [PATCH V2] " 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=20220217053126.49814-1-hongtao.liu@intel.com \
    --to=hongtao.liu@intel.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.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).