]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Track value_relations in GORI.
authorAndrew MacLeod <amacleod@redhat.com>
Thu, 22 Sep 2022 21:55:56 +0000 (17:55 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Thu, 29 Sep 2022 22:34:18 +0000 (18:34 -0400)
This allows GORI to recognize and pass relations along the calculation chain.
This will allow relations between the LHS and the operand being calculated
to be utilized in op1_range and op2_range.

* gimple-range-gori.cc (ori_compute::compute_operand_range):
Create a relation record and pass it along when possible.
(gori_compute::compute_operand1_range): Pass relation along.
(gori_compute::compute_operand2_range): Ditto.
(gori_compute::compute_operand1_and_operand2_range): Ditto.
* gimple-range-gori.h (class gori_compute): Adjust prototypes.
* gimple-range-op.cc (gimple_range_op_handler::calc_op1): Pass
relation to op1_range call.
(gimple_range_op_handler::calc_op2): Pass relation to op2_range call.
* gimple-range-op.h (class gimple_range_op_handler): Adjust
prototypes.

gcc/gimple-range-gori.cc
gcc/gimple-range-gori.h
gcc/gimple-range-op.cc
gcc/gimple-range-op.h

index 40b2f2f6ae9f1ee3ef9abe970ee30248ec49d558..57a7e8207494149a58788b310aeaca7d97bc042e 100644 (file)
@@ -603,8 +603,10 @@ gori_compute::compute_operand_range_switch (vrange &r, gswitch *s,
 bool
 gori_compute::compute_operand_range (vrange &r, gimple *stmt,
                                     const vrange &lhs, tree name,
-                                    fur_source &src)
+                                    fur_source &src, value_relation *rel)
 {
+  value_relation vrel;
+  value_relation *vrel_ptr = rel;
   // If the lhs doesn't tell us anything, neither will unwinding further.
   if (lhs.varying_p ())
     return false;
@@ -625,11 +627,23 @@ 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, use it instead of any passed in.  This will allow
+  // multiple relations to be processed in compound logicals.
+  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);
+    return compute_operand1_range (r, handler, lhs, name, src, vrel_ptr);
   if (op2 == name)
-    return compute_operand2_range (r, handler, lhs, name, src);
+    return compute_operand2_range (r, handler, lhs, name, src, vrel_ptr);
 
   // NAME is not in this stmt, but one of the names in it ought to be
   // derived from it.
@@ -672,11 +686,12 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt,
     }
   // Follow the appropriate operands now.
   else if (op1_in_chain && op2_in_chain)
-    res = compute_operand1_and_operand2_range (r, handler, lhs, name, src);
+    res = compute_operand1_and_operand2_range (r, handler, lhs, name, src,
+                                              vrel_ptr);
   else if (op1_in_chain)
-    res = compute_operand1_range (r, handler, lhs, name, src);
+    res = compute_operand1_range (r, handler, lhs, name, src, vrel_ptr);
   else if (op2_in_chain)
-    res = compute_operand2_range (r, handler, lhs, name, src);
+    res = compute_operand2_range (r, handler, lhs, name, src, vrel_ptr);
   else
     gcc_unreachable ();
 
@@ -927,7 +942,7 @@ bool
 gori_compute::compute_operand1_range (vrange &r,
                                      gimple_range_op_handler &handler,
                                      const vrange &lhs, tree name,
-                                     fur_source &src)
+                                     fur_source &src, value_relation *rel)
 {
   gimple *stmt = handler.stmt ();
   tree op1 = handler.operand1 ();
@@ -998,7 +1013,7 @@ gori_compute::compute_operand1_range (vrange &r,
   gcc_checking_assert (src_stmt);
 
   // Then feed this range back as the LHS of the defining statement.
-  return compute_operand_range (r, src_stmt, op1_range, name, src);
+  return compute_operand_range (r, src_stmt, op1_range, name, src, rel);
 }
 
 
@@ -1010,7 +1025,7 @@ bool
 gori_compute::compute_operand2_range (vrange &r,
                                      gimple_range_op_handler &handler,
                                      const vrange &lhs, tree name,
-                                     fur_source &src)
+                                     fur_source &src, value_relation *rel)
 {
   gimple *stmt = handler.stmt ();
   tree op1 = handler.operand1 ();
@@ -1070,7 +1085,7 @@ gori_compute::compute_operand2_range (vrange &r,
 //  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);
+  return compute_operand_range (r, src_stmt, op2_range, name, src, rel);
 }
 
 // Calculate a range for NAME from both operand positions of S
@@ -1083,17 +1098,18 @@ gori_compute::compute_operand1_and_operand2_range (vrange &r,
                                                                     &handler,
                                                   const vrange &lhs,
                                                   tree name,
-                                                  fur_source &src)
+                                                  fur_source &src,
+                                                  value_relation *rel)
 {
   Value_Range op_range (TREE_TYPE (name));
 
   // Calculate a good a range for op2.  Since op1 == op2, this will
   // have already included whatever the actual range of name is.
-  if (!compute_operand2_range (op_range, handler, lhs, name, src))
+  if (!compute_operand2_range (op_range, handler, lhs, name, src, rel))
     return false;
 
   // Now get the range thru op1.
-  if (!compute_operand1_range (r, handler, lhs, name, src))
+  if (!compute_operand1_range (r, handler, lhs, name, src, rel))
     return false;
 
   // Both operands have to be simultaneously true, so perform an intersection.
index 0c776ef853f749806270afafd00a4a3d19ae86ae..1fff3e6255a93912f9a715a74a514bebfc895444 100644 (file)
@@ -153,6 +153,8 @@ private:
 //
 // The remaining routines are internal use only.
 
+class value_relation;
+
 class gori_compute : public gori_map
 {
 public:
@@ -167,17 +169,21 @@ private:
   bool may_recompute_p (tree name, edge e);
   bool may_recompute_p (tree name, basic_block bb = NULL);
   bool compute_operand_range (vrange &r, gimple *stmt, const vrange &lhs,
-                             tree name, class fur_source &src);
+                             tree name, class fur_source &src,
+                             value_relation *rel = NULL);
   bool compute_operand_range_switch (vrange &r, gswitch *s, const vrange &lhs,
                                     tree name, fur_source &src);
   bool compute_operand1_range (vrange &r, gimple_range_op_handler &handler,
-                              const vrange &lhs, tree name, fur_source &src);
+                              const vrange &lhs, tree name, 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, tree name, fur_source &src,
+                              value_relation *rel = NULL);
   bool compute_operand1_and_operand2_range (vrange &r,
                                            gimple_range_op_handler &handler,
                                            const vrange &lhs, tree name,
-                                           fur_source &src);
+                                           fur_source &src,
+                                           value_relation *rel = NULL);
   void compute_logical_operands (vrange &true_range, vrange &false_range,
                                 gimple_range_op_handler &handler,
                                 const irange &lhs, tree name, fur_source &src,
index 3f5e5852e5a21329193e18d9eef9653bd90e2749..3a7c90746596d5f574c9dd41f8dcc350d97063ea 100644 (file)
@@ -202,7 +202,7 @@ gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range)
 
 bool
 gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range,
-                                  const vrange &op2_range)
+                                  const vrange &op2_range, relation_kind k)
 {
   // Give up on empty ranges.
   if (lhs_range.undefined_p ())
@@ -225,9 +225,9 @@ gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range,
        op2_type = TREE_TYPE (operand1 ());
       Value_Range trange (op2_type);
       trange.set_varying (op2_type);
-      return op1_range (r, type, lhs_range, trange);
+      return op1_range (r, type, lhs_range, trange, k);
     }
-  return op1_range (r, type, lhs_range, op2_range);
+  return op1_range (r, type, lhs_range, op2_range, k);
 }
 
 // Calculate what we can determine of the range of this statement's
@@ -237,7 +237,7 @@ gimple_range_op_handler::calc_op1 (vrange &r, const vrange &lhs_range,
 
 bool
 gimple_range_op_handler::calc_op2 (vrange &r, const vrange &lhs_range,
-                                  const vrange &op1_range)
+                                  const vrange &op1_range, relation_kind k)
 {
   // Give up on empty ranges.
   if (lhs_range.undefined_p ())
@@ -250,9 +250,9 @@ gimple_range_op_handler::calc_op2 (vrange &r, const vrange &lhs_range,
       tree op1_type = TREE_TYPE (operand1 ());
       Value_Range trange (op1_type);
       trange.set_varying (op1_type);
-      return op2_range (r, type, lhs_range, trange);
+      return op2_range (r, type, lhs_range, trange, k);
     }
-  return op2_range (r, type, lhs_range, op1_range);
+  return op2_range (r, type, lhs_range, op1_range, k);
 }
 
 // --------------------------------------------------------------------
index 68764198bc0605a657d573225700ef2447fc4816..3a555f29a65ae81cb5c7de86208b006e58f5c3c8 100644 (file)
@@ -35,8 +35,10 @@ public:
   tree operand1 () const { gcc_checking_assert (m_valid); return m_op1; }
   tree operand2 () const { gcc_checking_assert (m_valid); return m_op2; }
   bool calc_op1 (vrange &r, const vrange &lhs_range);
-  bool calc_op1 (vrange &r, const vrange &lhs_range, const vrange &op2_range);
-  bool calc_op2 (vrange &r, const vrange &lhs_range, const vrange &op1_range);
+  bool calc_op1 (vrange &r, const vrange &lhs_range, const vrange &op2_range,
+                relation_kind k = VREL_VARYING);
+  bool calc_op2 (vrange &r, const vrange &lhs_range, const vrange &op1_range,
+                relation_kind k = VREL_VARYING);
 private:
   void maybe_builtin_call ();
   gimple *m_stmt;