http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55945



             Bug #: 55945

           Summary: alloca aligns aligned pointers

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: target

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: nel...@seznam.cz





Alloca returns 16 byte aligned pointers on x64. However it does unnecessary

instructions.

Consider following example.



int foo(){

  char *a=alloca(64),*b=alloca(64),*c=alloca(64);

  bar(a,b,c);

}



Resulting assembly does not use that rsp is already 16 byte aligned nor that 

intermediate results are 16 byte aligned. 





  pushq %rbp

  xorl  %eax, %eax

  movq  %rsp, %rbp

  subq  $80, %rsp

  leaq  15(%rsp), %rdi

  subq  $80, %rsp

  leaq  15(%rsp), %rsi

  subq  $80, %rsp

  leaq  15(%rsp), %rdx

  andq  $-16, %rdi

  andq  $-16, %rsi

  andq  $-16, %rdx

  call  bar

  leave





Moreover it is suboptimal for stacks growing down as 



subq cnt,  %rsp

andq $-16, %rsp



is more effective way.

Reply via email to