When the path ranger cannot find a relation from within the path, it invokes a relation query from the root ranger.

 It only does that however if all the equivalencies it found within the path are not in the killed_def vector.. meaning no DEf was seen on the path.  And when this is satisifed, it queries the root ranger with its current know equivlence sets.

There are 2 problems with this.

 1 - if any equivalence def is killed in the path, no query between the original ssa_names to the path entry will be made, meaning we can miss known relations coming into the path,

 2 - Because the call is made with the equivlence sets, no known equivlences outside the path will be utilized either.

This patch adds a check that if we find nothing, query the root ranger from the entry block of the path for the 2 specified SSA names.  This will then do a dom search of what the root ranger knows in the dom tree, including its equivlence sets.

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

Andrew
From f156f181501466fba35b3b9e83f80604fa4da2f0 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <[email protected]>
Date: Wed, 15 Jul 2026 15:43:14 -0400
Subject: [PATCH 1/3] Path ranger should check root ranger equivalencies as
 well.

Path ranger currently checks the root ranger for realtions between
only local equivalencies.   If that fails, it should also check the
root ranger for any equivalencies and relations between the two names
which occur earlier in the IL.

	PR tree-optimization/125986
	* value-relation.cc (path_oracle::query): Query root oracle for
	relations.
---
 gcc/value-relation.cc | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc
index 932bb070dad..3ad522ccf64 100644
--- a/gcc/value-relation.cc
+++ b/gcc/value-relation.cc
@@ -1710,6 +1710,7 @@ path_oracle::query (basic_block bb, const_bitmap b1, const_bitmap b2)
       || bitmap_intersect_p (m_killed_defs, b2))
     return k;
 
+  // Query the root oracle for relations with path local equivalencies.
   if (k == VREL_VARYING && m_root)
     k = m_root->query (bb, b1, b2);
 
@@ -1733,7 +1734,12 @@ path_oracle::query (basic_block bb, tree ssa1, tree ssa2)
   if (bitmap_bit_p (equiv_1, v2) && bitmap_bit_p (equiv_2, v1))
     return VREL_EQ;
 
-  return query (bb, equiv_1, equiv_2);
+  relation_kind rel = query (bb, equiv_1, equiv_2);
+
+  // If the path relation query fails, check for relations in the root oracle.
+  if (rel == VREL_VARYING && m_root)
+      rel = m_root->query (bb, ssa1, ssa2);
+  return rel;
 }
 
 // Reset any relations registered on this path.  ORACLE is the root
-- 
2.45.0

Reply via email to