[llvm] f6cce56 - [Support] Change StringMap hash function from xxHash64 to xxh3_64bits

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 22 16:50:51 PDT 2023


Author: Fangrui Song
Date: 2023-07-22T16:50:47-07:00
New Revision: f6cce566b3d06de70efb9271ea9253b1d5845920

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

LOG: [Support] Change StringMap hash function from xxHash64 to xxh3_64bits

Similar to D142862.

xxh3 is significantly faster than xxh64. Switch to xxh3, as we did for
for lld and llvm-dwarfutil to increase performance (D154813 D155675).
While I think StringMap is not a bottleneck for most applications, it
seems good to eliminate the slower xxh64.
In addition, according to Erik Desjardins, an artificial benchmark of
Rust with very large constant strings improves by ~3% locally.

I have fixed all found issues (~20) separately, but one is remaining:

* ExecutionEngine/RuntimeDyld/ARM/MachO_ARM_PIC_relocations.s has a
  failure due to StringMap iteration order. It now passes
  with LLVM_ENABLE_REVERSE_ITERATION=on while failing with
  LLVM_ENABLE_REVERSE_ITERATION=off.

Reviewed By: erikdesjardins

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

Added: 
    

Modified: 
    llvm/lib/Support/StringMap.cpp
    llvm/test/ExecutionEngine/RuntimeDyld/ARM/MachO_ARM_PIC_relocations.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/StringMap.cpp b/llvm/lib/Support/StringMap.cpp
index 82c6e755284f15..67c05a87959cf0 100644
--- a/llvm/lib/Support/StringMap.cpp
+++ b/llvm/lib/Support/StringMap.cpp
@@ -85,7 +85,7 @@ unsigned StringMapImpl::LookupBucketFor(StringRef Name) {
   // Hash table unallocated so far?
   if (NumBuckets == 0)
     init(16);
-  unsigned FullHashValue = xxHash64(Name);
+  unsigned FullHashValue = xxh3_64bits(Name);
   if (shouldReverseIterate())
     FullHashValue = ~FullHashValue;
   unsigned BucketNo = FullHashValue & (NumBuckets - 1);
@@ -142,7 +142,7 @@ unsigned StringMapImpl::LookupBucketFor(StringRef Name) {
 int StringMapImpl::FindKey(StringRef Key) const {
   if (NumBuckets == 0)
     return -1; // Really empty table?
-  unsigned FullHashValue = xxHash64(Key);
+  unsigned FullHashValue = xxh3_64bits(Key);
   if (shouldReverseIterate())
     FullHashValue = ~FullHashValue;
   unsigned BucketNo = FullHashValue & (NumBuckets - 1);

diff  --git a/llvm/test/ExecutionEngine/RuntimeDyld/ARM/MachO_ARM_PIC_relocations.s b/llvm/test/ExecutionEngine/RuntimeDyld/ARM/MachO_ARM_PIC_relocations.s
index 495c8aed23d27b..2be84d06f4d4c6 100644
--- a/llvm/test/ExecutionEngine/RuntimeDyld/ARM/MachO_ARM_PIC_relocations.s
+++ b/llvm/test/ExecutionEngine/RuntimeDyld/ARM/MachO_ARM_PIC_relocations.s
@@ -1,4 +1,4 @@
-# UNSUPPORTED: reverse_iteration
+# REQUIRES: reverse_iteration
 # RUN: rm -rf %t && mkdir -p %t
 # RUN: llvm-mc -triple=armv7s-apple-ios7.0.0 -filetype=obj -o %t/foo.o %s
 # RUN: llvm-rtdyld -triple=armv7s-apple-ios7.0.0 -verify -check=%s %t/foo.o


        


More information about the llvm-commits mailing list