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

Jay Foad jay.foad at gmail.com
Sat Feb 25 00:06:35 PST 2012


On 25 February 2012 00:36, Chris Lattner <clattner at apple.com> wrote:
>
> On Feb 24, 2012, at 1:36 AM, Jay Foad wrote:
>
>> The attached patch lets the compiler remove the part of
>> GeneralHash::addBytes which hashes the final 1 to 3 bytes, if it is
>> known that we're hashing an array of T where sizeof (T) is a multiple
>> of 4.
>
> Looks good to me.

Thanks. There's a subtle point here that I'm unsure about. Given:

  int f(int *p) {
    int i;
    memcpy(&i, p, sizeof i);
    return i;
  }

can the compiler assume that p is 4-aligned, because of its type? Or
is it legal to take an arbitrary char*, cast it to int*, and pass it
into this function?

If the latter, how can I tell the compiler that I know p really is
aligned, so that codegen can turn the memcpy into an *aligned* load
(on targets where it makes a difference).

Thanks!
Jay.



More information about the llvm-commits mailing list