> From: Kyrylo Tkachov <[email protected]>
> 
> [This a respin of
> https://gcc.gnu.org/pipermail/gcc-patches/2026-October/735400.html after
> comments from Andrea]
> 
> The early inliner charges an aggregate copy into the return value even
> when its source is a local variable that SRA can remove after inlining.
> For a value-type wrapper such as
> 
>   T operator* (const T &a, const T &b)
>   {
>     T t = a;
>     return t *= b;
>   }
> 
> the copy appears as
> 
>   <retval> = t;
> 
> Charging this copy can put the wrapper above early-inlining-insns and
> leave its operands and result in memory at each call.
> 
> Credit aggregate return copies from automatic local variables and
> parameters whose address is not taken.  Recognize both RESULT_DECL and
> an invisible-reference result.  Preserve the existing half credit for
> unmodified parameters.  Keep the cost of copies from globals, statics,
> pointers and address-taken locals.  Exclude volatile accesses before
> applying any elimination credit.
> 
> Add tests for early inlining, source restrictions, invisible-reference
> returns and volatile scalar and aggregate accesses.
> 
> Bootstrapped and tested on aarch64-none-linux-gnu and
> x86_64-pc-linux-gnu.
> 
> Ok for trunk?
> Thanks,
> Kyrill
> 
> Cc: Martin Jambor <[email protected]>
> Cc: Jan Hubicka <[email protected]>
> 
> gcc/ChangeLog:
> 
>       * ipa-fnsummary.cc (eliminated_by_inlining_prob): Do not credit
>       volatile accesses.  Compute once whether the statement writes to
>       the return value.  Credit aggregate copies into the return value
>       from automatic local variables and parameters whose address is not
>       taken as eliminated by inlining.
> 
> gcc/testsuite/ChangeLog:
> 
>       * g++.dg/ipa/inline-aggregate-retval.C: New test.
>       * g++.dg/ipa/inline-aggregate-retval-2.C: Likewise.
>       * gcc.dg/ipa/inline-aggregate-retval.c: Likewise.
>       * gcc.dg/ipa/inline-aggregate-retval-2.c: Likewise.
>       * gcc.dg/ipa/inline-aggregate-retval-3.c: Likewise.

OK,
thanks!
Honza

Reply via email to