aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-range.cc
diff options
context:
space:
mode:
authorAndrew MacLeod <amacleod@redhat.com>2020-11-04 12:59:15 -0500
committerAndrew MacLeod <amacleod@redhat.com>2020-11-04 13:07:53 -0500
commite86fd6a17cdb26710d1f13c9a47a3878c76028f9 (patch)
tree28e836b34524e1129f1ceb70527d301c8483fe53 /gcc/gimple-range.cc
parent9c1125c121423a9948fa39e71ef89ba4059a2fad (diff)
downloadgcc-e86fd6a17cdb26710d1f13c9a47a3878c76028f9.zip
gcc-e86fd6a17cdb26710d1f13c9a47a3878c76028f9.tar.gz
gcc-e86fd6a17cdb26710d1f13c9a47a3878c76028f9.tar.bz2
Add Ranger temporal cache
Add a timestamp to supplement the global range cache to detect when a value may become stale. gcc/ PR tree-optimization/97515 * gimple-range-cache.h (class ranger_cache): New prototypes plus temporal cache pointer. * gimple-range-cache.cc (struct range_timestamp): New. (class temporal_cache): New. (temporal_cache::temporal_cache): New. (temporal_cache::~temporal_cache): New. (temporal_cache::get_timestamp): New. (temporal_cache::set_dependency): New. (temporal_cache::temporal_value): New. (temporal_cache::current_p): New. (temporal_cache::set_timestamp): New. (temporal_cache::set_always_current): New. (ranger_cache::ranger_cache): Allocate the temporal cache. (ranger_cache::~ranger_cache): Free temporal cache. (ranger_cache::get_non_stale_global_range): New. (ranger_cache::set_global_range): Add a timestamp. (ranger_cache::register_dependency): New. Add timestamp dependency. * gimple-range.cc (gimple_ranger::range_of_range_op): Add operand dependencies. (gimple_ranger::range_of_phi): Ditto. (gimple_ranger::range_of_stmt): Check if global range is stale, and recalculate if so. gcc/testsuite/ * gcc.dg/pr97515.c: Check listing for folding of entire function.
Diffstat (limited to 'gcc/gimple-range.cc')
-rw-r--r--gcc/gimple-range.cc23
1 files changed, 14 insertions, 9 deletions
diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 8fdcc31..ef65e00 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -415,12 +415,20 @@ bool
gimple_ranger::range_of_range_op (irange &r, gimple *s)
{
int_range_max range1, range2;
+ tree lhs = gimple_get_lhs (s);
tree type = gimple_expr_type (s);
gcc_checking_assert (irange::supports_type_p (type));
tree op1 = gimple_range_operand1 (s);
tree op2 = gimple_range_operand2 (s);
+ if (lhs)
+ {
+ // Register potential dependencies for stale value tracking.
+ m_cache.register_dependency (lhs, op1);
+ m_cache.register_dependency (lhs, op2);
+ }
+
if (range_of_non_trivial_assignment (r, s))
return true;
@@ -501,6 +509,9 @@ gimple_ranger::range_of_phi (irange &r, gphi *phi)
tree arg = gimple_phi_arg_def (phi, x);
edge e = gimple_phi_arg_edge (phi, x);
+ // Register potential dependencies for stale value tracking.
+ m_cache.register_dependency (phi_def, arg);
+
range_on_edge (arg_range, e, arg);
r.union_ (arg_range);
// Once the value reaches varying, stop looking.
@@ -1009,18 +1020,12 @@ gimple_ranger::range_of_stmt (irange &r, gimple *s, tree name)
if (!gimple_range_ssa_p (name))
return false;
- // If this STMT has already been processed, return that value.
- if (m_cache.get_global_range (r, name))
+ // Check if the stmt has already been processed, and is not stale.
+ if (m_cache.get_non_stale_global_range (r, name))
return true;
- // Avoid infinite recursion by initializing global cache
- int_range_max tmp = gimple_range_global (name);
- m_cache.set_global_range (name, tmp);
-
+ // Otherwise calculate a new value and save it.
calc_stmt (r, s, name);
-
- if (is_a<gphi *> (s))
- r.intersect (tmp);
m_cache.set_global_range (name, r);
return true;
}