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

Jay Foad jay.foad at gmail.com
Thu Feb 23 01:27:42 PST 2012


> $ cat ur.c
> unsigned unaligned_read(const void *p) {
>   unsigned x;
>   memcpy(&x, p, sizeof(x));
>   return x;
> }
>
> $ clang -w -O ur.c -S -emit-llvm -o-
> define i32 @unaligned_read(i8* nocapture %p) nounwind uwtable readonly ssp {
> entry:
>   %0 = bitcast i8* %p to i32*
>   %srcval = load i32* %0, align 1
>   ret i32 %srcval
> }

If I change your function so it takes an int*:

  unsigned unaligned_read(const int *p) { ... }

then I still get the same unaligned load:

  %srcval = load i32* %p, align 1

Can't the compiler assume that p is correctly aligned for an int? How
can I tell the compiler that I know that p *is* correctly aligned?

Thanks,
Jay.




More information about the llvm-commits mailing list