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]

Fix alignment computation at exapnsion time


Hi,
in earlier unit-at-a-time the variables was assembled first, function bodies later.
This order was changed to allow more optimizations, but now we forget to compute the
alignment of variable early having overly conservative assumptions at a time we expand
functions.

Bootstrapped/regtested i686-linux, will commit it in few days if no one objects.

Honza

/* { dg-do compile { target i?86-*-* } } */
/* { dg-options "-O2 -msse2 -march=pentiumpro" } */
/* { dg-final { scan-assembler "rep" } } */
/* { dg-final { scan-assembler "movs" } } */
/* { dg-final { scan-assembler-not "test" } } */
/* { dg-final { scan-assembler "\.L?:" } } */

/* A and B are aligned, but we used to lose track of it.
   Ensure that memcpy is inlined and alignment prologue is missing.  *.

char a[900];
char b[900];
t()
{
  memcpy (a,b,900);
}

	* cgraphunit.c (cgraph_varpool_analyze_pending_decls): Call align_variable.
	* output.h (align_variable): Declare.
	* varasm.c (align_variable): Export.
Index: cgraphunit.c
===================================================================
-u -L cgraphunit.c	(revision 114925) -L cgraphunit.c	(working copy) .svn/text-base/cgraphunit.c.svn-base cgraphunit.c
--- cgraphunit.c	(revision 114925)
+++ cgraphunit.c	(working copy)
@@ -281,6 +281,10 @@ cgraph_varpool_analyze_pending_decls (vo
 
       cgraph_varpool_first_unanalyzed_node = cgraph_varpool_first_unanalyzed_node->next_needed;
 
+      /* Compute the alignment early so function body expanders are
+	 already informed about increased alignment.  */
+      align_variable (decl, 0);
+
       if (DECL_INITIAL (decl))
 	{
 	  visited_nodes = pointer_set_create ();
Index: output.h
===================================================================
-u -L output.h	(revision 114925) -L output.h	(working copy) .svn/text-base/output.h.svn-base output.h
--- output.h	(revision 114925)
+++ output.h	(working copy)
@@ -200,6 +200,10 @@ extern void assemble_end_function (tree,
    initial value (that will be done by the caller).  */
 extern void assemble_variable (tree, int, int, int);
 
+/* Compute the alignment of variable specified by DECL.
+   DONT_OUTPUT_DATA is from assemble_variable.  */
+extern void align_variable (tree decl, bool dont_output_data);
+
 /* Output something to declare an external symbol to the assembler.
    (Most assemblers don't need this, so we normally output nothing.)
    Do nothing if DECL is not external.  */
Index: varasm.c
===================================================================
-u -L varasm.c	(revision 114925) -L varasm.c	(working copy) .svn/text-base/varasm.c.svn-base varasm.c
--- varasm.c	(revision 114925)
+++ varasm.c	(working copy)
@@ -834,7 +834,7 @@ bss_initializer_p (tree decl)
 /* Compute the alignment of variable specified by DECL.
    DONT_OUTPUT_DATA is from assemble_variable.  */
 
-static void
+void
 align_variable (tree decl, bool dont_output_data)
 {
   unsigned int align = DECL_ALIGN (decl);


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