When an inferred range is added, there was no mechanism in place to indicate that this was a new value and may cause other values to be stale.

With this patch, update_range_info() is called for the current range_query to indicate that the name having the inferred range added for is now stale.

IN addition, if the name is a default def, it also has a timestamp created for it.  Otherwise it would be considered always current as it is never calculated.  This timestamp will give it a current time and thus properly enable tracking of out-of-dateness.

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

Andrew
From c64d5ff19f34369717428dfea4377197a47fe414 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <[email protected]>
Date: Tue, 14 Jul 2026 14:55:44 -0400
Subject: [PATCH 1/2] Update ranger timestamps for inferred ranges.

If an inferred range is added for a name, mark the name as an updated
range to allow the dependency processing to pick up the change.

	PR tree-optimization/126110
	gcc/
	* gimple-range-cache.cc (ranger_cache::mark_stale): Default defs
	get a new timestamp to make them stale.
	* gimple-range-infer.cc (infer_range_manager::add_range): When
	an inferred range is added, mark the name as updated.

	gcc/testsuite/
	* gcc.dg/pr126110.c: New.
---
 gcc/gimple-range-cache.cc       | 15 +++++++++----
 gcc/gimple-range-infer.cc       |  2 ++
 gcc/testsuite/gcc.dg/pr126110.c | 38 +++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr126110.c

diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc
index fc5793ccf69..c5a19c866fb 100644
--- a/gcc/gimple-range-cache.cc
+++ b/gcc/gimple-range-cache.cc
@@ -1116,10 +1116,17 @@ ranger_cache::get_global_range (vrange &r, tree name) const
 void
 ranger_cache::mark_stale (tree name)
 {
-  // Only mark it as stale if it has been processed. If it has no range
-  // it will be calculated at the next request anyway.
-  if (m_globals.has_range (name))
-    bitmap_set_bit (m_stale, SSA_NAME_VERSION (name));
+  if (SSA_NAME_IS_DEFAULT_DEF (name))
+    {
+      // Default defs have no DEF to recalculate, just create a new timestamp.
+      m_temporal->set_timestamp_stored (name);
+    }
+  else if (m_globals.has_range (name))
+    {
+      // Otherwise Only mark it as stale if it has been processed. If it has no
+      // range it will be calculated at the next request anyway.
+      bitmap_set_bit (m_stale, SSA_NAME_VERSION (name));
+    }
 }
 
 // Get the global range for NAME, and return in R.  Return false if the
diff --git a/gcc/gimple-range-infer.cc b/gcc/gimple-range-infer.cc
index 30b5917e4ed..ecd197cf859 100644
--- a/gcc/gimple-range-infer.cc
+++ b/gcc/gimple-range-infer.cc
@@ -457,6 +457,8 @@ infer_range_manager::add_range (tree name, gimple *s, const vrange &r)
      fprintf (dump_file, "\n");
    }
 
+  get_range_query (cfun)->update_range_info (name);
+
   // If NAME already has a range, intersect them and done.
   exit_range *ptr = m_on_exit[bb->index].find_ptr (name);
   if (ptr)
diff --git a/gcc/testsuite/gcc.dg/pr126110.c b/gcc/testsuite/gcc.dg/pr126110.c
new file mode 100644
index 00000000000..278e53d0235
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr126110.c
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-evrp" } */
+
+struct rtx {
+  int code;
+};
+
+static inline void *zero ()
+{
+  return 0;
+}
+static inline int three ()
+{
+  return 3;
+}
+
+int
+can_combine_p (struct rtx *insn, struct rtx *elt)
+{
+  struct rtx *set;
+
+  set = zero ();
+  if (insn->code == three ())
+    set = insn;
+  else
+    {
+      set = elt;
+      if (set == zero ())
+        return 0;
+    }
+
+  return (set == zero ());
+
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump "Global Exported: set_.*1," "evrp" } } */
+
-- 
2.45.0

Reply via email to