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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-10-28
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  This is partial dead code elimination which we do not perform.
You can think of partial dead code elimination as sinking & duplicating code
to N places where dataflow determines that in M < N places the sunk code
is dead (it's usually done for stores, but calls work as well of course).
For malloc/free pairs it actually requires eliding the whole pair while
classically for stores only the sunk store is.  Thus

int g;
void f (int i)
{
  g = 1;
  if (i)
    g = 2;
}

becomes

int g;
void f (int i)
{
  if (i)
    g = 2;
  else
    g = 1;
}

in your case you'd sink the malloc and elide the malloc/free pair.
It might be tempting to implement this in two-steps and only do the
sinking, relying on followup DCE/DSE but that will likely run into
cases where we just ended up duplicating code.

Reply via email to