[llvm-commits] [PATCH] RFC: fix some problems in GeneralHash

Jay Foad jay.foad at gmail.com
Wed Feb 22 04:15:10 PST 2012


What do you think of the attached patch? It:

1. Fixes the theoretical problem with GeneralHash::addUnaligned
returning varying results on big-endian hosts.
2. Fixes the strict aliasing problems that foiled my attempt to apply
Meador's patch to improve uniquing of struct and function types.
3. Moves GeneralHash::finish and GeneralHash::mix out of line. This is
just a matter of taste, but the inlined code looked a bit long-winded
to me.

It also simplifies and combines addAligned and addUnaligned into a
single inline function addBytes that covers all cases, and relies on
the compiler to optimise away the calls to memcpy. This mostly seems
to work, except that GCC doesn't seem to be clever enough to optimise
away the whole of:

    if (I != E) {
      Data = 0;
      std::memcpy(&Data, I, E - I);
      mix(Data);
    }

... when addBits is called with a type which is known to be at least
4-aligned. Can I change the code a bit to help the compiler out?

Tested with "make check-all", llvm + clang, on a Release+Asserts build
built with GCC 4.4.6-11ubuntu2 on Ubuntu 11.10 x86_64.

Thanks,
Jay.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hashing.patch
Type: text/x-patch
Size: 3953 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120222/777fde3c/attachment.bin>


More information about the llvm-commits mailing list