[compiler-rt] e4fa0b3 - scudo: Obtain tag from pointer instead of loading it from memory. NFCI.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 21 21:47:59 PDT 2021


Author: Peter Collingbourne
Date: 2021-04-21T21:47:49-07:00
New Revision: e4fa0b307f7fe2c3db7442c719f643287f08eed4

URL: https://github.com/llvm/llvm-project/commit/e4fa0b307f7fe2c3db7442c719f643287f08eed4
DIFF: https://github.com/llvm/llvm-project/commit/e4fa0b307f7fe2c3db7442c719f643287f08eed4.diff

LOG: scudo: Obtain tag from pointer instead of loading it from memory. NFCI.

Since we already have a tagged pointer available to us, we can just
extract the tag from it and avoid an LDG instruction.

Differential Revision: https://reviews.llvm.org/D101014

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/combined.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index e778181685ea..e621c87da87a 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -518,6 +518,7 @@ class Allocator {
     if (UNLIKELY(!isAligned(reinterpret_cast<uptr>(Ptr), MinAlignment)))
       reportMisalignedPointer(AllocatorAction::Deallocating, Ptr);
 
+    void *TaggedPtr = Ptr;
     Ptr = getHeaderTaggedPointer(Ptr);
 
     Chunk::UnpackedHeader Header;
@@ -543,7 +544,7 @@ class Allocator {
         reportDeleteSizeMismatch(Ptr, DeleteSize, Size);
     }
 
-    quarantineOrDeallocateChunk(Options, Ptr, &Header, Size);
+    quarantineOrDeallocateChunk(Options, TaggedPtr, &Header, Size);
   }
 
   void *reallocate(void *OldPtr, uptr NewSize, uptr Alignment = MinAlignment) {
@@ -639,7 +640,7 @@ class Allocator {
     void *NewPtr = allocate(NewSize, Chunk::Origin::Malloc, Alignment);
     if (LIKELY(NewPtr)) {
       memcpy(NewPtr, OldTaggedPtr, Min(NewSize, OldSize));
-      quarantineOrDeallocateChunk(Options, OldPtr, &OldHeader, OldSize);
+      quarantineOrDeallocateChunk(Options, OldTaggedPtr, &OldHeader, OldSize);
     }
     return NewPtr;
   }
@@ -1031,13 +1032,13 @@ class Allocator {
            reinterpret_cast<uptr>(Ptr) - SizeOrUnusedBytes;
   }
 
-  void quarantineOrDeallocateChunk(Options Options, void *Ptr,
+  void quarantineOrDeallocateChunk(Options Options, void *TaggedPtr,
                                    Chunk::UnpackedHeader *Header, uptr Size) {
+    void *Ptr = getHeaderTaggedPointer(TaggedPtr);
     Chunk::UnpackedHeader NewHeader = *Header;
     if (UNLIKELY(useMemoryTagging<Params>(Options))) {
-      u8 PrevTag = 0;
+      u8 PrevTag = extractTag(reinterpret_cast<uptr>(TaggedPtr));
       if (NewHeader.ClassId) {
-        PrevTag = extractTag(loadTag(reinterpret_cast<uptr>(Ptr)));
         if (!TSDRegistry.getDisableMemInit()) {
           uptr TaggedBegin, TaggedEnd;
           const uptr OddEvenMask = computeOddEvenMaskForPointerMaybe(


        


More information about the llvm-commits mailing list