[PATCH 6/6] malloc: Ensure mtag code path in checked_request2size is cold
DJ Delorie
dj@redhat.com
Tue Mar 23 20:46:24 GMT 2021
Szabolcs Nagy <szabolcs.nagy@arm.com> writes:
> 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.
> 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);
> + }
Hack indeed, but cross-target-safe and shouldn't affect the unused code
removal on non-aarch64 targets.
LGTM.
Reviewed-by: DJ Delorie <dj@redhat.com>
More information about the Libc-alpha
mailing list