]> sourceware.org Git - glibc.git/commitdiff
malloc: Ensure mtag code path in checked_request2size is cold
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Mon, 15 Mar 2021 11:44:32 +0000 (11:44 +0000)
committerSzabolcs Nagy <szabolcs.nagy@arm.com>
Fri, 26 Mar 2021 11:03:06 +0000 (11:03 +0000)
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>
malloc/malloc.c

index 7c44b4f96d459eb575c74f10101ec806a5a5a79d..6640385282ec418c867b2747fa9b9a75a7d91c8e 100644 (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
      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;
This page took 0.044977 seconds and 5 git commands to generate.