Commit 9bfaf89d by Jakub Jelinek Committed by Jakub Jelinek

re PR target/39137 (-mpreferred-stack-boundary=2 causes lots of dynamic realign)

	PR target/39137
	* cfgexpand.c (get_decl_align_unit): Use LOCAL_DECL_ALIGNMENT
	macro.
	* defaults.h (LOCAL_DECL_ALIGNMENT): Define if not yet defined.
	* config/i386/i386.h (LOCAL_DECL_ALIGNMENT): Define.
	* config/i386/i386.c (ix86_local_alignment): For
	-m32 -mpreferred-stack-boundary=2 use 32-bit alignment for
	long long variables on the stack to avoid dynamic realignment.
	Allow the first argument to be a decl rather than type.
	* doc/tm.texi (LOCAL_DECL_ALIGNMENT): Document.

	* gcc.target/i386/stackalign/longlong-1.c: New test.
	* gcc.target/i386/stackalign/longlong-2.c: New test.

From-SVN: r144792
parent 8a9ceef2
2009-03-11 Jakub Jelinek <jakub@redhat.com>
PR target/39137
* cfgexpand.c (get_decl_align_unit): Use LOCAL_DECL_ALIGNMENT
macro.
* defaults.h (LOCAL_DECL_ALIGNMENT): Define if not yet defined.
* config/i386/i386.h (LOCAL_DECL_ALIGNMENT): Define.
* config/i386/i386.c (ix86_local_alignment): For
-m32 -mpreferred-stack-boundary=2 use 32-bit alignment for
long long variables on the stack to avoid dynamic realignment.
Allow the first argument to be a decl rather than type.
* doc/tm.texi (LOCAL_DECL_ALIGNMENT): Document.
2009-03-11 Nick Clifton <nickc@redhat.com>
PR target/5362
......
......@@ -488,8 +488,7 @@ get_decl_align_unit (tree decl)
{
unsigned int align;
align = DECL_ALIGN (decl);
align = LOCAL_ALIGNMENT (TREE_TYPE (decl), align);
align = LOCAL_DECL_ALIGNMENT (decl);
if (align > MAX_SUPPORTED_STACK_ALIGNMENT)
align = MAX_SUPPORTED_STACK_ALIGNMENT;
......
......@@ -19347,15 +19347,39 @@ ix86_data_alignment (tree type, int align)
return align;
}
/* Compute the alignment for a local variable or a stack slot. TYPE is
the data type, MODE is the widest mode available and ALIGN is the
alignment that the object would ordinarily have. The value of this
macro is used instead of that alignment to align the object. */
/* Compute the alignment for a local variable or a stack slot. EXP is
the data type or decl itself, MODE is the widest mode available and
ALIGN is the alignment that the object would ordinarily have. The
value of this macro is used instead of that alignment to align the
object. */
unsigned int
ix86_local_alignment (tree type, enum machine_mode mode,
ix86_local_alignment (tree exp, enum machine_mode mode,
unsigned int align)
{
tree type, decl;
if (exp && DECL_P (exp))
{
type = TREE_TYPE (exp);
decl = exp;
}
else
{
type = exp;
decl = NULL;
}
/* Don't do dynamic stack realignment for long long objects with
-mpreferred-stack-boundary=2. */
if (!TARGET_64BIT
&& align == 64
&& ix86_preferred_stack_boundary < 64
&& (mode == DImode || (type && TYPE_MODE (type) == DImode))
&& (!type || !TYPE_USER_ALIGN (type))
&& (!decl || !DECL_USER_ALIGN (decl)))
align = 32;
/* If TYPE is NULL, we are allocating a stack slot for caller-save
register in MODE. We will return the largest alignment of XF
and DF. */
......
......@@ -791,6 +791,19 @@ enum target_cpu_default
#define STACK_SLOT_ALIGNMENT(TYPE, MODE, ALIGN) \
ix86_local_alignment ((TYPE), (MODE), (ALIGN))
/* If defined, a C expression to compute the alignment for a local
variable DECL.
If this macro is not defined, then
LOCAL_ALIGNMENT (TREE_TYPE (DECL), DECL_ALIGN (DECL)) will be used.
One use of this macro is to increase alignment of medium-size
data to make it all fit in fewer cache lines. */
#define LOCAL_DECL_ALIGNMENT(DECL) \
ix86_local_alignment ((DECL), VOIDmode, DECL_ALIGN (DECL))
/* If defined, a C expression that gives the alignment boundary, in
bits, of an argument with the specified mode and type. If it is
not defined, `PARM_BOUNDARY' is used for all arguments. */
......
......@@ -944,6 +944,11 @@ along with GCC; see the file COPYING3. If not see
((TYPE) ? LOCAL_ALIGNMENT ((TYPE), (ALIGN)) : (ALIGN))
#endif
#ifndef LOCAL_DECL_ALIGNMENT
#define LOCAL_DECL_ALIGNMENT(DECL) \
LOCAL_ALIGNMENT (TREE_TYPE (DECL), DECL_ALIGN (DECL))
#endif
/* Alignment value for attribute ((aligned)). */
#ifndef ATTRIBUTE_ALIGNED_VALUE
#define ATTRIBUTE_ALIGNED_VALUE BIGGEST_ALIGNMENT
......
......@@ -1215,6 +1215,18 @@ This macro is to set alignment of stack slot to the maximum alignment
of all possible modes which the slot may have.
@end defmac
@defmac LOCAL_DECL_ALIGNMENT (@var{decl})
If defined, a C expression to compute the alignment for a local
variable @var{decl}.
If this macro is not defined, then
@code{LOCAL_ALIGNMENT (TREE_TYPE (@var{decl}), DECL_ALIGN (@var{decl}))}
is used.
One use of this macro is to increase alignment of medium-size data to
make it all fit in fewer cache lines.
@end defmac
@defmac EMPTY_FIELD_BOUNDARY
Alignment in bits to be given to a structure bit-field that follows an
empty field such as @code{int : 0;}.
......
2009-03-11 Jakub Jelinek <jakub@redhat.com>
PR target/39137
* gcc.target/i386/stackalign/longlong-1.c: New test.
* gcc.target/i386/stackalign/longlong-2.c: New test.
2009-03-11 Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
* g++.old-deja/g++.jason/thunk2.C: Skip on SPU.
......
/* PR target/39137 */
/* { dg-do compile } */
/* { dg-require-effective-target ilp32 } */
/* { dg-options "-O2 -mpreferred-stack-boundary=2" } */
/* Make sure dynamic stack realignment isn't performed just because there
are long long variables. */
/* { dg-final { scan-assembler-not "and\[lq\]?\[^\\n\]*-8,\[^\\n\]*sp" } } */
void fn (void *);
void f1 (void)
{
unsigned long long a;
fn (&a);
}
/* { dg-do compile } */
/* { dg-require-effective-target ilp32 } */
/* { dg-options "-O2 -mpreferred-stack-boundary=2" } */
/* { dg-final { scan-assembler-times "and\[lq\]?\[^\\n\]*-8,\[^\\n\]*sp" 2 } } */
/* { dg-final { scan-assembler-times "and\[lq\]?\[^\\n\]*-16,\[^\\n\]*sp" 2 } } */
void fn (void *);
void f2 (void)
{
unsigned long long a __attribute__((aligned (8)));
fn (&a);
}
void f3 (void)
{
typedef unsigned long long L __attribute__((aligned (8)));
L a;
fn (&a);
}
void f4 (void)
{
unsigned long long a __attribute__((aligned (16)));
fn (&a);
}
void f5 (void)
{
typedef unsigned long long L __attribute__((aligned (16)));
L a;
fn (&a);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment