This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH for named return value optimization
>>>>> "Gabriel" == Gabriel Dos Reis <gdr@codesourcery.com> writes:
> Jason Merrill <jason_merrill@redhat.com> writes:
> | This has been sitting in my to-be-finished directory for several months;
> | sorry I didn't remember it in time for 3.0.
> |
> | This is all pretty straightforward: if a function always returns the same
> | local variable in memory, it is stored in the return slot and the returns
> | become noops. The latter is accomplished by setting a flag on the
> | RETURN_STMT. I'm somewhat uncomfortable about that choice, but any tree
> | rewriting would break inlining.
> What I did at the time was in two-phase (I now think your approach is
> better in terms of compile-time performance):
> 1) Walk through the body and identify the potential named return value.
> 2) Replace it with DECL_RESULT.
> That is done before calling the inliner.
> In what would that break inlining?
I suppose it wouldn't. I was thinking of tweaking the RTL like I do and
splicing out the RETURN_STMTs, which would break inlining. But if you
replace the chosen VAR_DECL with DECL_RESULT everywhere in the trees and
splice out the RETURN_STMTs, I suppose that would work, too.
Actually, your scheme would work better with inlining; mine doesn't
optimize the inline case, either. I'll play with this a bit further.
Thanks,
Jason