diff mbox series

[COMMITTED,3/5] Invoke range_of_stmt on ssa_names with no context.

Message ID 7e388f53-180d-49bd-912f-6f06f52d46e0@redhat.com
State New
Headers show
Series [COMMITTED,1/5] Remove wrapper around gimple_range_global. | expand

Commit Message

Andrew MacLeod April 30, 2024, 9:24 p.m. UTC
If range_of_expr is called on an ssa-name with no context, ranger just 
grabs whatever the global value is.

It was pointed out we can do better than this.  If the name is in the 
IL, there is no reason for ranger to not try to fold the statement and 
see if we get a better result for it.   It removes an unnecessary 
penalty when there is no statement given for context.

This requires a tiny bit more work, sometimes for no benefit. However, 
the slowdown is also marginal.

Bootstrapped on x86_64-pc-linux-gnu with no regressions.  pushed.

Andrew
diff mbox series

Patch

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(-)

diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index 4d3b1ce8588..3966cfbd14c 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -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