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

Chris Lattner clattner at apple.com
Sat Feb 25 20:07:42 PST 2012


On Feb 25, 2012, at 12:06 AM, Jay Foad wrote:

> 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).

I'm pretty sure (but not certain) that the compiler has to treat the input to memcpy as unaligned, regardless of its type.

-Chris



More information about the llvm-commits mailing list