Transitive relations can add  processing time to the relation oracle as they need to look up previous relations. This  that may not be desired, especially for something like fast VRP.   This patch adds a flag at oracle creation time which makes processing them optional.

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

Andrew
From d3088bf565afcad410ce4fd3ebf6c993f63703b6 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacl...@redhat.com>
Date: Mon, 24 Jun 2024 10:29:06 -0400
Subject: [PATCH 1/2] Make transitive relations an oracle option

This patch makes processing of transitive relations configurable at
dom_oracle creation.

	* tree-vrp.cc (execute_fast_vrp): Do not use transitive relations.
	* value-query.cc (range_query::create_relation_oracle): Add
	parameter to enable transitive relations.
	* value-query.h (range_query::create_relation_oracle): Likewise.
	* value-relation.h (dom_oracle::dom_oracle): Likewise.
	* value-relation.cc (dom_oracle::dom_oracle): Likewise.
	(dom_oracle::register_transitives): Check transitive flag.
---
 gcc/tree-vrp.cc       | 3 ++-
 gcc/value-query.cc    | 7 ++++---
 gcc/value-query.h     | 2 +-
 gcc/value-relation.cc | 6 +++++-
 gcc/value-relation.h  | 3 ++-
 5 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc
index 4fc33e63e7d..26979b706e5 100644
--- a/gcc/tree-vrp.cc
+++ b/gcc/tree-vrp.cc
@@ -1258,7 +1258,8 @@ execute_fast_vrp (struct function *fun, bool final_p)
 
   gcc_checking_assert (!fun->x_range_query);
   fun->x_range_query = &dr;
-  get_range_query (fun)->create_relation_oracle ();
+  // Create a relation oracle without transitives.
+  get_range_query (fun)->create_relation_oracle (false);
 
   folder.substitute_and_fold ();
   if (folder.m_unreachable)
diff --git a/gcc/value-query.cc b/gcc/value-query.cc
index 0a280be580b..cac2cb5b2bc 100644
--- a/gcc/value-query.cc
+++ b/gcc/value-query.cc
@@ -223,17 +223,18 @@ range_query::destroy_infer_oracle ()
 }
 
 // Create dominance based range oracle for the current query if dom info is
-// available.
+// available.  DO_TRANS_P indicates whether transitive relations should
+// be created.  This can cost more in compile time.
 
 void
-range_query::create_relation_oracle ()
+range_query::create_relation_oracle (bool do_trans_p)
 {
   gcc_checking_assert (this != &global_ranges);
   gcc_checking_assert (m_relation == &default_relation_oracle);
 
   if (!dom_info_available_p (CDI_DOMINATORS))
     return;
-  m_relation = new dom_oracle ();
+  m_relation = new dom_oracle (do_trans_p);
   gcc_checking_assert (m_relation);
 }
 
diff --git a/gcc/value-query.h b/gcc/value-query.h
index 2572a03095d..78840fd7a78 100644
--- a/gcc/value-query.h
+++ b/gcc/value-query.h
@@ -76,7 +76,7 @@ public:
   virtual bool range_on_exit (vrange &r, basic_block bb, tree expr);
 
   inline class relation_oracle &relation () const  { return *m_relation; }
-  void create_relation_oracle ();
+  void create_relation_oracle (bool do_trans_p = true);
   void destroy_relation_oracle ();
 
   inline class infer_range_oracle &infer_oracle () const { return *m_infer; }
diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc
index d7bc1b72558..9293d9ed65b 100644
--- a/gcc/value-relation.cc
+++ b/gcc/value-relation.cc
@@ -978,8 +978,9 @@ relation_chain_head::find_relation (const_bitmap b1, const_bitmap b2) const
 
 // Instantiate a relation oracle.
 
-dom_oracle::dom_oracle ()
+dom_oracle::dom_oracle (bool do_trans_p)
 {
+  m_do_trans_p = do_trans_p;
   m_relations.create (0);
   m_relations.safe_grow_cleared (last_basic_block_for_fn (cfun) + 1);
   m_relation_set = BITMAP_ALLOC (&m_bitmaps);
@@ -1179,6 +1180,9 @@ void
 dom_oracle::register_transitives (basic_block root_bb,
 				  const value_relation &relation)
 {
+  // Only register transitives if they are requested.
+  if (!m_do_trans_p)
+    return;
   basic_block bb;
   // Only apply transitives to certain kinds of operations.
   switch (relation.kind ())
diff --git a/gcc/value-relation.h b/gcc/value-relation.h
index cf009e6aa19..f168fd9ed41 100644
--- a/gcc/value-relation.h
+++ b/gcc/value-relation.h
@@ -216,7 +216,7 @@ public:
 class dom_oracle : public equiv_oracle
 {
 public:
-  dom_oracle ();
+  dom_oracle (bool do_trans_p = true);
   ~dom_oracle ();
 
   void record (basic_block bb, relation_kind k, tree op1, tree op2)
@@ -229,6 +229,7 @@ public:
   void dump (FILE *f, basic_block bb) const final override;
   void dump (FILE *f) const final override;
 private:
+  bool m_do_trans_p;
   bitmap m_tmp, m_tmp2;
   bitmap m_relation_set;  // Index by ssa-name. True if a relation exists
   vec <relation_chain_head> m_relations;  // Index by BB, list of relations.
-- 
2.45.0

Reply via email to