diff mbox series

[COMMITTED,5/5] Make compute_operand_range a tail call.

Message ID b6b8901e-00e9-a30c-0892-aebd98199ee1@redhat.com
State New
Headers show
Series None | expand

Commit Message

Andrew MacLeod July 5, 2023, 11:08 p.m. UTC
This simply tweaks cmpute_operand_range a little so the recursion is a 
tail call.

With this, the patchset produces a modest speedup of 0.2% in VRP and 
0.4% in threading.  It will also have a much smaller stack profile.

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

Andrew
diff mbox series

Patch

From 51ed3a6ce432e7e6226bb62125ef8a09b2ebf60c Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Wed, 5 Jul 2023 14:26:00 -0400
Subject: [PATCH 5/6] Make compute_operand_range a tail call.

Tweak the routine so it is making a tail call.

	* gimple-range-gori.cc (compute_operand_range): Convert to a tail
	call.
---
 gcc/gimple-range-gori.cc | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc
index b036ed56f02..6dc15a0ce3f 100644
--- a/gcc/gimple-range-gori.cc
+++ b/gcc/gimple-range-gori.cc
@@ -725,36 +725,34 @@  gori_compute::compute_operand_range (vrange &r, gimple *stmt,
 			     op1_trange, op1_frange, op2_trange, op2_frange);
       if (idx)
 	tracer.trailer (idx, "compute_operand", res, name, r);
+      return res;
     }
   // Follow the appropriate operands now.
-  else if (op1_in_chain && op2_in_chain)
-    res = compute_operand1_and_operand2_range (r, handler, lhs, name, src,
-					       vrel_ptr);
-  else if (op1_in_chain)
+  if (op1_in_chain && op2_in_chain)
+    return compute_operand1_and_operand2_range (r, handler, lhs, name, src,
+						vrel_ptr);
+  Value_Range vr;
+  gimple *src_stmt;
+  if (op1_in_chain)
     {
-      Value_Range vr (TREE_TYPE (op1));
+      vr.set_type (TREE_TYPE (op1));
       if (!compute_operand1_range (vr, handler, lhs, src, vrel_ptr))
 	return false;
-      gimple *src_stmt = SSA_NAME_DEF_STMT (op1);
-      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);
+      src_stmt = SSA_NAME_DEF_STMT (op1);
     }
-  else if (op2_in_chain)
+  else
     {
-      Value_Range vr (TREE_TYPE (op2));
+      gcc_checking_assert (op2_in_chain);
+      vr.set_type (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);
+      src_stmt = SSA_NAME_DEF_STMT (op2);
     }
-  else
-    gcc_unreachable ();
 
+  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);
   // If neither operand is derived, this statement tells us nothing.
-  return res;
 }
 
 
-- 
2.40.1