@@ -1682,6 +1682,51 @@ ipa_vr_operation_and_type_effects (vrange &dst_vr,
dst_type, src_type);
}
+/* Given a constant function JFUNC, check that VR also contains all that should
+ have been deduced at the call-site, PARAM_TYPE is the type of the
+ parameter. */
+
+DEBUG_FUNCTION void
+ipa_check_const_jf_vr (ipa_jump_func *jfunc, const vrange &vr,
+ tree param_type)
+{
+ if (vr.singleton_p ())
+ return;
+
+ tree val = ipa_get_jf_constant (jfunc);
+ if (!ipa_vr_supported_type_p (TREE_TYPE (val)))
+ return;
+
+ if (POINTER_TYPE_P (TREE_TYPE (val)))
+ {
+ /* TODO: Non-nullness is sometimes lost here. */
+ if (!POINTER_TYPE_P (param_type))
+ return;
+ bool strict_overflow = false;
+ if (zerop (val))
+ {
+ if (is_a <prange> (vr) && vr.zero_p ())
+ return;
+ }
+ else if (tree_single_nonzero_warnv_p (val, &strict_overflow))
+ {
+ tree zero = build_zero_cst (param_type);
+ if (!vr.contains_p (zero))
+ return;
+ }
+ else
+ return;
+ }
+ fprintf (stderr, "Value range has not picked up expected information "
+ "for an IPA invariant:\n");
+ fprintf (stderr, "Jump function: ");
+ ipa_dump_jump_function (stderr, jfunc);
+ fprintf (stderr, "Value range: ");
+ vr.dump (stderr);
+ fprintf (stderr, "\n");
+ gcc_unreachable ();
+}
+
/* Given a PASS_THROUGH jump function JFUNC that takes as its source SRC_VR of
SRC_TYPE and the result needs to be DST_TYPE, if any value range information
can be deduced at all, intersect VR with it. */
@@ -1747,6 +1792,10 @@ ipa_value_range_from_jfunc (vrange &vr,
*jfunc->m_vr,
NOP_EXPR, parm_type,
jfunc->m_vr->type ());
+
+ if (flag_checking && jfunc->type == IPA_JF_CONST)
+ ipa_check_const_jf_vr (jfunc, vr, parm_type);
+
if (vr.singleton_p ())
return;
@@ -2540,6 +2589,9 @@ propagate_vr_across_jump_function (cgraph_edge *cs, ipa_jump_func *jfunc,
param_type,
jfunc->m_vr->type ());
+ if (flag_checking && jfunc->type == IPA_JF_CONST)
+ ipa_check_const_jf_vr (jfunc, vr, param_type);
+
if (jfunc->type == IPA_JF_PASS_THROUGH)
{
ipa_node_params *caller_info = ipa_node_params_sum->get (cs->caller);