[PATCH] D45571: [ELF] - Speedup MergeInputSection::splitStrings

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 27 06:25:37 PDT 2018


grimar added inline comments.


================
Comment at: ELF/InputSection.cpp:877
+  // calculate the string hash here.
+  while (reinterpret_cast<uintptr_t>(Data) & (sizeof(uint32_t) - 1)) {
+    if (!DataSize-- || !*Data)
----------------
espindola wrote:
> I think I just realized a problem with this.  If you have a string that is more than 4 bytes long, its hash value depends on its address, no? For example, if the string foobarzed starts at a position 4 byte aligned, we will hash it as
> 
> foob arzed \0
> 
> but if it is offset by one byte, it will be hashed as
> 
> f ooba zed\0
> 
> You can probably just delete the initial alignment loop. This will produce slow code on cpus that don't support fast unaligned loads, but we are already very slow in those cases.
> 
Oh, nice catch!

I removed the loop and what is interesting, it sped up the timings for me even more!
Time went from ~3968 to ~3704 (total LLD CPU time). And from ~443 to ~415 for `splitStrings`.
Seems it means it probably produces better hash with that change. I'll update the patch.


https://reviews.llvm.org/D45571





More information about the llvm-commits mailing list