tree-vect-patterns.c (vect_recog_dot_prod_pattern): Fix a bug when checking the dot...
authorCong Hou <congh@google.com>
Tue, 17 Sep 2013 18:20:08 +0000 (14:20 -0400)
committerCong Hou <congh@gcc.gnu.org>
Tue, 17 Sep 2013 18:20:08 +0000 (14:20 -0400)
2013-09-17  Cong Hou  <congh@google.com>

    * tree-vect-patterns.c (vect_recog_dot_prod_pattern): Fix a bug
      when checking the dot production pattern. The type of rhs operand
      of multiply is now checked correctly.

    * gcc.dg/vect/vect-reduc-dot-s16c.c: Add a test case with dot product
      on two arrays with short and int types. This should not be recognized
      as a dot product pattern.

From-SVN: r202663

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16c.c [new file with mode: 0644]
gcc/tree-vect-patterns.c

index 616a3f9baf2927095f8709b5f381a6ebfe31d1b2..0bb9263d442455e7d64b1aa15b2d4b622d530dad 100644 (file)
@@ -1,3 +1,9 @@
+2013-09-17  Cong Hou  <congh@google.com>
+
+       * tree-vect-patterns.c (vect_recog_dot_prod_pattern): Fix a bug
+       when checking the dot production pattern. The type of rhs operand
+       of multiply is now checked correctly.
+
 2013-09-17  Jeff Law  <law@redhat.com>
 
        * tree-ssa-dom.c (cprop_into_successor_phis): Also propagate
index 205dee8b01f5db204a4e84a88cb3abb584876551..796e14343c22827ff14dd30a4bb40f70bafc4de8 100644 (file)
@@ -1,3 +1,9 @@
+2013-09-17  Cong Hou  <congh@google.com>
+
+       * gcc.dg/vect/vect-reduc-dot-s16c.c: Add a test case with dot product 
+       on two arrays with short and int types. This should not be recognized
+       as a dot product pattern.
+
 2013-09-17  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/58435
diff --git a/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16c.c b/gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16c.c
new file mode 100644 (file)
index 0000000..8ba823b
--- /dev/null
@@ -0,0 +1,73 @@
+/* { dg-require-effective-target vect_int } */
+
+#include <stdarg.h>
+#include "tree-vect.h"
+
+#define N 64
+#define DOT 43680
+
+signed short X[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__)));
+signed int   Y[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__)));
+
+/* (short, int)->int->int dot product.
+   Not detected as a dot-product pattern.  */
+
+__attribute__ ((noinline)) int
+foo (int len)
+{
+  int i;
+  int result = 0;
+
+  for (i = 0; i < len; i++)
+    {
+      result += (X[i] * Y[i]);
+    }
+  return result;
+}
+
+
+/* (int, short)->int->int dot product.
+   Not detected as a dot-product pattern.  */
+
+__attribute__ ((noinline)) int
+bar (int len)
+{
+  int i;
+  int result = 0;
+
+  for (i = 0; i < len; i++)
+    {
+      result += (Y[i] * X[i]);
+    }
+  return result;
+}
+
+int
+main (void)
+{
+  int i;
+  int dot;
+
+  check_vect ();
+
+  for (i = 0; i < N; i++)
+    {
+      X[i] = i;
+      Y[i] = N - i;
+      __asm__ volatile ("");
+    }
+
+  dot = foo (N);
+  if (dot != DOT)
+    abort ();
+
+  dot = bar (N);
+  if (dot != DOT)
+    abort ();
+
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { target vect_unpack } } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
+
index 30372522832d85e7ca5f73713db2b45c2b919299..0a4e812fd823d574d6bc8a760185550cc11b19f9 100644 (file)
@@ -397,7 +397,7 @@ vect_recog_dot_prod_pattern (vec<gimple> *stmts, tree *type_in,
           || !promotion)
         return NULL;
       oprnd00 = gimple_assign_rhs1 (def_stmt);
-      if (!type_conversion_p (oprnd0, stmt, true, &half_type1, &def_stmt,
+      if (!type_conversion_p (oprnd1, stmt, true, &half_type1, &def_stmt,
                                 &promotion)
           || !promotion)
         return NULL;