ix86_data_alignment returns 32 bytes or the cache line size when getting
the optimized alignment for a static aggregate variable bigger than 32
bytes or the cache line size.  The increased alignment only applies to
the static variable in the same compilation unit while not optimizing for
space.  If excessive alignment over natural alignment provides very
little performance improvements, we should avoid it to reduce memory
size. This patch does 2 things:

1. Remove the cache line size alignment introduced in GCC 4.9.
2. Limit the alignment increase to word size like -Os.

Kirill, can you measure its performance impact on SPEC CPU 2006 with
-O2 and -O3?

Thanks.

H.J.
---
2014-06-11  H.J. Lu  <hongjiu...@intel.com>

        PR target/61296
        * config/i386/i386.c (ix86_data_alignment): Only increase
        alignment to word size for optimization.
        * config/i386/i386.h (DATA_ALIGNMENT): Update comments.

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 2050aaf..3a571bf 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -26617,42 +26617,27 @@ ix86_data_alignment (tree type, int align, bool opt)
 {
   /* GCC 4.8 and earlier used to incorrectly assume this alignment even
      for symbols from other compilation units or symbols that don't need
-     to bind locally.  In order to preserve some ABI compatibility with
-     those compilers, ensure we don't decrease alignment from what we
-     used to assume.  */
+     to bind locally.  When aligning for optimization, we align static
+     variable to the word size.  GCC 4.9 and earlier align static
+     aggregate variables to 32 bytes or the cache line size.  But it
+     creates data size without very little performance improvements
+     over natural data alignments.  */
 
-  int max_align_compat
-    = optimize_size ? BITS_PER_WORD : MIN (256, MAX_OFILE_ALIGNMENT);
-
-  /* A data structure, equal or greater than the size of a cache line
-     (64 bytes in the Pentium 4 and other recent Intel processors, including
-     processors based on Intel Core microarchitecture) should be aligned
-     so that its base address is a multiple of a cache line size.  */
-
-  int max_align
-    = MIN ((unsigned) ix86_tune_cost->prefetch_block * 8, MAX_OFILE_ALIGNMENT);
-
-  if (max_align < BITS_PER_WORD)
-    max_align = BITS_PER_WORD;
+  int max_align = BITS_PER_WORD;
 
   if (opt
       && AGGREGATE_TYPE_P (type)
       && TYPE_SIZE (type)
-      && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
-    {
-      if (wi::geu_p (TYPE_SIZE (type), max_align_compat)
-         && align < max_align_compat)
-       align = max_align_compat;
-       if (wi::geu_p (TYPE_SIZE (type), max_align)
-          && align < max_align)
-        align = max_align;
-    }
+      && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
+      && wi::geu_p (TYPE_SIZE (type), max_align)
+      && align < max_align)
+    align = max_align;
 
   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
      to 16byte boundary.  */
   if (TARGET_64BIT)
     {
-      if ((opt ? AGGREGATE_TYPE_P (type) : TREE_CODE (type) == ARRAY_TYPE)
+      if (TREE_CODE (type) == ARRAY_TYPE
          && TYPE_SIZE (type)
          && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
          && wi::geu_p (TYPE_SIZE (type), 128)
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index a4009d3..22af036 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -837,12 +837,7 @@ extern const char *host_detect_local_cpu (int argc, const 
char **argv);
    the object would ordinarily have.  The value of this macro is used
    instead of that alignment to align the object.
 
-   If this macro is not defined, then ALIGN is used.
-
-   One use of this macro is to increase alignment of medium-size
-   data to make it all fit in fewer cache lines.  Another is to
-   cause character arrays to be word-aligned so that `strcpy' calls
-   that copy constants to character arrays can be done inline.  */
+   If this macro is not defined, then ALIGN is used.  */
 
 #define DATA_ALIGNMENT(TYPE, ALIGN) \
   ix86_data_alignment ((TYPE), (ALIGN), true)

Reply via email to