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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note there is another way of solving this. From my anylsis (which I wrote in PR
121921):
currently DSE5 can remove the stores:
```
  Deleted dead store: MEM[(struct __as_base  &)&data] ={v} {CLOBBER(bob)};

  Deleted dead store: MEM[(struct _Bvector_impl_data *)&data] ={v}
{CLOBBER(bob)};

```
But DCE7 (which is right afterwards) does not `remove operator new/delete`
because this missed optimization and then forwprop4 (which is right after dce7)
is able to see (b+s) - (b+s - b) is just b and then later on the next DCE
optimizes away the new/delete pair.

> Unused new/delete pair is only being determined at cddce3 which is bit late. 

The reason why it is not before hand is due to `e - (e - b)` not being
optimized to b until forwprop4 which is right after dce7. If `e - (e - b)` got
folded say fre1:
```
  _1 = this_15(D)->_M_impl.D.25104._M_start.D.16464._M_p;
...
  _20 = MEM[(const struct _Bvector_impl
*)this_15(D)].D.25104._M_end_of_storage;
  _5 = _20 - _1; // e - b
  _8 = (long unsigned int) _5;
  _9 = -_8;
  _10 = _20 + _9; // e - (e - b)
  _11 = &this_15(D)->_M_impl;
  operator delete (_10, _8);
```
We should recongize the operator new/delete pair earlier too.

Reply via email to