]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Minor range type fixes for IPA in preparation for prange.
authorAldy Hernandez <aldyh@redhat.com>
Tue, 19 Mar 2024 16:55:58 +0000 (17:55 +0100)
committerAldy Hernandez <aldyh@redhat.com>
Tue, 7 May 2024 10:17:50 +0000 (12:17 +0200)
The polymorphic Value_Range object takes a tree type at construction
so it can determine what type of range to use (currently irange or
frange).  It seems a few of the types are slightly off.  This isn't a
problem now, because IPA only cares about integers and pointers, which
can both live in an irange.  However, with prange coming about, we
need to get the type right, because you can't store an integer in a
pointer range or vice versa.

Also, in preparation for prange, the irange::supports_p() idiom will become:

      irange::supports_p () || prange::supports_p()

To avoid changing all these places, I've added an inline function we
can later change and change everything at once.

Finally, there's a Value_Range::supports_type_p() &&
irange::supports_p() in the code.  The latter is a subset of the
former, so there's no need to check both.

gcc/ChangeLog:

* ipa-cp.cc (ipa_vr_operation_and_type_effects): Use ipa_supports_p.
(ipa_value_range_from_jfunc): Change Value_Range type.
(propagate_vr_across_jump_function): Same.
* ipa-cp.h (ipa_supports_p): New.
* ipa-fnsummary.cc (evaluate_conditions_for_known_args): Change Value_Range type.
* ipa-prop.cc (ipa_compute_jump_functions_for_edge): Use ipa_supports_p.
(ipcp_get_parm_bits): Same.

gcc/ipa-cp.cc
gcc/ipa-cp.h
gcc/ipa-fnsummary.cc
gcc/ipa-prop.cc

index a688dced5c99fcee44ec40c0423b2157eefbe303..5781f50c85464a7594c1b575bb925bc743b32a2f 100644 (file)
@@ -1649,7 +1649,7 @@ ipa_vr_operation_and_type_effects (vrange &dst_vr,
                                   enum tree_code operation,
                                   tree dst_type, tree src_type)
 {
-  if (!irange::supports_p (dst_type) || !irange::supports_p (src_type))
+  if (!ipa_supports_p (dst_type) || !ipa_supports_p (src_type))
     return false;
 
   range_op_handler handler (operation);
@@ -1720,7 +1720,7 @@ ipa_value_range_from_jfunc (vrange &vr,
 
       if (TREE_CODE_CLASS (operation) == tcc_unary)
        {
-         Value_Range res (vr_type);
+         Value_Range res (parm_type);
 
          if (ipa_vr_operation_and_type_effects (res,
                                                 srcvr,
@@ -1733,7 +1733,7 @@ ipa_value_range_from_jfunc (vrange &vr,
          Value_Range op_res (vr_type);
          Value_Range res (vr_type);
          tree op = ipa_get_jf_pass_through_operand (jfunc);
-         Value_Range op_vr (vr_type);
+         Value_Range op_vr (TREE_TYPE (op));
          range_op_handler handler (operation);
 
          ipa_range_set_and_normalize (op_vr, op);
@@ -2527,7 +2527,7 @@ propagate_vr_across_jump_function (cgraph_edge *cs, ipa_jump_func *jfunc,
       if (src_lats->m_value_range.bottom_p ())
        return dest_lat->set_to_bottom ();
 
-      Value_Range vr (operand_type);
+      Value_Range vr (param_type);
       if (TREE_CODE_CLASS (operation) == tcc_unary)
        ipa_vr_operation_and_type_effects (vr,
                                           src_lats->m_value_range.m_vr,
@@ -2540,16 +2540,16 @@ propagate_vr_across_jump_function (cgraph_edge *cs, ipa_jump_func *jfunc,
        {
          tree op = ipa_get_jf_pass_through_operand (jfunc);
          Value_Range op_vr (TREE_TYPE (op));
-         Value_Range op_res (operand_type);
+         Value_Range op_res (param_type);
          range_op_handler handler (operation);
 
          ipa_range_set_and_normalize (op_vr, op);
 
          if (!handler
-             || !op_res.supports_type_p (operand_type)
+             || !ipa_supports_p (operand_type)
              || !handler.fold_range (op_res, operand_type,
                                      src_lats->m_value_range.m_vr, op_vr))
-           op_res.set_varying (operand_type);
+           op_res.set_varying (param_type);
 
          ipa_vr_operation_and_type_effects (vr,
                                             op_res,
index 7ff74fb5c981bd40f26bf7978a82e9e39fb992c0..abeaaa4053e190cf8645a8be27607115a34555bb 100644 (file)
@@ -291,4 +291,12 @@ public:
 
 bool values_equal_for_ipcp_p (tree x, tree y);
 
+/* Return TRUE if IPA supports ranges of TYPE.  */
+
+static inline bool
+ipa_supports_p (tree type)
+{
+  return irange::supports_p (type);
+}
+
 #endif /* IPA_CP_H */
index 668a01ef175f06199f3ab7f6f08094aa5c084044..07a853f78e39232220d89b2e53c757a6cb61ae4f 100644 (file)
@@ -515,7 +515,7 @@ evaluate_conditions_for_known_args (struct cgraph_node *node,
                    }
                  else if (!op->val[1])
                    {
-                     Value_Range op0 (op->type);
+                     Value_Range op0 (TREE_TYPE (op->val[0]));
                      range_op_handler handler (op->code);
 
                      ipa_range_set_and_normalize (op0, op->val[0]);
index b57f9750431195114e6e1d0ca2cceacd97e01eed..2d5c51298f2b4e72ef75164d081ec7c6225f9f93 100644 (file)
@@ -2392,10 +2392,8 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
       else
        {
          if (param_type
-             && Value_Range::supports_type_p (TREE_TYPE (arg))
-             && Value_Range::supports_type_p (param_type)
-             && irange::supports_p (TREE_TYPE (arg))
-             && irange::supports_p (param_type)
+             && ipa_supports_p (TREE_TYPE (arg))
+             && ipa_supports_p (param_type)
              && get_range_query (cfun)->range_of_expr (vr, arg, cs->call_stmt)
              && !vr.undefined_p ())
            {
@@ -5763,7 +5761,7 @@ ipcp_get_parm_bits (tree parm, tree *value, widest_int *mask)
   ipcp_transformation *ts = ipcp_get_transformation_summary (cnode);
   if (!ts
       || vec_safe_length (ts->m_vr) == 0
-      || !irange::supports_p (TREE_TYPE (parm)))
+      || !ipa_supports_p (TREE_TYPE (parm)))
     return false;
 
   int i = ts->get_param_index (current_function_decl, parm);