aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2018-02-27 15:25:33 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2018-02-27 15:25:33 +0000
commitb1ddb654aba3859e025565c0af35d1a704c8e5d0 (patch)
treecf62b5231022071ef9708e731b1392bba45cd82d
parentc16d3e3c875cb00ff8cffbdf1aa58ab0932e767d (diff)
downloadgcc-b1ddb654aba3859e025565c0af35d1a704c8e5d0.zip
gcc-b1ddb654aba3859e025565c0af35d1a704c8e5d0.tar.gz
gcc-b1ddb654aba3859e025565c0af35d1a704c8e5d0.tar.bz2
re PR tree-optimization/84512 (Missed optimization: should be precalculated in compile-time)
2018-02-27 Richard Biener <rguenther@suse.de> PR tree-optimization/84512 * tree-vect-loop.c (vect_compute_single_scalar_iteration_cost): Do not use the estimate returned from record_stmt_cost for the scalar iteration cost but sum properly using add_stmt_cost. * gcc.dg/tree-ssa/pr84512.c: New testcase. From-SVN: r258036
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr84512.c15
-rw-r--r--gcc/tree-vect-loop.c35
4 files changed, 49 insertions, 13 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d4e56b3..d56af0f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
2018-02-27 Richard Biener <rguenther@suse.de>
+ PR tree-optimization/84512
+ * tree-vect-loop.c (vect_compute_single_scalar_iteration_cost):
+ Do not use the estimate returned from record_stmt_cost for
+ the scalar iteration cost but sum properly using add_stmt_cost.
+
+2018-02-27 Richard Biener <rguenther@suse.de>
+
PR tree-optimization/84466
* graphite-scop-detection.c (scop_detection::stmt_simple_for_scop_p):
Adjust last change to less strictly validate use operands.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 6506d8f..5431093 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2018-02-27 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/84512
+ * gcc.dg/tree-ssa/pr84512.c: New testcase.
+
2018-02-27 Martin Liska <mliska@suse.cz>
PR gcov-profile/84548
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr84512.c b/gcc/testsuite/gcc.dg/tree-ssa/pr84512.c
new file mode 100644
index 0000000..288fa5d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr84512.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-tree-optimized" } */
+
+int foo()
+{
+ int a[10];
+ for(int i = 0; i < 10; ++i)
+ a[i] = i*i;
+ int res = 0;
+ for(int i = 0; i < 10; ++i)
+ res += a[i];
+ return res;
+}
+
+/* { dg-final { scan-tree-dump "return 285;" "optimized" } } */
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 3a51147..6585c85 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -1384,16 +1384,10 @@ vect_compute_single_scalar_iteration_cost (loop_vec_info loop_vinfo)
{
struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
basic_block *bbs = LOOP_VINFO_BBS (loop_vinfo);
- int nbbs = loop->num_nodes, factor, scalar_single_iter_cost = 0;
+ int nbbs = loop->num_nodes, factor;
int innerloop_iters, i;
- /* Count statements in scalar loop. Using this as scalar cost for a single
- iteration for now.
-
- TODO: Add outer loop support.
-
- TODO: Consider assigning different costs to different scalar
- statements. */
+ /* Gather costs for statements in the scalar loop. */
/* FORNOW. */
innerloop_iters = 1;
@@ -1437,13 +1431,28 @@ vect_compute_single_scalar_iteration_cost (loop_vec_info loop_vinfo)
else
kind = scalar_stmt;
- scalar_single_iter_cost
- += record_stmt_cost (&LOOP_VINFO_SCALAR_ITERATION_COST (loop_vinfo),
- factor, kind, stmt_info, 0, vect_prologue);
+ record_stmt_cost (&LOOP_VINFO_SCALAR_ITERATION_COST (loop_vinfo),
+ factor, kind, stmt_info, 0, vect_prologue);
}
}
- LOOP_VINFO_SINGLE_SCALAR_ITERATION_COST (loop_vinfo)
- = scalar_single_iter_cost;
+
+ /* Now accumulate cost. */
+ void *target_cost_data = init_cost (loop);
+ stmt_info_for_cost *si;
+ int j;
+ FOR_EACH_VEC_ELT (LOOP_VINFO_SCALAR_ITERATION_COST (loop_vinfo),
+ j, si)
+ {
+ struct _stmt_vec_info *stmt_info
+ = si->stmt ? vinfo_for_stmt (si->stmt) : NULL;
+ (void) add_stmt_cost (target_cost_data, si->count,
+ si->kind, stmt_info, si->misalign,
+ vect_body);
+ }
+ unsigned dummy, body_cost = 0;
+ finish_cost (target_cost_data, &dummy, &body_cost, &dummy);
+ destroy_cost_data (target_cost_data);
+ LOOP_VINFO_SINGLE_SCALAR_ITERATION_COST (loop_vinfo) = body_cost;
}