On Fri, Apr 25, 2025 at 11:54 AM Jakub Jelinek <ja...@redhat.com> wrote:
>
> On Sat, Apr 19, 2025 at 08:33:48PM -0700, Andrew Pinski wrote:
> > > +       {
> > > +         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))
> > > +           other_value = gimple_call_arg (call, flags & 
> > > ERF_RETURN_ARG_MASK);
>
> I think this needs to verify that other_value's type is uselessly
> convertible to TREE_TYPE (ret_var).
> Because just relying on operand_equal_p returning false otherwise wouldn't
> work.
> E.g. if call is memcpy, and you pass say NULL as the first argument to it
> (and some pointer and some non-constant as last), but the function returns
> unsigned char 0, you don't want to do a tail call just because NULL is equal
> to that unsigned char 0.  Sure, on lots of targets/ABIs that will in this
> particular case work fine, but isn't guaranteed to work on all.
> Perhaps on 32-bit arches if function returns 0ULL?

Yes you are right. Along the similar lines I noticed that
useless_type_conversion_p is also too strong in some cases; I filed PR
119945 for that. I will implement the fix for that too. It does not
matter for musttail compatibility since clang requires the same return
types so we didn't see that come up until now.
Anyways I will fix that one too.

Thanks,
Andrew

>
>         Jakub
>

Reply via email to