This is a set of 5 patches which cleans up GORIs compute_operand routines.
This is the mechanism GORI uses to calculate ranges from the bottom of the routine back thru definitions in the block to the name that is requested.
Currently, compute_operand_range() is called on a stmt, and it divides the work based on which operands are used to get back to the requested name. It calls compute_operand1_range or compute_operand2_range or compute_operand1_and_operand2_range. If the specified name is not on this statement, then a call back to compute_operand_range on the definition statement is made.
this means the call chain is recursive, but involves alternating functions. This patch sets changes the compute_operand1_range and compute_operand2_range to be leaf functions, and then compute_operand_range is still recursive, but has a much smaller stack footprint, and is also becomes a tailcall.
I tried removing the recursion, but at this point, removing the recursion is a performance hit :-P stay tuned on that one.
This patch moves some common code for relation discovery from compute_operand[12]range into compute_operand_range.
Bootstraps on x86_64-pc-linux-gnu with no regressions. Pushed. Andrew
From 290798faef706c335bd346b13771f977ddedb415 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod <amacl...@redhat.com> Date: Tue, 4 Jul 2023 11:28:52 -0400 Subject: [PATCH 1/6] Move relation discovery into compute_operand_range compute_operand1_range and compute_operand2_range were both doing relation discovery between the 2 operands... move it into a common area. * gimple-range-gori.cc (compute_operand_range): Check for a relation between op1 and op2 and use that instead. (compute_operand1_range): Don't look for a relation override. (compute_operand2_range): Ditto. --- gcc/gimple-range-gori.cc | 42 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 4ee0ae36014..b0d13a8ac53 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -623,6 +623,18 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, tree op1 = gimple_range_ssa_p (handler.operand1 ()); tree op2 = gimple_range_ssa_p (handler.operand2 ()); + // If there is a relation betwen op1 and op2, use it instead as it is + // likely to be more applicable. + if (op1 && op2) + { + relation_kind k = handler.op1_op2_relation (lhs); + if (k != VREL_VARYING) + { + vrel.set_relation (k, op1, op2); + vrel_ptr = &vrel; + } + } + // Handle end of lookup first. if (op1 == name) return compute_operand1_range (r, handler, lhs, name, src, vrel_ptr); @@ -1079,7 +1091,6 @@ gori_compute::compute_operand1_range (vrange &r, const vrange &lhs, tree name, fur_source &src, value_relation *rel) { - value_relation local_rel; gimple *stmt = handler.stmt (); tree op1 = handler.operand1 (); tree op2 = handler.operand2 (); @@ -1088,7 +1099,6 @@ gori_compute::compute_operand1_range (vrange &r, relation_trio trio; if (rel) trio = rel->create_trio (lhs_name, op1, op2); - relation_kind op_op = trio.op1_op2 (); Value_Range op1_range (TREE_TYPE (op1)); Value_Range tmp (TREE_TYPE (op1)); @@ -1102,19 +1112,7 @@ gori_compute::compute_operand1_range (vrange &r, { src.get_operand (op2_range, op2); - // If there is a relation betwen op1 and op2, use it instead. - // This allows multiple relations to be processed in compound logicals. - if (gimple_range_ssa_p (op1) && gimple_range_ssa_p (op2)) - { - relation_kind k = handler.op1_op2_relation (lhs); - if (k != VREL_VARYING) - { - op_op = k; - local_rel.set_relation (op_op, op1, op2); - rel = &local_rel; - } - } - + relation_kind op_op = trio.op1_op2 (); if (op_op != VREL_VARYING) refine_using_relation (op1, op1_range, op2, op2_range, src, op_op); @@ -1189,7 +1187,6 @@ gori_compute::compute_operand2_range (vrange &r, const vrange &lhs, tree name, fur_source &src, value_relation *rel) { - value_relation local_rel; gimple *stmt = handler.stmt (); tree op1 = handler.operand1 (); tree op2 = handler.operand2 (); @@ -1207,19 +1204,6 @@ gori_compute::compute_operand2_range (vrange &r, trio = rel->create_trio (lhs_name, op1, op2); relation_kind op_op = trio.op1_op2 (); - // If there is a relation betwen op1 and op2, use it instead. - // This allows multiple relations to be processed in compound logicals. - if (gimple_range_ssa_p (op1) && gimple_range_ssa_p (op2)) - { - relation_kind k = handler.op1_op2_relation (lhs); - if (k != VREL_VARYING) - { - op_op = k; - local_rel.set_relation (op_op, op1, op2); - rel = &local_rel; - } - } - if (op_op != VREL_VARYING) refine_using_relation (op1, op1_range, op2, op2_range, src, op_op); -- 2.40.1