On 7/1/25 10:13 PM, Andrew Pinski wrote:
With struct returns, we normally get a decl on the LHS of the call expression
that will be tail called and we can match things up there easy.
With TREE_ADDRESSABLE set on the type, things get more complex.
Instead we get:
```
   *_6(D) = get_s (1); [return slot optimization]
...
   return _6(D);
```

So we have to match _6 as being the ssa name for the result decl, make sure RSO 
is set
and match MEM_REF with a zero offset if we want to do tail calls.

This is also the first step in allowing tail calls in this case too;  I will 
expand
the patch for PR71761 to handle the taill call later on.

Bootstrapped and tested on x86_64-linux-gnu and aarch64-linux-gnu.

        PR tree-optimization/120871

gcc/ChangeLog:

        * tree-tailcall.cc (find_tail_calls): Allow a MEM_REF
        with a zero offset with RSO set on the call and with
        the MEM_REF is of the result decl default definition.

gcc/testsuite/ChangeLog:

        * g++.dg/opt/tail-call-1.C: New test.
Do you have to worry about statements between the call and return statements? ISTM that to get a tail call all those statements would have be eliminated.

Or is this just about getting things marked so that we have a fighting chance to realize a tail call optimization later?

Jeff

Reply via email to