[LLVMdev] Alignment of vectors

Eli Friedman eli.friedman at gmail.com
Fri Jul 18 15:03:18 PDT 2008


On Fri, Jul 18, 2008 at 10:12 AM, Benedict Gaster
<benedict.gaster at amd.com> wrote:
>>> but what about
>>> if the following code had been generated:
>>>
>>> define void @foo() {
>>> entry:
>>>     %p = alloca float*, align 4        ; <float**> [#uses=1]
>>>     %offset = alloca i32, align 4        ; <i32*> [#uses=1]
>>>     %tmp = alloca <2 x float>, align 4        ; <<2 x float>*> [#uses=1]
>>>     %tmp1 = load float** %p        ; <float*> [#uses=1]
>>>     %tmp2 = load i32* %offset        ; <i32> [#uses=1]
>>>     %add.ptr = getelementptr float* %tmp1, i32 %tmp2        ; <float*>
>>> [#uses=1]
>>>     %conv = bitcast float* %add.ptr to <2 x float>*        ; <<2 x float>*>
>>> [#uses=1]
>>>     %tmp3 = load <2 x float>* %conv        ; <<2 x float>> [#uses=1]
>>>     store <2 x float> %tmp3, <2 x float>* %tmp
>>>     ret void
>>> }
>>
>> clang shouldn't be generating code like that.  Per the current gcc
>> documentation, the aligned attribute isn't allowed to decrease
>> alignment.  What would happen if the code subsequently passed a
>> pointer to the variable with the aligned attribute to another
>> function?
>>
>
> [bg] Sorry I did not mean to imply that Clang generated this code, it was
> written by hand. What I was trying to understand was: is if it is valid LLVM
> IL?

It has undefined behavior; all loads and stores must have an alignment
which is at most the alignment of the relevant pointer.

-Eli



More information about the llvm-dev mailing list