diff mbox series

[COMMITTED,4/5] Make compute_operand2_range a leaf call.

Message ID f5662c87-368a-f072-3819-b6535baefeb1@redhat.com
State New
Headers show
Series None | expand

Commit Message

Andrew MacLeod July 5, 2023, 11:08 p.m. UTC
now operand2 alone is resolved, and returned as the result.  much 
cleaner, and removes it from the recursion stack.

compute_operand_range() will decide if further evaluation is required.

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

Andrew
diff mbox series

Patch

From 298952bcf05d298892e99adba1f4a75af17bc65a Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Wed, 5 Jul 2023 13:52:21 -0400
Subject: [PATCH 4/6] Make compute_operand2_range a leaf call.

Rather than creating long call chains, put the onus for finishing
the evlaution on the caller.

	* gimple-range-gori.cc (compute_operand_range): After calling
	compute_operand2_range, recursively call self if needed.
	(compute_operand2_range): Turn into a leaf function.
	(gori_compute::compute_operand1_and_operand2_range): Finish
	operand2 calculation.
	* gimple-range-gori.h (compute_operand2_range): Remove name param.
---
 gcc/gimple-range-gori.cc | 52 +++++++++++++++++++---------------------
 gcc/gimple-range-gori.h  |  2 +-
 2 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc
index b66b9b0398c..b036ed56f02 100644
--- a/gcc/gimple-range-gori.cc
+++ b/gcc/gimple-range-gori.cc
@@ -639,7 +639,7 @@  gori_compute::compute_operand_range (vrange &r, gimple *stmt,
   if (op1 == name)
     return compute_operand1_range (r, handler, lhs, src, vrel_ptr);
   if (op2 == name)
-    return compute_operand2_range (r, handler, lhs, name, src, vrel_ptr);
+    return compute_operand2_range (r, handler, lhs, src, vrel_ptr);
 
   // NAME is not in this stmt, but one of the names in it ought to be
   // derived from it.
@@ -741,7 +741,15 @@  gori_compute::compute_operand_range (vrange &r, gimple *stmt,
       return compute_operand_range (r, src_stmt, vr, name, src, vrel_ptr);
     }
   else if (op2_in_chain)
-    res = compute_operand2_range (r, handler, lhs, name, src, vrel_ptr);
+    {
+      Value_Range vr (TREE_TYPE (op2));
+      if (!compute_operand2_range (vr, handler, lhs, src, vrel_ptr))
+	return false;
+      gimple *src_stmt = SSA_NAME_DEF_STMT (op2);
+      gcc_checking_assert (src_stmt);
+      // Then feed this range back as the LHS of the defining statement.
+      return compute_operand_range (r, src_stmt, vr, name, src, vrel_ptr);
+    }
   else
     gcc_unreachable ();
 
@@ -1188,7 +1196,7 @@  gori_compute::compute_operand1_range (vrange &r,
 bool
 gori_compute::compute_operand2_range (vrange &r,
 				      gimple_range_op_handler &handler,
-				      const vrange &lhs, tree name,
+				      const vrange &lhs,
 				      fur_source &src, value_relation *rel)
 {
   gimple *stmt = handler.stmt ();
@@ -1198,7 +1206,6 @@  gori_compute::compute_operand2_range (vrange &r,
 
   Value_Range op1_range (TREE_TYPE (op1));
   Value_Range op2_range (TREE_TYPE (op2));
-  Value_Range tmp (TREE_TYPE (op2));
 
   src.get_operand (op1_range, op1);
   src.get_operand (op2_range, op2);
@@ -1215,7 +1222,7 @@  gori_compute::compute_operand2_range (vrange &r,
   if (op1 == op2 && gimple_range_ssa_p (op1))
     trio = relation_trio (trio.lhs_op1 (), trio.lhs_op2 (), VREL_EQ);
   // Intersect with range for op2 based on lhs and op1.
-  if (!handler.calc_op2 (tmp, lhs, op1_range, trio))
+  if (!handler.calc_op2 (r, lhs, op1_range, trio))
     return false;
 
   unsigned idx;
@@ -1237,31 +1244,16 @@  gori_compute::compute_operand2_range (vrange &r,
       tracer.print (idx, "Computes ");
       print_generic_expr (dump_file, op2, TDF_SLIM);
       fprintf (dump_file, " = ");
-      tmp.dump (dump_file);
+      r.dump (dump_file);
       fprintf (dump_file, " intersect Known range : ");
       op2_range.dump (dump_file);
       fputc ('\n', dump_file);
     }
   // Intersect the calculated result with the known result and return if done.
-  if (op2 == name)
-    {
-      tmp.intersect (op2_range);
-      r = tmp;
-      if (idx)
-	tracer.trailer (idx, " produces ", true, NULL_TREE, r);
-      return true;
-    }
-  // If the calculation continues, we're using op2_range as the new LHS.
-  op2_range.intersect (tmp);
-
+  r.intersect (op2_range);
   if (idx)
-    tracer.trailer (idx, " produces ", true, op2, op2_range);
-  gimple *src_stmt = SSA_NAME_DEF_STMT (op2);
-  gcc_checking_assert (src_stmt);
-//  gcc_checking_assert (!is_import_p (op2, find.bb));
-
-  // Then feed this range back as the LHS of the defining statement.
-  return compute_operand_range (r, src_stmt, op2_range, name, src, rel);
+    tracer.trailer (idx, " produces ", true, op2, r);
+  return true;
 }
 
 // Calculate a range for NAME from both operand positions of S
@@ -1279,15 +1271,21 @@  gori_compute::compute_operand1_and_operand2_range (vrange &r,
 {
   Value_Range op_range (TREE_TYPE (name));
 
+  Value_Range vr (TREE_TYPE (handler.operand2 ()));
   // Calculate a good a range through op2.
-  if (!compute_operand2_range (r, handler, lhs, name, src, rel))
+  if (!compute_operand2_range (vr, handler, lhs, src, rel))
+    return false;
+  gimple *src_stmt = SSA_NAME_DEF_STMT (handler.operand2 ());
+  gcc_checking_assert (src_stmt);
+  // Then feed this range back as the LHS of the defining statement.
+  if (!compute_operand_range (r, src_stmt, vr, name, src, rel))
     return false;
 
   // Now get the range thru op1.
-  Value_Range vr (TREE_TYPE (handler.operand1 ()));
+  vr.set_type (TREE_TYPE (handler.operand1 ()));
   if (!compute_operand1_range (vr, handler, lhs, src, rel))
     return false;
-  gimple *src_stmt = SSA_NAME_DEF_STMT (handler.operand1 ());
+  src_stmt = SSA_NAME_DEF_STMT (handler.operand1 ());
   gcc_checking_assert (src_stmt);
   // Then feed this range back as the LHS of the defining statement.
   if (!compute_operand_range (op_range, src_stmt, vr, name, src, rel))
diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h
index 1d451fa7e9a..b8d97d1dd72 100644
--- a/gcc/gimple-range-gori.h
+++ b/gcc/gimple-range-gori.h
@@ -186,7 +186,7 @@  private:
 			       const vrange &lhs, fur_source &src,
 			       value_relation *rel = NULL);
   bool compute_operand2_range (vrange &r, gimple_range_op_handler &handler,
-			       const vrange &lhs, tree name, fur_source &src,
+			       const vrange &lhs, fur_source &src,
 			       value_relation *rel = NULL);
   bool compute_operand1_and_operand2_range (vrange &r,
 					    gimple_range_op_handler &handler,
-- 
2.40.1