about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSzabolcs Nagy <szabolcs.nagy@arm.com>2021-03-15 11:44:32 +0000
committerSzabolcs Nagy <szabolcs.nagy@arm.com>2021-03-19 11:49:13 +0000
commit57b96253346fe679c82b7f88e2398ec21553b52c (patch)
tree917222986f0a4a3b189ac6f6679825ad00395824
parent7203bf2d0d1405daa5d1c62744abf8ceee85b5bb (diff)
downloadglibc-nsz/mtag-2.tar.gz
glibc-nsz/mtag-2.tar.xz
glibc-nsz/mtag-2.zip
malloc: Ensure mtag code path in checked_request2size is cold nsz/mtag-2
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.
-rw-r--r--malloc/malloc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c
index cb1837d0d7..ef1f5b1621 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;