]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/60656 (x86 vectorization produces wrong code)
authorCong Hou <congh@google.com>
Sat, 5 Apr 2014 01:27:21 +0000 (21:27 -0400)
committerCong Hou <congh@gcc.gnu.org>
Sat, 5 Apr 2014 01:27:21 +0000 (21:27 -0400)
2014-04-04  Cong Hou  <congh@google.com>

    PR tree-optimization/60656
    * tree-vect-stmts.c (supportable_widening_operation):
      Fix a bug that elements in a vector with vect_used_by_reduction
      property are incorrectly reordered when the operation on it is not
      consistant with the one in reduction operation.

2014-04-04  Cong Hou  <congh@google.com>

    PR tree-optimization/60656
    * gcc.dg/vect/pr60656.c: New test.

From-SVN: r209138

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/pr60656.c [new file with mode: 0644]
gcc/tree-vect-stmts.c

index c6d836576dadc47a46564c47c3b4e7114da23a4c..b561dce0c929a6c653b8b133f6f178d2fe75e9a1 100644 (file)
@@ -1,3 +1,11 @@
+2014-04-04  Cong Hou  <congh@google.com>
+
+       PR tree-optimization/60656
+       * tree-vect-stmts.c (supportable_widening_operation):
+       Fix a bug that elements in a vector with vect_used_by_reduction
+       property are incorrectly reordered when the operation on it is not
+       consistant with the one in reduction operation.
+
 2014-04-04  John David Anglin  <danglin@gcc.gnu.org>
 
        PR rtl-optimization/60155
index 7d030fd64a8913bba44da6604a2cb966527b47bf..a0af48c0502ef94b5ecbddf86f86a99d83ae0122 100644 (file)
@@ -1,3 +1,8 @@
+2014-04-04  Cong Hou  <congh@google.com>
+
+       PR tree-optimization/60656
+       * gcc.dg/vect/pr60656.c: New test.
+
 2014-04-04  Andreas Krebbel  <Andreas.Krebbel@de.ibm.com>
 
        * gcc.dg/builtin-bswap-6.c: Adjust return value to disable GCC
diff --git a/gcc/testsuite/gcc.dg/vect/pr60656.c b/gcc/testsuite/gcc.dg/vect/pr60656.c
new file mode 100644 (file)
index 0000000..ebaab62
--- /dev/null
@@ -0,0 +1,45 @@
+/* { dg-require-effective-target vect_int } */
+
+#include "tree-vect.h"
+
+__attribute__ ((noinline)) long
+foo ()
+{
+  int v[] = {5000, 5001, 5002, 5003};
+  long s = 0;
+  int i;
+
+  for(i = 0; i < 4; ++i)
+    {
+      long P = v[i];
+      s += P*P*P;
+    }
+  return s;
+}
+
+long
+bar ()
+{
+  int v[] = {5000, 5001, 5002, 5003};
+  long s = 0;
+  int i;
+
+  for(i = 0; i < 4; ++i)
+    {
+      long P = v[i];
+      s += P*P*P;
+      __asm__ volatile ("");
+    }
+  return s;
+}
+
+int main()
+{
+  if (foo () != bar ())
+    abort ();
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */
+/* { dg-final { cleanup-tree-dump "vect" } } */
+
index 884e769c8848a7a8e31c062636b4187e48f9162e..1a51d6d7b57a0d6d5214c5a67674414aa977417d 100644 (file)
@@ -7848,7 +7848,21 @@ supportable_widening_operation (enum tree_code code, gimple stmt,
                                             stmt, vectype_out, vectype_in,
                                             code1, code2, multi_step_cvt,
                                             interm_types))
-       return true;
+        {
+          /* Elements in a vector with vect_used_by_reduction property cannot
+             be reordered if the use chain with this property does not have the
+             same operation.  One such an example is s += a * b, where elements
+             in a and b cannot be reordered.  Here we check if the vector defined
+             by STMT is only directly used in the reduction statement.  */
+          tree lhs = gimple_assign_lhs (stmt);
+          use_operand_p dummy;
+          gimple use_stmt;
+          stmt_vec_info use_stmt_info = NULL;
+          if (single_imm_use (lhs, &dummy, &use_stmt)
+              && (use_stmt_info = vinfo_for_stmt (use_stmt))
+              && STMT_VINFO_DEF_TYPE (use_stmt_info) == vect_reduction_def)
+            return true;
+        }
       c1 = VEC_WIDEN_MULT_LO_EXPR;
       c2 = VEC_WIDEN_MULT_HI_EXPR;
       break;