[LLVMdev] MCJIT generates MOVAPS on unaligned address

Frank Winter fwinter at jlab.org
Thu Aug 7 13:38:53 PDT 2014


Hang on.. I sent the wrong file. That one is already vectorized!

Frank


On 08/07/2014 04:36 PM, Frank Winter wrote:
> Makes sense. I overlooked the missing alignment tag in the IR.
>
> Attached the full test case.
>
> Frank
>
>
> On 08/07/2014 04:29 PM, Arnold Schwaighofer wrote:
>>> On Aug 7, 2014, at 12:42 PM, Frank Winter <fwinter at jlab.org> wrote:
>>>
>>> MCJIT when lowering to x86-64 generates a MOVAPS (Move Aligned 
>>> Packed Single-Precision Floating-Point Values) on a non-aligned 
>>> memory address:
>>>
>>>     movaps    88(%rdx), %xmm0
>>>
>>> where %rdx comes in as a function argument with only natural 
>>> alignment (float*). This x86 instruction requires the memory address 
>>> to be 16 byte aligned which 88 plus something aligned to 4 byte isn't.
>>>
>>> Here the according IR code which was produced from the SLP vectorizer:
>>>
>>> define void @func(float* noalias %arg0, float* noalias %arg1, float* 
>>> noalias %arg2) {
>>> entrypoint:
>>> ...
>>>   %104 = getelementptr float* %arg0, i32 22
>>> ...
>>>   %204 = bitcast float* %104 to <4 x float>*
>>>   store <4 x float> %198, <4 x float>* %204
>>>
>>> This in itself not wrong. However, shouldn't the lowering pass 
>>> recognize the wrong alignment?
>> The LLVM IR is wrong. Omitting the align directive on the store means 
>> abi alignment of the target. The backend is “right” wrt to LLVM IR 
>> semantics to produce the movaps.
>>
>> The error is in the  producer (looks like the SLP vectorizer) of said 
>> vector store. Could you provide a full test case where running the 
>> SLP vectorizer (opt -slp-vectorize < t.ll) produces such an output?
>>
>> The following code in the SLP vectorizer should have made sure that 
>> we created an alignment of “4 bytes” given a data layout 
>> (http://llvm.org/docs/LangRef.html#data-layout) that specifies 
>> f32:32:32.
>>
>>      case Instruction::Store: {
>>        StoreInst *SI = cast<StoreInst>(VL0);
>>        unsigned Alignment = SI->getAlignment();
>>        ...
>>        StoreInst *S = Builder.CreateStore(VecValue, VecPtr);
>>        if (!Alignment)
>>          Alignment = 
>> DL->getABITypeAlignment(SI->getPointerOperand()->getType()); // << 
>> Get the 4byte alignment for the scalar float store from the data 
>> layout string.
>>        S->setAlignment(Alignment);
>
>





More information about the llvm-dev mailing list