This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] fix PR65048: check that jump-thread paths are still valid
- From: Sebastian Pop <sebpop at gmail dot com>
- To: gcc-patches at gcc dot gnu dot org, Jeff Law <law at redhat dot com>
- Date: Fri, 13 Feb 2015 23:50:33 +0000
- Subject: [patch] fix PR65048: check that jump-thread paths are still valid
- Authentication-results: sourceware.org; auth=none
Hi,
the attached patch fixes PR65048 by checking before jump-threading that a path
to be threaded is still valid: as the testcase shows, there may be paths that
are not connected anymore because the cfg has changed in a previous jump-thread.
PR tree-optimization/65048
* tree-ssa-threadupdate.c (valid_jump_thread_path): New.
(thread_through_all_blocks): Call valid_jump_thread_path.
Remove invalid FSM jump-thread paths.
* gcc.dg/tree-ssa/ssa-dom-thread-9.c: New.
The patch passed bootstrap and regression tests on x86_64-linux.
Ok for trunk?
Thanks,
Sebastian
>From 79b93a743649b898010cfea70769184bca28efb1 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <sebpop@gmail.com>
Date: Tue, 10 Feb 2015 22:36:50 +0100
Subject: [PATCH] check that paths are still valid to be threaded
PR tree-optimization/65048
* tree-ssa-threadupdate.c (valid_jump_thread_path): New.
(thread_through_all_blocks): Call valid_jump_thread_path.
Remove invalid FSM jump-thread paths.
* gcc.dg/tree-ssa/ssa-dom-thread-9.c: New.
---
gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-9.c | 49 ++++++++++++++++++++++
gcc/tree-ssa-threadupdate.c | 40 +++++++++++++++---
2 files changed, 83 insertions(+), 6 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-9.c
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-9.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-9.c
new file mode 100644
index 0000000..a843753
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-9.c
@@ -0,0 +1,49 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+int a, b, c, d;
+void fn (void);
+
+int
+foo (x)
+{
+ switch (x)
+ {
+ case 'A':
+ return 'T';
+ case 'U':
+ return 'A';
+ }
+}
+
+void
+bar (int x, int y)
+{
+ switch (c)
+ {
+ case 'U':
+ switch (x)
+ {
+ default:
+ fn ();
+ case 'G':
+ switch (y)
+ {
+ case 'A':
+ d = 7;
+ }
+ }
+ }
+}
+
+void
+baz (void)
+{
+ while (1)
+ {
+ a = foo ();
+ b = foo ();
+ bar (a, b);
+ }
+}
+
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 3326144..7a41ab2 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -2473,6 +2473,21 @@ duplicate_seme_region (edge entry, edge exit,
return true;
}
+/* Return true when PATH is a valid jump-thread path. */
+
+static bool
+valid_jump_thread_path (vec<jump_thread_edge *> *path)
+{
+ unsigned len = path->length ();
+
+ /* Check that the path is connected. */
+ for (unsigned int j = 0; j < len - 1; j++)
+ if ((*path)[j]->e->dest != (*path)[j+1]->e->src)
+ return false;
+
+ return true;
+}
+
/* Walk through all blocks and thread incoming edges to the appropriate
outgoing edge for each edge pair recorded in THREADED_EDGES.
@@ -2505,12 +2520,25 @@ thread_through_all_blocks (bool may_peel_loop_headers)
vec<jump_thread_edge *> *path = paths[i];
edge entry = (*path)[0]->e;
- if ((*path)[0]->type != EDGE_FSM_THREAD
- /* Do not jump-thread twice from the same block. */
- || bitmap_bit_p (threaded_blocks, entry->src->index)) {
- i++;
- continue;
- }
+ /* Only code-generate FSM jump-threads in this loop. */
+ if ((*path)[0]->type != EDGE_FSM_THREAD)
+ {
+ i++;
+ continue;
+ }
+
+ /* Do not jump-thread twice from the same block. */
+ if (bitmap_bit_p (threaded_blocks, entry->src->index)
+ /* Verify that the jump thread path is still valid: a
+ previous jump-thread may have changed the CFG, and
+ invalidated the current path. */
+ || !valid_jump_thread_path (path))
+ {
+ /* Remove invalid FSM jump-thread paths. */
+ delete_jump_thread_path (path);
+ paths.unordered_remove (i);
+ continue;
+ }
unsigned len = path->length ();
edge exit = (*path)[len - 1]->e;
--
1.7.2.5