On Wed, Jan 14, 2026 at 11:28 AM Martin Jambor <[email protected]> wrote:
>
> Hi,
>
> PR 123542 is about triggering a checking assert that verifies that we
> indeed clone a function for the constant value we started evaluating.
> The issue is that we get a double 2 instead of a float 2 which comes
> down to function ipa_value_from_jfunc not doing the necessary
> conversion when dealing directly with constants (and ancestor jump
> functions but that is very unlikley to cause problems).
>
> This patch makes sure the required conversion is performed in all
> cases (even for the ancestor JFs) and checks that the result tyoe is
> known, because when the function is invoked from ipa-modref.cc or
> ipa-fnsummary.cc that may not be the case.
>
> Bootstrapped and tested on x86_64-linux.  OK for master?

Ok.

>
> I do not think the patch strictly needs backporting.  In previous
> versions, IPA-CP would use directly the value from the lattice and other
> uses either look for pointer usage (modref) or are just for heuristics
> (ipa-fnsummary).
>
> Thanks,
>
> Martin
>
>
> gcc/ChangeLog:
>
> 2026-01-14  Martin Jambor  <[email protected]>
>
>         PR ipa/123542
>         * ipa-cp.cc (ipa_value_from_jfunc): Always use
>         ipacp_value_safe_for_type.  Bail out if parm_type is NULL.
>
> gcc/testsuite/ChangeLog:
>
> 2026-01-14  Martin Jambor  <[email protected]>
>
>         PR ipa/123542
>         * gcc.dg/ipa/pr123542.c: New test.
> ---
>  gcc/ipa-cp.cc                       | 10 ++++++----
>  gcc/testsuite/gcc.dg/ipa/pr123542.c | 13 +++++++++++++
>  2 files changed, 19 insertions(+), 4 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/ipa/pr123542.c
>
> diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
> index 9f61f682d58..8e2aafc7923 100644
> --- a/gcc/ipa-cp.cc
> +++ b/gcc/ipa-cp.cc
> @@ -1627,8 +1627,10 @@ tree
>  ipa_value_from_jfunc (class ipa_node_params *info, struct ipa_jump_func 
> *jfunc,
>                       tree parm_type)
>  {
> +  if (!parm_type)
> +    return NULL_TREE;
>    if (jfunc->type == IPA_JF_CONST)
> -    return ipa_get_jf_constant (jfunc);
> +    return ipacp_value_safe_for_type (parm_type, ipa_get_jf_constant 
> (jfunc));
>    else if (jfunc->type == IPA_JF_PASS_THROUGH
>            || jfunc->type == IPA_JF_ANCESTOR)
>      {
> @@ -1660,8 +1662,6 @@ ipa_value_from_jfunc (class ipa_node_params *info, 
> struct ipa_jump_func *jfunc,
>
>        if (jfunc->type == IPA_JF_PASS_THROUGH)
>         {
> -         if (!parm_type)
> -           return NULL_TREE;
>           enum tree_code opcode = ipa_get_jf_pass_through_operation (jfunc);
>           tree op2 = ipa_get_jf_pass_through_operand (jfunc);
>           tree op_type
> @@ -1671,7 +1671,9 @@ ipa_value_from_jfunc (class ipa_node_params *info, 
> struct ipa_jump_func *jfunc,
>           return ipacp_value_safe_for_type (parm_type, cstval);
>         }
>        else
> -       return ipa_get_jf_ancestor_result (jfunc, input);
> +       return ipacp_value_safe_for_type (parm_type,
> +                                         ipa_get_jf_ancestor_result (jfunc,
> +                                                                     input));
>      }
>    else
>      return NULL_TREE;
> diff --git a/gcc/testsuite/gcc.dg/ipa/pr123542.c 
> b/gcc/testsuite/gcc.dg/ipa/pr123542.c
> new file mode 100644
> index 00000000000..76af651b797
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/ipa/pr123542.c
> @@ -0,0 +1,13 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O3 -std=gnu89" } */
> +
> +double cos(double);
> +void sub(p1, p2, p3, p4, p5, p6) float p1, p2, p3, *p4, p5, p6;
> +{
> +  float ar2 = cos(*p4);
> +  if (p2)
> +    ar2 = 0.0;
> +  for (;;)
> +    *p4 += ar2;
> +}
> +void main() { sub(1.0, 2.0); }
> --
> 2.52.0
>

Reply via email to