public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-4679] vect-patterns: Fix up vect_recog_rotate_pattern [PR108064]
Date: Tue, 13 Dec 2022 15:55:58 +0000 (GMT)	[thread overview]
Message-ID: <20221213155558.08EDA383D8EF@sourceware.org> (raw)

https://gcc.gnu.org/g:33be3ee36a7e2c0be383ec01b5fbc9aef39568fd

commit r13-4679-g33be3ee36a7e2c0be383ec01b5fbc9aef39568fd
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Dec 13 16:55:21 2022 +0100

    vect-patterns: Fix up vect_recog_rotate_pattern [PR108064]
    
    Since vect_recog_rotate_pattern has been extended to work also
    on signed types in r13-1100 we miscompile the testcase below.
    vect_recog_rotate_pattern actually emits correct scalar code into
    the pattern def sequence (in particular cast to utype, doing the
    2 shifts in utype so that the right shift is logical and not arithmetic,
    or and then cast back to the signed type), but it didn't supply vectype
    for most of those pattern statements, which means that the generic handling
    fills it up later with the vectype provided by vect_recog_rotate_pattern.
    The problem is that it is vectype of the result of the whole pattern,
    i.e. vector of signed values in this case, while the conversion to utype,
    2 shifts and or (everything with utype lhs in scalar code) should have
    uvectype as STMT_VINFO_VECTYPE.
    
    2022-12-13  Jakub Jelinek  <jakub@redhat.com>
    
            PR tree-optimization/108064
            * tree-vect-patterns.cc (vect_recog_rotate_pattern): Pass uvectype
            as 4th argument to append_pattern_def_seq for statements with lhs
            with utype type.
    
            * gcc.c-torture/execute/pr108064.c: New test.

Diff:
---
 gcc/testsuite/gcc.c-torture/execute/pr108064.c | 28 ++++++++++++++++++++++++++
 gcc/tree-vect-patterns.cc                      | 10 ++++-----
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.c-torture/execute/pr108064.c b/gcc/testsuite/gcc.c-torture/execute/pr108064.c
new file mode 100644
index 00000000000..a7170bcf17b
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr108064.c
@@ -0,0 +1,28 @@
+/* PR tree-optimization/108064 */
+
+static inline short
+foo (short value)
+{
+  return ((value >> 8) & 0xff) | ((value & 0xff) << 8);
+}
+
+__attribute__((noipa))
+void
+bar (short *d, const short *s)
+{
+  for (unsigned long i = 0; i < 4; i++)
+    d[i] = foo (s[i]);
+}
+
+int
+main ()
+{
+  short a[4] __attribute__((aligned (16))) = { 0xff, 0, 0, 0 };
+  short b[4] __attribute__((aligned (16)));
+  short c[4] __attribute__((aligned (16)));
+
+  bar (b, a);
+  bar (c, b);
+  if (a[0] != c[0])
+    __builtin_abort ();
+}
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc
index d9fdb24ee62..32f95a7a409 100644
--- a/gcc/tree-vect-patterns.cc
+++ b/gcc/tree-vect-patterns.cc
@@ -3113,7 +3113,7 @@ vect_recog_rotate_pattern (vec_info *vinfo,
     {
       def = vect_recog_temp_ssa_var (utype, NULL);
       def_stmt = gimple_build_assign (def, NOP_EXPR, oprnd0);
-      append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt);
+      append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, uvectype);
       oprnd0 = def;
     }
 
@@ -3137,7 +3137,7 @@ vect_recog_rotate_pattern (vec_info *vinfo,
     {
       def = vect_recog_temp_ssa_var (utype, NULL);
       def_stmt = gimple_build_assign (def, NOP_EXPR, oprnd1);
-      append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt);
+      append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, uvectype);
     }
   stype = TREE_TYPE (def);
 
@@ -3185,13 +3185,13 @@ vect_recog_rotate_pattern (vec_info *vinfo,
   def_stmt = gimple_build_assign (var1, rhs_code == LROTATE_EXPR
 					? LSHIFT_EXPR : RSHIFT_EXPR,
 				  oprnd0, def);
-  append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt);
+  append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, uvectype);
 
   var2 = vect_recog_temp_ssa_var (utype, NULL);
   def_stmt = gimple_build_assign (var2, rhs_code == LROTATE_EXPR
 					? RSHIFT_EXPR : LSHIFT_EXPR,
 				  oprnd0, def2);
-  append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt);
+  append_pattern_def_seq (vinfo, stmt_vinfo, def_stmt, uvectype);
 
   /* Pattern detected.  */
   vect_pattern_detected ("vect_recog_rotate_pattern", last_stmt);
@@ -3202,7 +3202,7 @@ vect_recog_rotate_pattern (vec_info *vinfo,
 
   if (!useless_type_conversion_p (type, utype))
     {
-      append_pattern_def_seq (vinfo, stmt_vinfo, pattern_stmt);
+      append_pattern_def_seq (vinfo, stmt_vinfo, pattern_stmt, uvectype);
       tree result = vect_recog_temp_ssa_var (type, NULL);
       pattern_stmt = gimple_build_assign (result, NOP_EXPR, var);
     }

                 reply	other threads:[~2022-12-13 15:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20221213155558.08EDA383D8EF@sourceware.org \
    --to=jakub@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.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).