https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121921
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |117924 See Also|https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=117924 | --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Longer example: ``` static inline char *a(char *b, char *e) { return e - (e - b); } void f(short s, char *t) { char *b = new char[s]; char *e = b+s; if (s == 0) ; else if (s == 1) b[0] = t[0]; else __builtin_memcpy(b,t, s); char *b1 = a(b,e); delete []b1; } ``` With -O2, we can optimize away the whole f function but that is only because of forwprop. if we disable forwprop we can't due to this optimization missing. Looking into PR 117924 further, 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. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117924 [Bug 117924] unused std::vector<bool> are not optimized out fully at gimple level