From cca3c4f2e7075fe613ac1cd67a3e1743faf33505 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Wed, 13 Mar 2024 14:13:28 -0400
Subject: [PATCH 3/9] Invoke range_of_stmt on ssa_names with no context.
Evalaute ssa-names when range_of_expr is called with no context statement
by calling range_of_stmt to get an initial value.
* gimple-range.cc (gimple_ranger::range_of_expr): Call range_of_stmt
when there is no context stmt.
---
gcc/gimple-range.cc | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
@@ -102,7 +102,15 @@ gimple_ranger::range_of_expr (vrange &r, tree expr, gimple *stmt)
if (!stmt)
{
Value_Range tmp (TREE_TYPE (expr));
- m_cache.get_global_range (r, expr);
+ // If there is no global range for EXPR yet, try to evaluate it.
+ // This call sets R to a global range regardless.
+ if (!m_cache.get_global_range (r, expr))
+ {
+ gimple *s = SSA_NAME_DEF_STMT (expr);
+ // Calculate a range for S if it is safe to do so.
+ if (s && gimple_bb (s) && gimple_get_lhs (s) == expr)
+ return range_of_stmt (r, s);
+ }
// Pick up implied context information from the on-entry cache
// if current_bb is set. Do not attempt any new calculations.
if (current_bb && m_cache.block_range (tmp, current_bb, expr, false))
--
2.41.0