LoadInst::getAlignment

I’m just diving into LLVM. What does it mean when LoadInst::getAlignment() returns 0? Unknown alignment, use default alignment of the type for the load, something else?

In particular, clang appears to set to 0 the alignment of the load instruction that results from accessing the lvalue returned by a call. Is this the intended behavior?

For example:

const double &foo(void *p);

double ans;

void bar()

{

ans = foo(0);

}

Produces:

target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3

2:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:64-n32-S64"

target triple = “armv4t—eabi”

@ans = global double 0.000000e+00, align 8

define void @_Z3barv() {

entry:

%call = call double* @_Z3fooPv(i8* null)

%0 = load double* %call

store double %0, double* @ans, align 8

ret void

}

declare double* @_Z3fooPv(i8*)

Notice that the load does not have an alignment specification.

Thanks for your help,

Jon

Hi Jonathan,

I’m just diving into LLVM. What does it mean when LoadInst::getAlignment()
returns 0? Unknown alignment, use default alignment of the type for the load,
something else?

from the LangRef (load instruction):

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.

Ciao, Duncan.