Moving out https://gcc.gnu.org/PR98499#c9 to a separate enhancement PR: Right now analyze_ssa_name_flags() does not perform detailed modref analysis of return slot optimization and falls back to conservative assumption: analyze_ssa_name_flags() /* Return slot optiomization would require bit of propagation; give up for now. */ if (gimple_call_return_slot_opt_p (call) && gimple_call_lhs (call) != NULL_TREE && TREE_ADDRESSABLE (TREE_TYPE (gimple_call_lhs (call)))) { if (dump_file) fprintf (dump_file, "%*s Unhandled return slot opt\n", depth * 4, ""); lattice[index].merge (0); } I don't know what would be a good test for it. If I don't overstimate modref and alias analysis destructor should disappear completely in the example below (from https://gcc.gnu.org/PR98499#c4): struct string { char * _M_buf; // local store char _M_local_buf[16]; __attribute__((noinline)) string() : _M_buf(_M_local_buf) {} ~string() { if (_M_buf != _M_local_buf) __builtin_trap(); } string(const string &__str); // no copies }; // main.cc __attribute__((noinline)) static string dir_name() { return string(); } class Importer { string base_path; public: __attribute__((noinline)) Importer() : base_path (dir_name()) {} }; int main() { Importer imp; }
> If I don't overstimate modref and alias analysis destructor should disappear > completely in the example below (from https://gcc.gnu.org/PR98499#c4): > > struct string { > char * _M_buf; > // local store > char _M_local_buf[16]; > > __attribute__((noinline)) string() : _M_buf(_M_local_buf) {} > > ~string() { > if (_M_buf != _M_local_buf) > __builtin_trap(); > } > > string(const string &__str); // no copies > }; To see that _M_buf == _M_local_buf at the destruction time would require tracking the aggregate alue from the inlinined constructor to destructor which is something fitting to ipa-prop. Modref can helip in case _M_buf is initialized to NULL. In that case the address of return value would be non-escaping and we could optimize the if condition to true (is we did incorrectly before). I have WIP patch for this and will discuss with Martin Jambor the jump functions for return values. Thanks! Honza
Modref now handles return slots. However as discussed in earlier comment we also need return function in ipa-prop to propagate constant from callee to caller. So I am keeping the PR to track this (I think it would be useful especially for offlined ctors)
Return value range propagation was added in r:53ba8d669550d3a1f809048428b97ca607f95cf5 however it works on scalar return values only for now. Extending it to aggregates is a logical next step and should not be terribly hard. The code also misses logic for IPA streaming so it works only in ealry and late opts.