]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Only update global value if it changes.
authorAndrew MacLeod <amacleod@redhat.com>
Tue, 23 May 2023 19:41:03 +0000 (15:41 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Wed, 24 May 2023 12:39:58 +0000 (08:39 -0400)
Do not update and propagate a global value if it hasn't changed.

PR tree-optimization/109695
* gimple-range-cache.cc (ranger_cache::get_global_range): Add
changed param.
* gimple-range-cache.h (ranger_cache::get_global_range): Ditto.
* gimple-range.cc (gimple_ranger::range_of_stmt): Pass changed
flag to set_global_range.
(gimple_ranger::prefill_stmt_dependencies): Ditto.

gcc/gimple-range-cache.cc
gcc/gimple-range-cache.h
gcc/gimple-range.cc

index db7ee8eab4e953b496d606343cd5b72097287169..e069241bc9d9e2fe4ff8fa290d31e75e6ce72fd6 100644 (file)
@@ -992,10 +992,18 @@ ranger_cache::get_global_range (vrange &r, tree name, bool &current_p)
 //  Set the global range of NAME to R and give it a timestamp.
 
 void
-ranger_cache::set_global_range (tree name, const vrange &r)
+ranger_cache::set_global_range (tree name, const vrange &r, bool changed)
 {
   // Setting a range always clears the always_current flag.
   m_temporal->set_always_current (name, false);
+  if (!changed)
+    {
+      // If there are dependencies, make sure this is not out of date.
+      if (!m_temporal->current_p (name, m_gori.depend1 (name),
+                                m_gori.depend2 (name)))
+       m_temporal->set_timestamp (name);
+      return;
+    }
   if (m_globals.set_range (name, r))
     {
       // If there was already a range set, propagate the new value.
index 946fbc514650ad71dfd0af59f288914ea1cfc124..871255a8116861c6f66df806293e41d04b747df8 100644 (file)
@@ -117,7 +117,7 @@ public:
 
   bool get_global_range (vrange &r, tree name) const;
   bool get_global_range (vrange &r, tree name, bool &current_p);
-  void set_global_range (tree name, const vrange &r);
+  void set_global_range (tree name, const vrange &r, bool changed = true);
 
   void propagate_updated_value (tree name, basic_block bb);
 
index a275c090e4bdfc3efc105597c5a0fa60400f2268..4fae3f95e6abd0ee9eb7add9866a0eab96466ee8 100644 (file)
@@ -320,8 +320,8 @@ gimple_ranger::range_of_stmt (vrange &r, gimple *s, tree name)
       // Combine the new value with the old value.  This is required because
       // the way value propagation works, when the IL changes on the fly we
       // can sometimes get different results.  See PR 97741.
-      r.intersect (tmp);
-      m_cache.set_global_range (name, r);
+      bool changed = r.intersect (tmp);
+      m_cache.set_global_range (name, r, changed);
       res = true;
     }
 
@@ -393,8 +393,8 @@ gimple_ranger::prefill_stmt_dependencies (tree ssa)
              // Make sure we don't lose any current global info.
              Value_Range tmp (TREE_TYPE (name));
              m_cache.get_global_range (tmp, name);
-             r.intersect (tmp);
-             m_cache.set_global_range (name, r);
+             bool changed = tmp.intersect (r);
+             m_cache.set_global_range (name, tmp, changed);
            }
          continue;
        }