Pushed to trunk.
On Sun, Apr 28, 2024 at 10:10 PM Aldy Hernandez <al...@redhat.com> wrote:
>
> 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 palces, 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.
>
> OK for trunk?
>
> 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 | 14 +++++++-------
> gcc/ipa-cp.h | 8 ++++++++
> gcc/ipa-fnsummary.cc | 2 +-
> gcc/ipa-prop.cc | 8 +++-----
> 4 files changed, 19 insertions(+), 13 deletions(-)
>
> diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
> index a688dced5c9..5781f50c854 100644
> --- a/gcc/ipa-cp.cc
> +++ b/gcc/ipa-cp.cc
> @@ -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,
> diff --git a/gcc/ipa-cp.h b/gcc/ipa-cp.h
> index 7ff74fb5c98..abeaaa4053e 100644
> --- a/gcc/ipa-cp.h
> +++ b/gcc/ipa-cp.h
> @@ -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 */
> diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc
> index dff40cd8aa5..1dbf5278149 100644
> --- a/gcc/ipa-fnsummary.cc
> +++ b/gcc/ipa-fnsummary.cc
> @@ -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]);
> diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
> index b57f9750431..2d5c51298f2 100644
> --- a/gcc/ipa-prop.cc
> +++ b/gcc/ipa-prop.cc
> @@ -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);
> --
> 2.44.0
>