From 95ed3a5570f1e2160c365337d21609c7f5ede807 Mon Sep 17 00:00:00 2001 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> Date: Sun, 7 Jul 2024 19:57:06 +0900 Subject: [PATCH] compiler-rt: Optimize IsSameObject() Now that we use multi-level shadow scheme, IsSameObject() doesn't need to call GetBlockBegin() which is dozens of times slower. Just check if the two metadata from the pointers are the same. This improves the slowdowns in SPEC CPU2017 502.gcc_r from 350x to 7x. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- compiler-rt/lib/plsan/plsan_allocator.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/compiler-rt/lib/plsan/plsan_allocator.cpp b/compiler-rt/lib/plsan/plsan_allocator.cpp index 576c3e0c1..b94152a73 100644 --- a/compiler-rt/lib/plsan/plsan_allocator.cpp +++ b/compiler-rt/lib/plsan/plsan_allocator.cpp @@ -60,22 +60,7 @@ bool IsSameObject(Metadata *metadata, const void *x, const void *y) { if (!metadata || !y) return false; - if (x == y) - return true; - - uptr size = metadata->GetRequestedSize(); - if (size <= (1 << 15)) { - // size is always power of two if allocated from the primary - uptr a = reinterpret_cast(x) & ~(size - 1); - uptr b = reinterpret_cast(y) & ~(size - 1); - return a == b; - } - - void *begin = allocator.GetBlockBegin(x); - if (!begin) - return false; - - return begin <= y && (uptr)y < (uptr)begin + metadata->GetRequestedSize(); + return (GetMetadata(y) == x); } u8 GetRefCount(Metadata *metadata) { return metadata->GetRefCount(); }