summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2016-01-27 14:54:03 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2016-01-27 14:54:03 +0000
commitc88301adefa9a0db1b48ecae8996c3bfd0fe5527 (patch)
tree09ba81f79679354fa63f7baab396d5491db9948a
parent8ca4755082d1fca190e25d32592f9f5303a608aa (diff)
downloadgcc-c88301adefa9a0db1b48ecae8996c3bfd0fe5527.tar.gz
2016-01-27 Richard Biener <rguenther@suse.de>
PR tree-optimization/69166 * tree-vect-loop.c (vect_is_simple_reduction): Always check reduction code for commutativity / associativity. * gcc.dg/torture/pr69166.c: New testcase. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@232878 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr69166.c14
-rw-r--r--gcc/tree-vect-loop.c28
4 files changed, 39 insertions, 14 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 824c69c1859..9f8869b6f6d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2016-01-27 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/69166
+ * tree-vect-loop.c (vect_is_simple_reduction): Always check
+ reduction code for commutativity / associativity.
+
2016-01-27 Martin Jambor <mjambor@suse.cz>
PR tree-optimization/69355
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7dae86c1fe0..8c7f4ddb371 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-01-27 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/69166
+ * gcc.dg/torture/pr69166.c: New testcase.
+
2016-01-27 Martin Jambor <mjambor@suse.cz>
PR tree-optimization/69355
diff --git a/gcc/testsuite/gcc.dg/torture/pr69166.c b/gcc/testsuite/gcc.dg/torture/pr69166.c
new file mode 100644
index 00000000000..c10f8e65357
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr69166.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+
+void fn2(double *e, double a)
+{
+ int b = 0;
+ for (; b < 256; b++)
+ {
+ int c = 0;
+ double x = e[b];
+ for (; c < 256; ++c)
+ x /= a;
+ e[b] = x;
+ }
+}
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 60346725a44..b8303ad4139 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -2750,17 +2750,17 @@ vect_is_simple_reduction (loop_vec_info loop_info, gimple *phi,
&& SSA_NAME_DEF_STMT (op1) == phi)
code = PLUS_EXPR;
- if (check_reduction)
+ if (code == COND_EXPR)
{
- if (code == COND_EXPR)
+ if (check_reduction)
*v_reduc_type = COND_REDUCTION;
- else if (!commutative_tree_code (code) || !associative_tree_code (code))
- {
- if (dump_enabled_p ())
- report_vect_op (MSG_MISSED_OPTIMIZATION, def_stmt,
- "reduction: not commutative/associative: ");
- return NULL;
- }
+ }
+ else if (!commutative_tree_code (code) || !associative_tree_code (code))
+ {
+ if (dump_enabled_p ())
+ report_vect_op (MSG_MISSED_OPTIMIZATION, def_stmt,
+ "reduction: not commutative/associative: ");
+ return NULL;
}
if (get_gimple_rhs_class (code) != GIMPLE_BINARY_RHS)
@@ -2856,11 +2856,11 @@ vect_is_simple_reduction (loop_vec_info loop_info, gimple *phi,
and therefore vectorizing reductions in the inner-loop during
outer-loop vectorization is safe. */
- if (*v_reduc_type != COND_REDUCTION)
+ if (*v_reduc_type != COND_REDUCTION
+ && check_reduction)
{
/* CHECKME: check for !flag_finite_math_only too? */
- if (SCALAR_FLOAT_TYPE_P (type) && !flag_associative_math
- && check_reduction)
+ if (SCALAR_FLOAT_TYPE_P (type) && !flag_associative_math)
{
/* Changing the order of operations changes the semantics. */
if (dump_enabled_p ())
@@ -2868,7 +2868,7 @@ vect_is_simple_reduction (loop_vec_info loop_info, gimple *phi,
"reduction: unsafe fp math optimization: ");
return NULL;
}
- else if (INTEGRAL_TYPE_P (type) && check_reduction)
+ else if (INTEGRAL_TYPE_P (type))
{
if (!operation_no_trapping_overflow (type, code))
{
@@ -2891,7 +2891,7 @@ vect_is_simple_reduction (loop_vec_info loop_info, gimple *phi,
return NULL;
}
}
- else if (SAT_FIXED_POINT_TYPE_P (type) && check_reduction)
+ else if (SAT_FIXED_POINT_TYPE_P (type))
{
/* Changing the order of operations changes the semantics. */
if (dump_enabled_p ())