Once an inferred range such as non-null has been registered, its a waste of time to register and apply them over and over. Pointers that are frequently used often are registered in each basic block as non-null.  This patch prevents them from being registered if a dominator block has already indicated they are non-null.

This is a more subtle change over the first one for this testcase, with a nominal speed up of about 0.7% in VRP.  Overall compile time in VRP of GCC source files improves by about 0.8%, so it seems to map across most source files.

Bootstraps on build-x86_64-pc-linux-gnu with no regressions.  OK?

Andrew

From 9434efb95a481ea57db8d47919d05cbe17b8bcba Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacl...@redhat.com>
Date: Sat, 23 Nov 2024 14:05:54 -0500
Subject: [PATCH 3/3] Only add inferred ranges if they change the value.

Do not add an inferred range if it is already incorprated in the
current range of an SSA_NAME.

	PR tree-optimization/117467
	* gimple-range-infer.cc (infer_range_manager::add_ranges): Check
	range_of_expr to see if the inferred range is needed.
---
 gcc/gimple-range-infer.cc | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-range-infer.cc b/gcc/gimple-range-infer.cc
index e9ee4d13530..6239e19f7fb 100644
--- a/gcc/gimple-range-infer.cc
+++ b/gcc/gimple-range-infer.cc
@@ -377,7 +377,14 @@ void
 infer_range_manager::add_ranges (gimple *s, gimple_infer_range &infer)
 {
   for (unsigned x = 0; x < infer.num (); x++)
-    add_range (infer.name (x), s, infer.range (x));
+    {
+      tree arg = infer.name (x);
+      value_range r (TREE_TYPE (arg));
+      m_query->range_of_expr (r, arg, s);
+      // Only add the inferred range if it changes the current range.
+      if (r.intersect (infer.range (x)))
+	add_range (arg, s, infer.range (x));
+    }
 }
 
 // Add range R as an inferred range for NAME on stmt S.
-- 
2.45.0

Reply via email to