This is the mail archive of the gcc-patches@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]

Re: [PATCH] Fix PR 16660, attribute((aligned)) doesn't work for variables on the stack for greater than required alignment


Trevor Smigiel/R&D/SCEA@Playstation wrote on 05/17/2007 04:49:53 PM:

> Andrew,
> 
> It seems you missed merging a change that I made in our local tree.
> 
> In cfgexpand.c, you removed this code:
> 
> -  /* Set alignment we actually gave this decl.  */
> -  offset -= frame_phase;
> -  align = offset & -offset;
> -  align *= BITS_PER_UNIT;
> -  if (align > STACK_BOUNDARY || align == 0)
> -    align = STACK_BOUNDARY;
> -  DECL_ALIGN (decl) = align;
> -  DECL_USER_ALIGN (decl) = 0;
> 
> In our local tree that code is conditioned on 
>   if (!DECL_USER_ALIGN (decl))
> (Which could be done more precisely.  Consider the case where a user
> specified alignment is smaller than the decl's actual alignment on the
> stack.)
> 
> Without it less efficient code can be generated because higher
> alignments are not propagated.  At least, that's the behaviour on 4.1.1.

Here is a testcase which shows that even checking for DECL_USER_ALIGN is 
wrong, we need to check for align < STACK_BOUNDARY also.  Before my patch, 
we would get the mem for accessing i with an alignment of 32 bits but 
after this patch, we get an alignment of 8.  I will fix this testcase now 
too.

Thanks,
Andrew Pinski


/* { dg-do compile } */
/* { dg-options "-O2 -fdump-rtl-expand" } */
int g(int *);
int f(void)
{
  int i __attribute__((aligned(1) ));
  int *a = &i;
  g(a);
  return *a;
}
/* Even though the user supplied an alignment of 1, the memory
   location for i should have the natural alignment of int.   */

/* { dg-final { scan-rtl-dump-not "A8" "expand" } } */
/* { dg-final { scan-rtl-dump "A32" "expand" } } */
/* { dg-final { cleanup-rtl-dump "expand" } } */


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