On Thu, 24 Nov 2016, Prathamesh Kulkarni wrote:

> Hi,
> Consider following test-case:
> 
> void *f(void *a1, void *a2, __SIZE_TYPE__ a3)
> {
>   __builtin_memcpy (a1, a2, a3);
>   return a1;
> }
> 
> return a1 can be considered equivalent to return value of memcpy,
> and the call could be emitted as a tail-call.
> gcc doesn't emit the above call to memcpy as a tail-call,
> but if it is changed to:
> 
> void *t1 = __builtin_memcpy (a1, a2, a3);
> return t1;
> 
> Then memcpy is emitted as a tail-call.
> The attached patch tries to handle the former case.
> 
> Bootstrapped+tested on x86_64-unknown-linux-gnu.
> Cross tested on arm*-*-*, aarch64*-*-*
> Does this patch look OK ?

+/* Return arg, if function returns it's argument or NULL if it doesn't.  
*/
+tree
+gimple_call_return_arg (gcall *call_stmt)
+{


Please just inline it at the single use - the name is not terribly
informative.

I'm not sure you can rely on code-generation working if you not
effectively change the IL to

  a1 = __builtin_memcpy (a1, a2, a3);
  return a1;

someone more familiar with RTL expansion plus tail call emission on
RTL needs to chime in.

Richard.

Reply via email to