tree-vect-slp.c (vect_bb_slp_scalar_cost): Properly confine life to the active subtree.
authorRichard Biener <rguenther@suse.de>
Tue, 29 Aug 2017 07:04:31 +0000 (07:04 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 29 Aug 2017 07:04:31 +0000 (07:04 +0000)
2017-08-29  Richard Biener  <rguenther@suse.de>
Dominik Infuehr <dominik.infuehr@theobroma-systems.com>

* tree-vect-slp.c (vect_bb_slp_scalar_cost): Properly confine
life to the active subtree.

* gcc.dg/vect/costmodel/x86_64/costmodel-vect-slp.c: New testcase.

Co-Authored-By: Dominik Infuehr <dominik.infuehr@theobroma-systems.com>
From-SVN: r251398

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-vect-slp.c [new file with mode: 0644]
gcc/tree-vect-slp.c

index 9a60a80b7466b635e77ae4c881f21c14e7e63748..682f4054b040910e51420c020058088a96095c94 100644 (file)
@@ -1,3 +1,9 @@
+2017-08-29  Richard Biener  <rguenther@suse.de>
+       Dominik Infuehr <dominik.infuehr@theobroma-systems.com>
+
+       * tree-vect-slp.c (vect_bb_slp_scalar_cost): Properly confine
+       life to the active subtree.
+
 2017-08-28  Jeff Law  <law@redhat.com>
 
        * tree-ssa-dom.c (edge_info::record_simple_equiv): Call
index 0ffc4f9a70fb2d516e88e2bf9ac207ffc6ba370c..ed3c67423298a0f6c136acbaaf7a1fb6aa625a19 100644 (file)
@@ -1,3 +1,8 @@
+2017-08-29  Richard Biener  <rguenther@suse.de>
+       Dominik Infuehr <dominik.infuehr@theobroma-systems.com>
+
+       * gcc.dg/vect/costmodel/x86_64/costmodel-vect-slp.c: New testcase.
+
 2017-08-28  Jeff Law  <law@redhat.com>
 
        * gcc.dg/torture/pr57214.c: Fix type of loop counter.
diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-vect-slp.c b/gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-vect-slp.c
new file mode 100644 (file)
index 0000000..5121a88
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fdump-tree-slp-details" } */
+
+#define N 4
+
+int s1[N], s2[N], s3[N];
+void escape(int, int, int, int);
+
+void
+foo ()
+{
+  int t1, t2, t3, t4;
+
+  t1 = s1[0] + s2[0] + s3[0];
+  t2 = s1[1] + s2[1] + s3[1];
+  t3 = s1[2] + s2[2] + s3[2];
+  t4 = s1[3] + s2[3] + s3[3];
+
+  s3[0] = t1 - s1[0] * s2[0];
+  s3[1] = t2 - s1[1] * s2[1];
+  s3[2] = t3 - s1[2] * s2[2];
+  s3[3] = t4 - s1[3] * s2[3];
+
+  escape (t1, t2, t3, t4);
+}
+
+/* { dg-final { scan-tree-dump-not "vectorization is not profitable" "slp2" } } */
+/* { dg-final { scan-tree-dump "basic block vectorized" "slp2" } } */
index 04ecaab7fc35c98d1c5cc787dd8bb457b39eb2ef..2167293076f2a0494f2c7dee1d232c5a16da63a9 100644 (file)
@@ -2690,9 +2690,18 @@ vect_bb_slp_scalar_cost (basic_block bb,
       scalar_cost += stmt_cost;
     }
 
+  auto_vec<bool, 20> subtree_life;
   FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
-    if (SLP_TREE_DEF_TYPE (child) == vect_internal_def)
-      scalar_cost += vect_bb_slp_scalar_cost (bb, child, life);
+    {
+      if (SLP_TREE_DEF_TYPE (child) == vect_internal_def)
+       {
+         /* Do not directly pass LIFE to the recursive call, copy it to
+            confine changes in the callee to the current child/subtree.  */
+         subtree_life.safe_splice (*life);
+         scalar_cost += vect_bb_slp_scalar_cost (bb, child, &subtree_life);
+         subtree_life.truncate (0);
+       }
+    }
 
   return scalar_cost;
 }