On Mon, Apr 28, 2025 at 12:37 AM Jakub Jelinek <ja...@redhat.com> wrote:
>
> On Fri, Apr 25, 2025 at 09:12:45PM -0700, Andrew Pinski wrote:
> > --- a/gcc/tree-tailcall.cc
> > +++ b/gcc/tree-tailcall.cc
> > @@ -1083,57 +1083,74 @@ find_tail_calls (basic_block bb, struct tailcall 
> > **ret, bool only_musttail,
> >      {
> >        bool ok = false;
> >        value_range val;
> > -      tree valr;
> > -      /* If IPA-VRP proves called function always returns a singleton 
> > range,
> > -      the return value is replaced by the only value in that range.
> > -      For tail call purposes, pretend such replacement didn't happen.  */
> >        if (ass_var == NULL_TREE && !tail_recursion)
> > -     if (tree type = gimple_range_type (call))
> > -       if (tree callee = gimple_call_fndecl (call))
> > -         if ((INTEGRAL_TYPE_P (type)
> > -              || SCALAR_FLOAT_TYPE_P (type)
> > -              || POINTER_TYPE_P (type))
> > -             && useless_type_conversion_p (TREE_TYPE (TREE_TYPE (callee)),
> > -                                           type)
> > -             && useless_type_conversion_p (TREE_TYPE (ret_var), type)
> > -             && ipa_return_value_range (val, callee)
> > -             && val.singleton_p (&valr))
> > +     {
> > +       tree other_value = NULL_TREE;
> > +       /* If we have a function call that we know the return value is the 
> > same
> > +          as the argument, try the argument too. */
> > +       int flags = gimple_call_return_flags (call);
> > +       if ((flags & ERF_RETURNS_ARG) != 0
> > +           && (flags & ERF_RETURN_ARG_MASK) < gimple_call_num_args (call))
> > +         {
> > +           tree arg = gimple_call_arg (call, flags & ERF_RETURN_ARG_MASK);
> > +           if (useless_type_conversion_p (TREE_TYPE (arg), TREE_TYPE 
> > (ret_var)))
>
> This should have the arguments swapped, i.e.
>               if (useless_type_conversion_p (TREE_TYPE (ret_var), TREE_TYPE 
> (arg)))
> because we want to check if the type of arg is uselessly convertible to the
> ret_var type (i.e. the return type).

Oh yes, I forgot that useless_type_conversion_p was not symmetric.
Thanks for the fix.

>
> Otherwise LGTM.

Just to double check, was this an approval after the fix for the call
to useless_type_conversion_p?

Thanks,
Andrew

>
>         Jakub
>

Reply via email to