[Bug tree-optimization/82991] memcpy and strcpy return value can be assumed to be equal to first argument

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Nov 14 17:16:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82991

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC tracks that fact, see gimple_call_return_flags ERF_RETURNS_ARG and
ERF_RETURN_ARG_MASK to say which argument it is.
>From what I can see, it is used during aliasing and vrp (in the latter case
only whether it is non-NULL or not).  So it is just a matter of using it in
further optimizations.  But it needs to be used with care.
Trying to optimize:
  return strcpy (x, y);
as
  strcpy (x, y);
  return x;
is not a good idea, it would make it not tail-call optimizable, and in many
cases even for RA purposes it is cheaper to read the value from the return
register rather than saving it in call saved register and restoring from there,
etc. Which is why it is not that strightforward to say do it in SCCVN.


More information about the Gcc-bugs mailing list