re PR tree-optimization/71347 (Performance drop after r235513 on x86-64 in 32-bit...
authorBin Cheng <bin.cheng@arm.com>
Fri, 17 Jun 2016 09:26:05 +0000 (09:26 +0000)
committerBin Cheng <amker@gcc.gnu.org>
Fri, 17 Jun 2016 09:26:05 +0000 (09:26 +0000)
PR tree-optimization/71347
* tree-ssa-loop-ivopts.c (determine_group_iv_cost_address): Compute
cost for all uses in group.

PR tree-optimization/71347
* gcc.dg/tree-ssa/pr71347.c: New test.

From-SVN: r237552

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr71347.c [new file with mode: 0644]
gcc/tree-ssa-loop-ivopts.c

index aa2f101dcf11af025b83a6b0fd60902118520b0d..d804252b76c42bd19e66b5d971036f3d895bddb0 100644 (file)
@@ -1,3 +1,9 @@
+2016-06-17  Bin Cheng  <bin.cheng@arm.com>
+
+       PR tree-optimization/71347
+       * tree-ssa-loop-ivopts.c (determine_group_iv_cost_address): Compute
+       cost for all uses in group.
+
 2016-06-17 Bin Cheng  <bin.cheng@arm.com>
 
        * tree-vect-loop.c (vect_create_epilog_for_reduction): Only
index a80086ce3025d7f43395084ba7e78bab30059c89..f2893c18e68cef0e54f8c1b1c47671208e81ba5e 100644 (file)
@@ -1,3 +1,8 @@
+2016-06-17  Bin Cheng  <bin.cheng@arm.com>
+
+       PR tree-optimization/71347
+       * gcc.dg/tree-ssa/pr71347.c: New test.
+
 2016-06-17  Bin Cheng  <bin.cheng@arm.com>
 
        PR tree-optimization/71354
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71347.c b/gcc/testsuite/gcc.dg/tree-ssa/pr71347.c
new file mode 100644 (file)
index 0000000..c8f87a9
--- /dev/null
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+double in;
+extern void Write (double);
+void foo (void)
+{
+  static double X[9];
+  int i;
+        X[1] = in * in;
+        for (i = 2; i <= 8; i++)
+            X[i] = X[i - 1] * X[1];
+        Write (X[5]);
+}
+
+/* Load of X[i - i] can be omitted by reusing X[i] in previous iteration.  */
+/* { dg-final { scan-tree-dump-not ".* = MEM.*;" "optimized"} } */
index 1e8d6377360c07ecb2fec78bf232d7ddeb54e454..25b978085124f1ccdd91f6a52112c9c69bd97d11 100644 (file)
@@ -5115,7 +5115,7 @@ determine_group_iv_cost_address (struct ivopts_data *data,
 {
   unsigned i;
   bitmap depends_on;
-  bool can_autoinc, first = true;
+  bool can_autoinc;
   iv_inv_expr_ent *inv_expr = NULL;
   struct iv_use *use = group->vuses[0];
   comp_cost sum_cost = no_cost, cost;
@@ -5142,30 +5142,11 @@ determine_group_iv_cost_address (struct ivopts_data *data,
     {
       struct iv_use *next = group->vuses[i];
 
-      /* Compute cost for the first use with different offset to the main
-        use and add it afterwards.  Costs for these uses could be quite
-        different.  Given below uses in a group:
-          use 0  : {base + A + offset_0, step}
-          use 0.1: {base + A + offset_0, step}
-          use 0.2: {base + A + offset_1, step}
-          use 0.3: {base + A + offset_2, step}
-        when we need to compute costs with candidate:
-          cand 1 : {base + B + offset_0, step}
-
-        The first use with different offset is use 0.2, its cost is larger
-        than cost of use 0/0.1 because we need to compute:
-          A - B + offset_1 - offset_0
-          rather than:
-          A - B.  */
-      if (first && next->addr_offset != use->addr_offset)
-       {
-         first = false;
-         cost = get_computation_cost (data, next, cand, true,
-                                      NULL, &can_autoinc, NULL);
-         /* Remove setup cost.  */
-         if (!cost.infinite_cost_p ())
-           cost -= cost.scratch;
-       }
+      /* TODO: We could skip computing cost for sub iv_use when it has the
+        same cost as the first iv_use, but the cost really depends on the
+        offset and where the iv_use is.  */
+       cost = get_computation_cost (data, next, cand, true,
+                                    NULL, &can_autoinc, NULL);
       sum_cost += cost;
     }
   set_group_iv_cost (data, group, cand, sum_cost, depends_on,