aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2020-11-16 09:28:03 +0100
committerRichard Biener <rguenther@suse.de>2020-11-16 11:14:44 +0100
commitd0a206abc6cbf0e992bf82bbb3584686eae05d34 (patch)
treede0135c3962f0de52c88f749031274a5e4fae456 /gcc
parent5e303cdee1ff01e4b302ef2f913c0bdd84ab967e (diff)
downloadgcc-d0a206abc6cbf0e992bf82bbb3584686eae05d34.zip
gcc-d0a206abc6cbf0e992bf82bbb3584686eae05d34.tar.gz
gcc-d0a206abc6cbf0e992bf82bbb3584686eae05d34.tar.bz2
tree-optimization/97838 - fix SLP leaf detection
This properly handles reduction PHI nodes with unrepresented initial value as leaf in the SLP graph. 2020-11-16 Richard Biener <rguenther@suse.de> PR tree-optimization/97838 * tree-vect-slp.c (vect_slp_build_vertices): Properly handle not backwards reachable cycles. (vect_optimize_slp): Check a node is leaf before marking it visited. * gcc.dg/vect/pr97838.c: New testcase.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.dg/vect/pr97838.c11
-rw-r--r--gcc/tree-vect-slp.c22
2 files changed, 28 insertions, 5 deletions
diff --git a/gcc/testsuite/gcc.dg/vect/pr97838.c b/gcc/testsuite/gcc.dg/vect/pr97838.c
new file mode 100644
index 0000000..06ec035
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr97838.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+
+int a, b, c, d;
+
+void f() {
+ while (c++) {
+ int e = -1;
+ d = a ? e / a : e;
+ b ^= ~d;
+ }
+}
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index e4c2aa4..b98d5db 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -2629,8 +2629,18 @@ vect_slp_build_vertices (vec_info *info, vec<slp_tree> &vertices,
unsigned i;
slp_instance instance;
FOR_EACH_VEC_ELT (info->slp_instances, i, instance)
- vect_slp_build_vertices (visited, SLP_INSTANCE_TREE (instance), vertices,
- leafs);
+ {
+ unsigned n_v = vertices.length ();
+ unsigned n_l = leafs.length ();
+ vect_slp_build_vertices (visited, SLP_INSTANCE_TREE (instance), vertices,
+ leafs);
+ /* If we added vertices but no entries to the reverse graph we've
+ added a cycle that is not backwards-reachable. Push the entry
+ to mimic as leaf then. */
+ if (vertices.length () > n_v
+ && leafs.length () == n_l)
+ leafs.safe_push (SLP_INSTANCE_TREE (instance)->vertex);
+ }
}
/* Apply (reverse) bijectite PERM to VEC. */
@@ -2724,9 +2734,11 @@ vect_optimize_slp (vec_info *vinfo)
|| SLP_TREE_DEF_TYPE (node) == vect_constant_def)
continue;
- /* Loads are the only thing generating permutes and leafs do not
- change across iterations. */
- bitmap_set_bit (n_visited, idx);
+ /* Leafs do not change across iterations. Note leafs also double
+ as entries to the reverse graph. */
+ if (!slpg->vertices[idx].succ)
+ bitmap_set_bit (n_visited, idx);
+ /* Loads are the only thing generating permutes. */
if (!SLP_TREE_LOAD_PERMUTATION (node).exists ())
continue;