aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2018-11-13 13:51:34 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2018-11-13 13:51:34 +0000
commitbe2b68e4cd63e50f4dd5fca247b9a919fb0013a0 (patch)
tree4195b8bd3d01d316a9a6390f21fb723aa650477f /gcc
parenta28dfaafc5afd06419408048b664a843b2739086 (diff)
downloadgcc-be2b68e4cd63e50f4dd5fca247b9a919fb0013a0.zip
gcc-be2b68e4cd63e50f4dd5fca247b9a919fb0013a0.tar.gz
gcc-be2b68e4cd63e50f4dd5fca247b9a919fb0013a0.tar.bz2
re PR tree-optimization/87962 (ICE in vect_get_vec_def_for_operand_1, at tree-vect-stmts.c:1485)
2018-11-13 Richard Biener <rguenther@suse.de> PR tree-optimization/87962 * tree-vect-loop.c (vect_is_simple_reduction): More reliably detect outer reduction for disqualifying in-loop uses. * gcc.dg/pr87962.c: New testcase. From-SVN: r266071
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr87962.c17
-rw-r--r--gcc/tree-vect-loop.c39
4 files changed, 44 insertions, 23 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 19ccd9c..95ea4cd 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,11 @@
2018-11-13 Richard Biener <rguenther@suse.de>
+ PR tree-optimization/87962
+ * tree-vect-loop.c (vect_is_simple_reduction): More reliably
+ detect outer reduction for disqualifying in-loop uses.
+
+2018-11-13 Richard Biener <rguenther@suse.de>
+
PR tree-optimization/87967
* tree-vect-loop.c (vect_transform_loop): Also copy PHIs
for constants for the scalar loop.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 41ffd8b..bc45308 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2018-11-13 Richard Biener <rguenther@suse.de>
+ PR tree-optimization/87962
+ * gcc.dg/pr87962.c: New testcase.
+
+2018-11-13 Richard Biener <rguenther@suse.de>
+
PR tree-optimization/87967
* g++.dg/opt/pr87967.C: New testcase.
diff --git a/gcc/testsuite/gcc.dg/pr87962.c b/gcc/testsuite/gcc.dg/pr87962.c
new file mode 100644
index 0000000..6a551d3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr87962.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+/* { dg-additional-options "-march=bdver2" { target { x86_64-*-* i?86-*-* } } } */
+
+int a, b;
+
+int c()
+{
+ long d, e;
+ while (a) {
+ a++;
+ b = 0;
+ for (; b++ - 2; d = d >> 1)
+ e += d;
+ }
+ return e;
+}
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index c4886ec..a6f0b82 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -2807,11 +2807,11 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info,
gphi *phi = as_a <gphi *> (phi_info->stmt);
struct loop *loop = (gimple_bb (phi))->loop_father;
struct loop *vect_loop = LOOP_VINFO_LOOP (loop_info);
+ bool nested_in_vect_loop = flow_loop_nested_p (vect_loop, loop);
gimple *phi_use_stmt = NULL;
enum tree_code orig_code, code;
tree op1, op2, op3 = NULL_TREE, op4 = NULL_TREE;
tree type;
- int nloop_uses;
tree name;
imm_use_iterator imm_iter;
use_operand_p use_p;
@@ -2827,7 +2827,7 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info,
can be constant. See PR60382. */
if (has_zero_uses (phi_name))
return NULL;
- nloop_uses = 0;
+ unsigned nphi_def_loop_uses = 0;
FOR_EACH_IMM_USE_FAST (use_p, imm_iter, phi_name)
{
gimple *use_stmt = USE_STMT (use_p);
@@ -2843,20 +2843,7 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info,
return NULL;
}
- /* For inner loop reductions in nested vectorization there are no
- constraints on the number of uses in the inner loop. */
- if (loop == vect_loop->inner)
- continue;
-
- nloop_uses++;
- if (nloop_uses > 1)
- {
- if (dump_enabled_p ())
- dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
- "reduction value used in loop.\n");
- return NULL;
- }
-
+ nphi_def_loop_uses++;
phi_use_stmt = use_stmt;
}
@@ -2894,26 +2881,32 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info,
return NULL;
}
- nloop_uses = 0;
+ unsigned nlatch_def_loop_uses = 0;
auto_vec<gphi *, 3> lcphis;
+ bool inner_loop_of_double_reduc = false;
FOR_EACH_IMM_USE_FAST (use_p, imm_iter, name)
{
gimple *use_stmt = USE_STMT (use_p);
if (is_gimple_debug (use_stmt))
continue;
if (flow_bb_inside_loop_p (loop, gimple_bb (use_stmt)))
- nloop_uses++;
+ nlatch_def_loop_uses++;
else
- /* We can have more than one loop-closed PHI. */
- lcphis.safe_push (as_a <gphi *> (use_stmt));
+ {
+ /* We can have more than one loop-closed PHI. */
+ lcphis.safe_push (as_a <gphi *> (use_stmt));
+ if (nested_in_vect_loop
+ && (STMT_VINFO_DEF_TYPE (loop_info->lookup_stmt (use_stmt))
+ == vect_double_reduction_def))
+ inner_loop_of_double_reduc = true;
+ }
}
/* If this isn't a nested cycle or if the nested cycle reduction value
is used ouside of the inner loop we cannot handle uses of the reduction
value. */
- bool nested_in_vect_loop = flow_loop_nested_p (vect_loop, loop);
- if ((!nested_in_vect_loop || !lcphis.is_empty ())
- && nloop_uses > 1)
+ if ((!nested_in_vect_loop || inner_loop_of_double_reduc)
+ && (nlatch_def_loop_uses > 1 || nphi_def_loop_uses > 1))
{
if (dump_enabled_p ())
dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,