Bug 55945 - alloca aligns aligned pointers
Summary: alloca aligns aligned pointers
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2013-01-11 19:51 UTC by Ondrej Bilka
Modified: 2013-01-15 02:46 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-01-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ondrej Bilka 2013-01-11 19:51:38 UTC
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.
Comment 1 Richard Biener 2013-01-14 13:23:00 UTC
Confirmed.