https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127005
Drea Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2026-08-22
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Keywords| |missed-optimization
--- Comment #1 from Drea Pinski <pinskia at gcc dot gnu.org> ---
So libstdc++ optional has this:
constexpr void
_M_destroy() noexcept
{
_M_engaged = false;
_M_payload._M_value.~_Stored_type();
I wonder if we should set engaged before and after the call to ~_Stored_type.
That would allow to optimize away the check like this:
```
c._M_engaged = 0;
_13 = MEM[(struct lock_guard *)&c]._M_device;
_14 = &MEM[(struct mutex *)_13].D.31492._M_mutex;
pthread_mutex_unlock (_14);
MEM[(struct lock_guard *)&c] ={v} {CLOBBER(eob)};
_5 = MEM[(struct _Optional_payload_base *)&c]._M_engaged;
if (_5 != 0)
```
I might take a look into this next week.