[cfe-dev] Unaligned loads

Damien Vincent damien.llvm at gmail.com
Wed Mar 30 12:10:10 PDT 2011


I generated the llvm code for the following simple function (based on
clang/llvm 2.8) using:
clang -S -O2 -emit-llvm memory_unalignedint.c

int f(char *ptr)
{
  int r = *((int*)(ptr+2));
  return r;
}

And I was wondering why the alignment for the load is set to 4 although the
load is not aligned ? (%tmp1 = load i32* %0, align 4)
Thank you,

Damien


target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu"

define i32 @f(i8* nocapture %ptr) nounwind readonly {
entry:
  %add.ptr = getelementptr inbounds i8* %ptr, i64 2
  %0 = bitcast i8* %add.ptr to i32*
  %tmp1 = load i32* %0, align 4
  ret i32 %tmp1
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110330/e81eb9d1/attachment.html>


More information about the cfe-dev mailing list