-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Simplify hot-path size computations in BumpPtrAllocator. #101467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reapply #101312 with a fix for Asan builds. |
@llvm/pr-subscribers-llvm-support Author: Owen Anderson (resistor) Changes~0.1% instruction count improvements Full diff: https://github.com/llvm/llvm-project/pull/101467.diff 1 Files Affected:
diff --git a/llvm/include/llvm/Support/Allocator.h b/llvm/include/llvm/Support/Allocator.h
index e05f0ec0e8704..568f0d34032fa 100644
--- a/llvm/include/llvm/Support/Allocator.h
+++ b/llvm/include/llvm/Support/Allocator.h
@@ -149,8 +149,7 @@ class BumpPtrAllocatorImpl
// Keep track of how many bytes we've allocated.
BytesAllocated += Size;
- size_t Adjustment = offsetToAlignedAddr(CurPtr, Alignment);
- assert(Adjustment + Size >= Size && "Adjustment + Size must not overflow");
+ uintptr_t AlignedPtr = alignAddr(CurPtr, Alignment);
size_t SizeToAllocate = Size;
#if LLVM_ADDRESS_SANITIZER_BUILD
@@ -158,19 +157,22 @@ class BumpPtrAllocatorImpl
SizeToAllocate += RedZoneSize;
#endif
+ uintptr_t AllocEndPtr = AlignedPtr + SizeToAllocate;
+ assert(AllocEndPtr >= uintptr_t(CurPtr) &&
+ "Alignment + Size must not overflow");
+
// Check if we have enough space.
- if (LLVM_LIKELY(Adjustment + SizeToAllocate <= size_t(End - CurPtr)
+ if (LLVM_LIKELY(AllocEndPtr <= uintptr_t(End)
// We can't return nullptr even for a zero-sized allocation!
&& CurPtr != nullptr)) {
- char *AlignedPtr = CurPtr + Adjustment;
- CurPtr = AlignedPtr + SizeToAllocate;
+ CurPtr = reinterpret_cast<char *>(AllocEndPtr);
// Update the allocation point of this memory block in MemorySanitizer.
// Without this, MemorySanitizer messages for values originated from here
// will point to the allocation of the entire slab.
- __msan_allocated_memory(AlignedPtr, Size);
+ __msan_allocated_memory(reinterpret_cast<char *>(AlignedPtr), Size);
// Similarly, tell ASan about this space.
- __asan_unpoison_memory_region(AlignedPtr, Size);
- return AlignedPtr;
+ __asan_unpoison_memory_region(reinterpret_cast<char *>(AlignedPtr), Size);
+ return reinterpret_cast<char *>(AlignedPtr);
}
return AllocateSlow(Size, SizeToAllocate, Alignment);
|
nikic
reviewed
Aug 1, 2024
nikic
reviewed
Aug 1, 2024
nikic
approved these changes
Aug 1, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
~0.1% instruction count improvements
https://llvm-compile-time-tracker.com/compare.php?from=07d2709a17860a202d91781769a88837e4fb5f2a&to=d5cc47831ecd9f0a2b164b16da67f74b94e9aafc&stat=instructions:u