]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Canonicalize vec_perm index to make the first index come from the first vector.
authorliuhongt <hongtao.liu@intel.com>
Tue, 18 Oct 2022 08:58:52 +0000 (16:58 +0800)
committerliuhongt <hongtao.liu@intel.com>
Wed, 19 Oct 2022 06:09:09 +0000 (14:09 +0800)
Fix unexpected non-canon form from gimple vector selector.

gcc/ChangeLog:

PR target/107271
* config/i386/i386-expand.cc (ix86_vec_perm_index_canon): New.
(expand_vec_perm_shufps_shufps): Call
ix86_vec_perm_index_canon

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr107271.c: New test.

gcc/config/i386/i386-expand.cc
gcc/testsuite/gcc.target/i386/pr107271.c [new file with mode: 0644]

index a0f8a98986ee9a5cb14504d18c8261da36f9e176..70fd82b27d44125a7efdaed364d71abf18049cc5 100644 (file)
@@ -19604,6 +19604,22 @@ expand_vec_perm_1 (struct expand_vec_perm_d *d)
   return false;
 }
 
+/* Canonicalize vec_perm index to make the first index
+   always comes from the first vector.  */
+static void
+ix86_vec_perm_index_canon (struct expand_vec_perm_d *d)
+{
+  unsigned nelt = d->nelt;
+  if (d->perm[0] < nelt)
+    return;
+
+  for (unsigned i = 0; i != nelt; i++)
+    d->perm[i] = (d->perm[i] + nelt) % (2 * nelt);
+
+  std::swap (d->op0, d->op1);
+  return;
+}
+
 /* A subroutine of ix86_expand_vec_perm_const_1. Try to implement D
    in terms of a pair of shufps+ shufps/pshufd instructions.  */
 static bool
@@ -19621,6 +19637,7 @@ expand_vec_perm_shufps_shufps (struct expand_vec_perm_d *d)
   if (d->testing_p)
     return true;
 
+  ix86_vec_perm_index_canon (d);
   for (i = 0; i < 4; ++i)
     count += d->perm[i] > 3 ? 1 : 0;
 
diff --git a/gcc/testsuite/gcc.target/i386/pr107271.c b/gcc/testsuite/gcc.target/i386/pr107271.c
new file mode 100644 (file)
index 0000000..fe89c9a
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O0" } */
+
+typedef int __attribute__((__vector_size__ (16))) V;
+
+static inline __attribute__((__always_inline__)) V
+bar (V v128u32_0)
+{
+  return __builtin_shuffle ((V){}, v128u32_0, v128u32_0);
+}
+
+V
+foo (void)
+{
+  return bar ((V){7, 4, 4});
+}