[PATCH] [Codegen] Ensure stack is properly aligned for call argument initialization

Jeroen Ketema via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 24 04:14:34 PDT 2015


Bump.

Jeroen

On 11/08/15 10:58, Jeroen Ketema wrote:
> Ping.
>
> Jeroen
>
> On 05/08/2015 11:07, Jeroen Ketema wrote:
>> Arguments spilled on the stack before a function call may have
>> alignment requirements, for example in the case of vectors.
>> These requirements are exploited by the code generator by using
>> move instructions that have similar alignment requirements, e.g.,
>> movaps on x86.
>>
>> Although the code generator properly aligns the arguments with
>> respect to the displacement of the stack pointer it computes,
>> the displacement itself may cause misalignment. For example if
>> we have
>>
>>   %3 = load <16 x float>, <16 x float>* %1, align 64
>>   call void @bar(<16 x float> %3, i32 0)
>>
>> The x86 back-end emits:
>>
>>   movaps  32(%ecx), %xmm2
>>   movaps  (%ecx), %xmm0
>>   movaps  16(%ecx), %xmm1
>>   movaps  48(%ecx), %xmm3
>>   subl    $20, %esp       <-- if %esp was 16-byte aligned before this
>>                               instruction, it no longer will be 
>> afterwards
>>   movaps  %xmm3, (%esp)   <-- movaps requires 16-byte alignment, 
>> while %esp
>>                               is not aligned as such.
>>   movl    $0, 16(%esp)
>>   calll   __bar
>>
>> To solve this, we need to make sure that the computed value with which
>> the stack pointer is changed is a multiple af the maximal alignment seen
>> during its computation. With this change we get proper alignment:
>>
>>   subl    $32, %esp
>>   movaps  %xmm3, (%esp)
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: stack.patch
Type: text/x-patch
Size: 3638 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150824/c6b8d54b/attachment.bin>


More information about the llvm-commits mailing list