diff mbox

xtensa: align data naturally when optimizing for size

Message ID 1424564349-18355-1-git-send-email-jcmvbkbc@gmail.com
State New
Headers show

Commit Message

Max Filippov Feb. 22, 2015, 12:19 a.m. UTC
gcc for xtensa always aligns data at least to a word boundary, even when
it has smaller natural alignment. This results in unexpectedly high data
section sizes and unreasonable amount of wasted space when linking
objects compiled with -fdata-sections flag.

Align data naturally when optimization for size is enabled.

2015-02-22  Max Filippov  <jcmvbkbc@gmail.com>

gcc/
	* config/xtensa/xtensa.h (CONSTANT_ALIGNMENT, DATA_ALIGNMENT):
	use natural alignment when optimizing for size.
---
 gcc/config/xtensa/xtensa.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Max Filippov Feb. 23, 2015, 11:37 p.m. UTC | #1
On Tue, Feb 24, 2015 at 2:30 AM, augustine.sterling@gmail.com
<augustine.sterling@gmail.com> wrote:
> On Sat, Feb 21, 2015 at 4:19 PM, Max Filippov <jcmvbkbc@gmail.com> wrote:
>>
>> gcc for xtensa always aligns data at least to a word boundary, even when
>> it has smaller natural alignment. This results in unexpectedly high data
>> section sizes and unreasonable amount of wasted space when linking
>> objects compiled with -fdata-sections flag.
>>
>> Align data naturally when optimization for size is enabled.
>>
>> 2015-02-22  Max Filippov  <jcmvbkbc@gmail.com>
>
>
> This is OK for xtensa.

Applied to trunk. Thanks!

-- Max
augustine.sterling@gmail.com Feb. 24, 2015, 12:30 a.m. UTC | #2
On Sat, Feb 21, 2015 at 4:19 PM, Max Filippov <jcmvbkbc@gmail.com> wrote:
> gcc for xtensa always aligns data at least to a word boundary, even when
> it has smaller natural alignment. This results in unexpectedly high data
> section sizes and unreasonable amount of wasted space when linking
> objects compiled with -fdata-sections flag.
>
> Align data naturally when optimization for size is enabled.
>
> 2015-02-22  Max Filippov  <jcmvbkbc@gmail.com>
>
> gcc/
>         * config/xtensa/xtensa.h (CONSTANT_ALIGNMENT, DATA_ALIGNMENT):
>         use natural alignment when optimizing for size.

This is OK for xtensa.
diff mbox

Patch

diff --git a/gcc/config/xtensa/xtensa.h b/gcc/config/xtensa/xtensa.h
index 0de072b..74ca240 100644
--- a/gcc/config/xtensa/xtensa.h
+++ b/gcc/config/xtensa/xtensa.h
@@ -174,7 +174,8 @@  extern unsigned xtensa_current_frame_size;
    constants to be word aligned so that 'strcpy' calls that copy
    constants can be done inline.  */
 #define CONSTANT_ALIGNMENT(EXP, ALIGN)					\
-  ((TREE_CODE (EXP) == STRING_CST || TREE_CODE (EXP) == CONSTRUCTOR)	\
+  (!optimize_size &&							\
+   (TREE_CODE (EXP) == STRING_CST || TREE_CODE (EXP) == CONSTRUCTOR)	\
    && (ALIGN) < BITS_PER_WORD						\
 	? BITS_PER_WORD							\
 	: (ALIGN))
@@ -186,7 +187,7 @@  extern unsigned xtensa_current_frame_size;
    that copy constants to character arrays can be done inline.  */
 #undef DATA_ALIGNMENT
 #define DATA_ALIGNMENT(TYPE, ALIGN)					\
-  ((((ALIGN) < BITS_PER_WORD)						\
+  (!optimize_size && (((ALIGN) < BITS_PER_WORD)				\
     && (TREE_CODE (TYPE) == ARRAY_TYPE					\
 	|| TREE_CODE (TYPE) == UNION_TYPE				\
 	|| TREE_CODE (TYPE) == RECORD_TYPE)) ? BITS_PER_WORD : (ALIGN))