public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r8-10801] tree-optimization/97081 - fix wrong-code with vectorized shift
@ 2021-03-17 10:20 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-03-17 10:20 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:16e2f38167eb90a4dc977b806dcc0dc9011cc456

commit r8-10801-g16e2f38167eb90a4dc977b806dcc0dc9011cc456
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Sep 18 13:36:24 2020 +0200

    tree-optimization/97081 - fix wrong-code with vectorized shift
    
    This corrects the mask for creation of x << s | x >> (-x & mask)
    from a rotate x <<r s to use the precision of x.
    
    2020-09-18  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/97081
            * tree-vect-patterns.c (vect_recog_rotate_pattern): Use the
            precision of the shifted operand to determine the mask.
    
            * gcc.dg/vect/pr97081.c: New testcase.
    
    (cherry picked from commit 86b25a1a5e1956c30fe7eaee80ebf719b759d631)

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr97081.c | 26 ++++++++++++++++++++++++++
 gcc/tree-vect-patterns.c            |  3 +--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr97081.c b/gcc/testsuite/gcc.dg/vect/pr97081.c
new file mode 100644
index 00000000000..bc83c88c019
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr97081.c
@@ -0,0 +1,26 @@
+#include "tree-vect.h"
+
+#define EXEC_ROR2(a, b, sz)     (a >> b) | (a << (64 - b))
+
+#define TYPE __UINT64_TYPE__
+
+void __attribute__((noipa))
+exec_VRORudi_i(TYPE *__restrict__ pvd,
+	       TYPE *__restrict__ const pva, unsigned char IMM)
+{
+  unsigned char I2 = IMM & 63;
+
+  for (unsigned i = 0; i < 4; i++)
+    pvd[i] = EXEC_ROR2(pva[i], I2, 8);
+}
+
+int main()
+{
+  check_vect ();
+
+  TYPE pvd[4], pva[4] = { 0x0102030405060708, 0x0102030405060708, 0x0102030405060708, 0x0102030405060708 };
+  exec_VRORudi_i (pvd, pva, 7);
+  if (pvd[0] != 0x10020406080a0c0e)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index de21c4bbd3f..24a8c903c0f 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -1984,7 +1984,6 @@ vect_recog_rotate_pattern (vec<gimple *> *stmts, tree *type_in, tree *type_out)
       append_pattern_def_seq (stmt_vinfo, def_stmt);
     }
   stype = TREE_TYPE (def);
-  scalar_int_mode smode = SCALAR_INT_TYPE_MODE (stype);
 
   if (TREE_CODE (def) == INTEGER_CST)
     {
@@ -2019,7 +2018,7 @@ vect_recog_rotate_pattern (vec<gimple *> *stmts, tree *type_in, tree *type_out)
 	}
 
       def2 = vect_recog_temp_ssa_var (stype, NULL);
-      tree mask = build_int_cst (stype, GET_MODE_PRECISION (smode) - 1);
+      tree mask = build_int_cst (stype, GET_MODE_PRECISION (mode) - 1);
       def_stmt = gimple_build_assign (def2, BIT_AND_EXPR,
 				      gimple_assign_lhs (def_stmt), mask);
       if (ext_def)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-03-17 10:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17 10:20 [gcc r8-10801] tree-optimization/97081 - fix wrong-code with vectorized shift Richard Biener

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).