aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew MacLeod <amacleod@redhat.com>2024-03-13 14:10:41 -0400
committerAndrew MacLeod <amacleod@redhat.com>2024-04-30 17:19:57 -0400
commite8ae56a7dc46e39a48017bb5159e4dc672ec7fad (patch)
treee759ec98ea732f7c3dc1e429732382c5c5fdb030
parent56aa8ad7cd91fbc42123f1190d3238e293020085 (diff)
Fix ranger when called from SCEV.
Do not pre-evaluate PHIs in the cache, and allow fill_block_cache to be re-entrant. This allows SCEV to call into ranger with a context and not produce cycles or loops. * gimple-range-cache.cc (ranger_cache::get_global_range): Do not pre-evaluate PHI nodes from the cache. (ranger_cache::fill_block_cache): Make re-entrant.
-rw-r--r--gcc/gimple-range-cache.cc10
1 files changed, 6 insertions, 4 deletions
diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index a33b7a73872..72ac2552311 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -1047,7 +1047,9 @@ ranger_cache::get_global_range (vrange &r, tree name, bool &current_p)
if (r.varying_p () && !cfun->after_inlining)
{
gimple *s = SSA_NAME_DEF_STMT (name);
- if (gimple_get_lhs (s) == name)
+ // Do not process PHIs as SCEV may be in use and it can
+ // spawn cyclic lookups.
+ if (gimple_get_lhs (s) == name && !is_a<gphi *> (s))
{
if (!fold_range (r, s, get_global_range_query ()))
gimple_range_global (r, name);
@@ -1413,7 +1415,7 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb)
// At this point we shouldn't be looking at the def, entry block.
gcc_checking_assert (bb != def_bb && bb != ENTRY_BLOCK_PTR_FOR_FN (cfun));
- gcc_checking_assert (m_workback.length () == 0);
+ unsigned start_length = m_workback.length ();
// If the block cache is set, then we've already visited this block.
if (m_on_entry.bb_range_p (name, bb))
@@ -1500,7 +1502,7 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb)
}
m_on_entry.set_bb_range (name, bb, block_result);
- gcc_checking_assert (m_workback.length () == 0);
+ gcc_checking_assert (m_workback.length () == start_length);
return;
}
@@ -1512,7 +1514,7 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb)
m_on_entry.set_bb_range (name, bb, undefined);
gcc_checking_assert (m_update->empty_p ());
- while (m_workback.length () > 0)
+ while (m_workback.length () > start_length)
{
basic_block node = m_workback.pop ();
if (DEBUG_RANGE_CACHE)