https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122727
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I wonder if this small change will improve things:
```
[apinski@xeond2 bits]$ git diff basic_string.h
diff --git a/libstdc++-v3/include/bits/basic_string.h
b/libstdc++-v3/include/bits/basic_string.h
index 8ae6569f501..c4b6b1064a9 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -269,8 +269,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
void
_M_set_length(size_type __n)
{
- _M_length(__n);
traits_type::assign(_M_data()[__n], _CharT());
+ _M_length(__n);
}
_GLIBCXX20_CONSTEXPR
```
That is switch around the order of the store of the null character and the
store the length.
This might allow more loads not to happen as much as the store to the data
happens before hand and the next load of the length will be the same as the
store.