aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-range-path.cc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2022-08-10 12:54:05 +0200
committerRichard Biener <rguenther@suse.de>2022-08-11 08:51:45 +0200
commit757fd34803b7ae0eb3705315060e5fbba1148c5c (patch)
tree7da42d7a63689585d8450a18b9eba425781d1228 /gcc/gimple-range-path.cc
parentb22086c261f20a7576f233db3537ccf192e7160c (diff)
downloadgcc-757fd34803b7ae0eb3705315060e5fbba1148c5c.zip
gcc-757fd34803b7ae0eb3705315060e5fbba1148c5c.tar.gz
gcc-757fd34803b7ae0eb3705315060e5fbba1148c5c.tar.bz2
Fix path query compute_imports for external path
The following fixes the use of compute_imports from the backwards threader which ends up accessing stale m_path from a previous threading attempt. The fix is to pass in the path explicitely (and not the exit), and initializing it with the exit around this call from the backwards threader. That unfortunately exposed that we rely on this broken behavior as the new testcase shows. The missed threading can be restored by registering all relations from conditions on the path during solving, for the testcase the particular important case is for relations provided by the path entry conditional. I've verified that the GORI query for imported ranges on edges is not restricted this way. This regresses the new ssa-thread-19.c testcase which is exactly a case for the other patch re-doing how we compute imports since this misses imports for defs that are not on the dominating path from the exit. That's one of the cases this regresses (it also progresses a few due to more or the correct relations added). Overall it reduces the number of threads from 98649 to 98620 on my set of cc1files. I think it's a reasonable intermediate step to find a stable, less random ground to compare stats to. * gimple-range-path.h (path_range_query::compute_imports): Take path as argument, not the exit block. * gimple-range-path.cc (path_range_query::compute_imports): Likewise, and adjust, avoiding possibly stale m_path. (path_range_query::compute_outgoing_relations): Register relations for all conditionals. * tree-ssa-threadbackward.cc (back_threader::find_paths): Adjust. * gcc.dg/tree-ssa/ssa-thread-18.c: New testcase. * gcc.dg/tree-ssa/ssa-thread-19.c: Likewise, but XFAILed.
Diffstat (limited to 'gcc/gimple-range-path.cc')
-rw-r--r--gcc/gimple-range-path.cc21
1 files changed, 8 insertions, 13 deletions
diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc
index 43e7526..389faec 100644
--- a/gcc/gimple-range-path.cc
+++ b/gcc/gimple-range-path.cc
@@ -549,7 +549,7 @@ path_range_query::add_to_imports (tree name, bitmap imports)
return false;
}
-// Compute the imports to the path ending in EXIT. These are
+// Compute the imports to PATH. These are
// essentially the SSA names used to calculate the final conditional
// along the path.
//
@@ -559,9 +559,10 @@ path_range_query::add_to_imports (tree name, bitmap imports)
// we can solve.
void
-path_range_query::compute_imports (bitmap imports, basic_block exit)
+path_range_query::compute_imports (bitmap imports, const vec<basic_block> &path)
{
// Start with the imports from the exit block...
+ basic_block exit = path[0];
gori_compute &gori = m_ranger->gori ();
bitmap r_imports = gori.imports (exit);
bitmap_copy (imports, r_imports);
@@ -599,7 +600,7 @@ path_range_query::compute_imports (bitmap imports, basic_block exit)
tree arg = gimple_phi_arg (phi, i)->def;
if (TREE_CODE (arg) == SSA_NAME
- && m_path.contains (e->src)
+ && path.contains (e->src)
&& bitmap_set_bit (imports, SSA_NAME_VERSION (arg)))
worklist.safe_push (arg);
}
@@ -607,9 +608,9 @@ path_range_query::compute_imports (bitmap imports, basic_block exit)
}
// Exported booleans along the path, may help conditionals.
if (m_resolve)
- for (i = 0; i < m_path.length (); ++i)
+ for (i = 0; i < path.length (); ++i)
{
- basic_block bb = m_path[i];
+ basic_block bb = path[i];
tree name;
FOR_EACH_GORI_EXPORT_NAME (gori, bb, name)
if (TREE_CODE (TREE_TYPE (name)) == BOOLEAN_TYPE)
@@ -636,7 +637,7 @@ path_range_query::compute_ranges (const vec<basic_block> &path,
if (imports)
bitmap_copy (m_imports, imports);
else
- compute_imports (m_imports, exit_bb ());
+ compute_imports (m_imports, m_path);
if (m_resolve)
get_path_oracle ()->reset_path ();
@@ -845,15 +846,9 @@ path_range_query::compute_phi_relations (basic_block bb, basic_block prev)
void
path_range_query::compute_outgoing_relations (basic_block bb, basic_block next)
{
- gimple *stmt = last_stmt (bb);
-
- if (stmt
- && gimple_code (stmt) == GIMPLE_COND
- && (import_p (gimple_cond_lhs (stmt))
- || import_p (gimple_cond_rhs (stmt))))
+ if (gcond *cond = safe_dyn_cast <gcond *> (last_stmt (bb)))
{
int_range<2> r;
- gcond *cond = as_a<gcond *> (stmt);
edge e0 = EDGE_SUCC (bb, 0);
edge e1 = EDGE_SUCC (bb, 1);