This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/55945] New: alloca aligns aligned pointers


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: unassigned@gcc.gnu.org
        ReportedBy: neleai@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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]