Hi, I believe that the current function ipa_range_set_and_normalize lacks a check that a base of an ADDR_EXPR lacks a test whether the base really cannot be NULL, so this patch adds it. Moreover, I never liked the name as I do not think it makes the value of ranges any more normal but rather just special-cases non-zero ip_invariant pointers. Therefore, I have given it a different name and moved it to a .cc file, our LTO bootstrap should inline (and/or split) it if necessary anyway.
Bootstrapped and tested on x86_64-linux, the whole patch series has additionally passed LTO and profiled-LTO bootstrap on the same platform and a bootstrap and testsuite on ppc64-linux. Aarch64-linux bootstrap and testing is in progress. OK for master is that passes too? Thanks, Martin gcc/ChangeLog: 2024-11-04 Martin Jambor <mjam...@suse.cz> * ipa-prop.h (ipa_get_range_from_ip_invariant): Declare. (ipa_range_set_and_normalize): Remove. * ipa-prop.cc (ipa_get_range_from_ip_invariant): New function. * ipa-cp.cc (ipa_vr_intersect_with_arith_jfunc): Use ipa_get_range_from_ip_invariant instead of ipa_range_set_and_normalize. * ipa-fnsummary.cc (evaluate_conditions_for_known_args): Likewise. --- gcc/ipa-cp.cc | 2 +- gcc/ipa-fnsummary.cc | 4 ++-- gcc/ipa-prop.cc | 17 +++++++++++++++++ gcc/ipa-prop.h | 15 +-------------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index f979fcd561d..83e30b6be55 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -1756,7 +1756,7 @@ ipa_vr_intersect_with_arith_jfunc (vrange &vr, if (!handler) return; value_range op_vr (TREE_TYPE (operand)); - ipa_range_set_and_normalize (op_vr, operand); + ipa_get_range_from_ip_invariant (op_vr, operand); tree operation_type; if (TREE_CODE_CLASS (operation) == tcc_comparison) diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc index e921cd495f6..6a28ecd873c 100644 --- a/gcc/ipa-fnsummary.cc +++ b/gcc/ipa-fnsummary.cc @@ -519,7 +519,7 @@ evaluate_conditions_for_known_args (struct cgraph_node *node, value_range op0 (TREE_TYPE (op->val[0])); range_op_handler handler (op->code); - ipa_range_set_and_normalize (op0, op->val[0]); + ipa_get_range_from_ip_invariant (op0, op->val[0]); if (!handler || !res.supports_type_p (op->type) @@ -538,7 +538,7 @@ evaluate_conditions_for_known_args (struct cgraph_node *node, value_range val_vr (TREE_TYPE (c->val)); range_op_handler handler (c->code); - ipa_range_set_and_normalize (val_vr, c->val); + ipa_get_range_from_ip_invariant (val_vr, c->val); if (!handler || !val_vr.supports_type_p (TREE_TYPE (c->val)) diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index 3ff4753653b..07e3c62eb07 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -2312,6 +2312,23 @@ ipa_set_jfunc_vr (ipa_jump_func *jf, const ipa_vr &vr) ipa_set_jfunc_vr (jf, tmp); } +/* Given VAL that conforms to is_gimple_ip_invariant, produce a VRANGE that + represents it as a range. */ + +void +ipa_get_range_from_ip_invariant (vrange &r, tree val) +{ + if (TREE_CODE (val) == ADDR_EXPR) + { + bool strict_overflow = false; + if (tree_single_nonzero_warnv_p (val, &strict_overflow)) + r.set_nonzero (TREE_TYPE (val)); + else + r.set_varying (TREE_TYPE (val)); + } + else + r.set (val, val); +} /* If T is an SSA_NAME that is a result of a simple type conversion statement, return the operand of that conversion, otherwise treturn T. */ diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index 3215395286b..e0064b4b2c9 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -1257,7 +1257,7 @@ tree ipcp_get_aggregate_const (struct function *func, tree parm, bool by_ref, HOST_WIDE_INT bit_size); bool unadjusted_ptr_and_unit_offset (tree op, tree *ret, poly_int64 *offset_ret); - +void ipa_get_range_from_ip_invariant (vrange &r, tree val); void ipa_prop_cc_finalize (void); /* From tree-sra.cc: */ @@ -1266,19 +1266,6 @@ tree build_ref_for_offset (location_t, tree, poly_int64, bool, tree, /* In ipa-cp.cc */ void ipa_cp_cc_finalize (void); - -/* Set R to the range of [VAL, VAL] while normalizing addresses to - non-zero. */ - -inline void -ipa_range_set_and_normalize (vrange &r, tree val) -{ - if (TREE_CODE (val) == ADDR_EXPR) - r.set_nonzero (TREE_TYPE (val)); - else - r.set (val, val); -} - bool ipa_return_value_range (value_range &range, tree decl); void ipa_record_return_value_range (value_range val); bool ipa_jump_functions_equivalent_p (ipa_jump_func *jf1, ipa_jump_func *jf2); -- 2.47.0