malloc: Ensure mtag code path in checked_request2size is cold

This is a workaround (hack) for a gcc optimization issue (PR 99551).
Without this the generated code may evaluate the expression in the
cold path which causes performance regression for small allocations
in the memory tagging disabled (common) case.
This commit is contained in:
Szabolcs Nagy 2021-03-15 11:44:32 +00:00
parent 7203bf2d0d
commit 57b9625334

View File

@ -1357,8 +1357,13 @@ checked_request2size (size_t req, size_t *sz) __nonnull (1)
must be a macro that produces a compile time constant if passed must be a macro that produces a compile time constant if passed
a constant literal. */ a constant literal. */
if (__glibc_unlikely (mtag_enabled)) if (__glibc_unlikely (mtag_enabled))
req = (req + (__MTAG_GRANULE_SIZE - 1)) & {
~(size_t)(__MTAG_GRANULE_SIZE - 1); /* Ensure this is not evaluated if !mtag_enabled, see gcc PR 99551. */
asm ("");
req = (req + (__MTAG_GRANULE_SIZE - 1)) &
~(size_t)(__MTAG_GRANULE_SIZE - 1);
}
*sz = request2size (req); *sz = request2size (req);
return true; return true;