https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96945
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Component|c++ |tree-optimization Last reconfirmed| |2023-07-13 Status|UNCONFIRMED |NEW Summary|optimizations regression |unused std::vector is not |when defaulting copy |always optimized away |constructor | Ever confirmed|0 |1 Severity|normal |enhancement --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Confirmed. In the case of having a move constructor, there is a loop generated for the constructor (and since this is an empty struct, the loop is empty). In the case of not having a move constructo, we get: MEM <unsigned char[3]> [(char * {ref-all})_30] = MEM <unsigned char[3]> [(char * {ref-all})&D.26026]; In the end DSE does not remove that store even though it is dead right before the operator delete. _30 = operator new (3); MEM <unsigned char[3]> [(char * {ref-all})_30] = MEM <unsigned char[3]> [(char * {ref-all})&D.26026]; D.26026 ={v} {CLOBBER(eol)}; operator delete (_30, 3); [tail call] Also if we add an field and initialize it to 0, we get a memcpy: __builtin_memcpy (_40, &D.26033, 12); Which is also not DSEd: _40 = operator new (12); __builtin_memcpy (_40, &D.26033, 12); D.26033 ={v} {CLOBBER(eol)}; operator delete (_40, 12); [tail call] Maybe the clobber is getting in the way here ....