Hi!

Cong's patch fixes these two PRs, I've bootstrapped/regtested the backport
on 4.8 branch together with the new tests, ok for 4.8?
Are the new tests ok for trunk/4.9?

2014-09-08  Jakub Jelinek  <ja...@redhat.com>

        PR tree-optimization/60196
        PR tree-optimization/63189
        Backported from mainline
        2013-09-17  Cong Hou  <co...@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/pr63189.c: New test.
        * gcc.dg/vect/pr60196-1.c: New test.
        * gcc.dg/vect/pr60196-2.c: New test.

        Backported from mainline
        2013-09-17  Cong Hou  <co...@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.

--- gcc/tree-vect-patterns.c    (revision 202662)
+++ gcc/tree-vect-patterns.c    (revision 202663)
@@ -397,7 +397,7 @@ vect_recog_dot_prod_pattern (vec<gimple>
           || !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;
--- gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16c.c     (revision 0)
+++ gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16c.c     (revision 202663)
@@ -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" } } */
+
--- gcc/testsuite/gcc.dg/vect/pr63189.c.jj      2014-09-08 18:20:52.217190980 
+0200
+++ gcc/testsuite/gcc.dg/vect/pr63189.c 2014-09-08 18:23:03.088551066 +0200
@@ -0,0 +1,26 @@
+/* PR tree-optimization/63189 */
+/* { dg-do run } */
+
+#include "tree-vect.h"
+
+short int d[16] = { 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+__attribute__((noinline, noclone)) void
+foo (void)
+{
+  int j, s = 0;
+  for (j = 0; j < 8; j++)
+    s += d[j] * j;
+  if (s != 7)
+    abort ();
+}
+
+int
+main ()
+{
+  check_vect ();
+  foo ();
+  return 0;
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */
--- gcc/testsuite/gcc.dg/vect/pr60196-1.c.jj    2014-09-08 18:24:54.184008171 
+0200
+++ gcc/testsuite/gcc.dg/vect/pr60196-1.c       2014-09-08 18:30:39.351317988 
+0200
@@ -0,0 +1,34 @@
+/* PR tree-optimization/63189 */
+/* { dg-additional-options "-fwrapv" } */
+/* { dg-do run } */
+
+#include "tree-vect.h"
+
+__attribute__((noinline, noclone)) static int
+bar (const short *a, int len)
+{
+  int x;
+  int x1 = 0;
+
+  for (x = 0; x < len; x++)
+    x1 += x * a[x];
+  return x1;
+}
+
+__attribute__((noinline, noclone)) void
+foo (void)
+{
+  short stuff[9] = {1, 1, 1, 1, 1, 1, 1, 1, 1 };
+  if (bar (stuff, 9) != 36)
+    abort ();
+}
+
+int
+main ()
+{
+  check_vect ();
+  foo ();
+  return 0;
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */
--- gcc/testsuite/gcc.dg/vect/pr60196-2.c.jj    2014-09-08 18:27:06.814356716 
+0200
+++ gcc/testsuite/gcc.dg/vect/pr60196-2.c       2014-09-08 18:30:30.964358841 
+0200
@@ -0,0 +1,33 @@
+/* PR tree-optimization/63189 */
+/* { dg-do run } */
+
+#include "tree-vect.h"
+
+static const short a[8] = {1, 1, 1, 1, 1, 1, 1, 1 };
+static const unsigned char b[8] = {0, 0, 0, 0, 0, 0, 0, 0 };
+
+__attribute__((noinline, noclone)) static int
+bar (void)
+{
+  int sum = 0, i;
+  for (i = 0; i < 8; ++i)
+    sum += a[i] * b[i];
+  return sum;
+}
+
+__attribute__((noinline, noclone)) void
+foo (void)
+{
+  if (bar () != 0)
+    abort ();
+}
+
+int
+main ()
+{
+  check_vect ();
+  foo ();
+  return 0;
+}
+
+/* { dg-final { cleanup-tree-dump "vect" } } */

        Jakub

Reply via email to