diff options
author | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2021-03-15 11:44:32 +0000 |
---|---|---|
committer | Szabolcs Nagy <szabolcs.nagy@arm.com> | 2021-03-26 11:03:06 +0000 |
commit | 850dbf24ee04c1e462640b87dbe1c6044fbe65e2 (patch) | |
tree | 404dddbadcfa97a4c01aaf54406235bd7a8298a6 /malloc/malloc.c | |
parent | 05f878c58e53370a76c2b82679899936bc69c714 (diff) | |
download | glibc-850dbf24ee04c1e462640b87dbe1c6044fbe65e2.zip glibc-850dbf24ee04c1e462640b87dbe1c6044fbe65e2.tar.gz glibc-850dbf24ee04c1e462640b87dbe1c6044fbe65e2.tar.bz2 |
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.
Reviewed-by: DJ Delorie <dj@redhat.com>
Diffstat (limited to 'malloc/malloc.c')
-rw-r--r-- | malloc/malloc.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c index 7c44b4f..6640385 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -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 a constant literal. */ 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); return true; |