https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127495
Bug ID: 127495
Summary: push_back twice to a new std::vector still has two
operator new rather than one
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Blocks: 118130
Target Milestone: ---
Take:
```
#include <vector>
std::vector<int> f()
{
std::vector<int> a;
a.push_back(1);
a.push_back(1);
return a;
}
```
In optimized we have:
```
_46 = operator new (4);
*_46 = 1;
_71 = operator new (8);
MEM <unsigned long> [(void *)_71] = 4294967297;
__new_finish_61 = _71 + 8;
operator delete (_46, 4);
a_2(D)->D.34495._M_impl.D.33792._M_start = _71;
a_2(D)->D.34495._M_impl.D.33792._M_finish = __new_finish_61;
a_2(D)->D.34495._M_impl.D.33792._M_end_of_storage = __new_finish_61;
return a_2(D);
```
Notice the first operator new is dead/unused?
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118130
[Bug 118130] std::vector code quality issues