criswell at uiuc.edu
Fri Jul 16 07:40:51 PDT 2010
Anton Korobeynikov wrote:
>> In the insrtuction
>> %1 = load i32** %y_addr, align 4
>> what is the meaning of align 4??
>> Can anyone explain?
> >From http://llvm.org/docs/LangRef.html#i_load :
> "The optional constant align argument specifies the alignment of the
> operation (that is, the alignment of the memory address). A value of 0
> or an omitted align argument means that the operation has the
> preferential alignment for the target. It is the responsibility of the
> code emitter to ensure that the alignment information is correct.
> Overestimating the alignment results in undefined behavior.
> Underestimating the alignment may produce less efficient code. An
> alignment of 1 is always safe."
After reading the description, I am left wondering why LLVM has this
feature and for what it is intended to be used.
My best guess is that it allows LLVM to generate code for unaligned
data. For example, on a machine that only supports loads of 32-bit
values at 4-byte alignment, an LLVM load instruction with an alignment
of 1 tells the code generator to insert byte loads and shifting
operations to mimic a load from a non-4-byte-aligned memory address.
Is my guess correct, or does this alignment feature fulfill other needs?
-- John T.
More information about the llvm-dev