GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++ Performance Win

libstdc++: Use always_inline for <atomic> memory_order parameters

Adds always_inline to std::atomic functions to ensure memory_order is a compile-time constant, improving optimization.

std::atomic member functions in might not be inlined at -Os, causing the std::memory_order parameter to become a runtime argument and forcing fallbacks to seq_cst operations. This change adds the always_inline attribute to these functions. This ensures that a compile-time constant memory order is propagated to the atomic builtins, potentially enabling more efficient implementations than the default seq_cst.

In Details

This change affects the inlining of std::atomic operations within libstdc++. By marking functions like load, store, and exchange with always_inline, the compiler is encouraged to inline them even at optimization levels like -Os. This is crucial for propagating std::memory_order values, which are often compile-time constants, to the underlying atomic builtins. Without inlining, the memory_order might be promoted to a runtime value, preventing the selection of optimal hardware instructions and potentially degrading to seq_cst semantics.

Filed Under: libstdc++optimizationatomic