Hi Sterling, I found that we can avoid emitting excessive literal loading instructions with with section anchors. This patch also passed the cases in testsuite/gcc.c-torture/execute/ dir. Please apply it if OK for trunk.
Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 206599) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,11 @@ +2014-01-14 Felix Yang <fei.yang0...@gmail.com> + + * common/config/xtensa/xtensa-common.c + (xtensa_option_optimization_table): Enable -fsection-anchors under -O1 + or plus, and disable -fcommon by default. + * config/xtensa/xtensa.c (TARGET_MAX_ANCHOR_OFFSET): New. + (TARGET_MIN_ANCHOR_OFFSET): Ditto. + 2014-01-14 Richard Biener <rguent...@suse.de> PR tree-optimization/58921 Index: gcc/common/config/xtensa/xtensa-common.c =================================================================== --- gcc/common/config/xtensa/xtensa-common.c (revision 206599) +++ gcc/common/config/xtensa/xtensa-common.c (working copy) @@ -35,6 +35,13 @@ static const struct default_options xtensa_option_ assembler, so GCC cannot do a good job of reordering blocks. Do not enable reordering unless it is explicitly requested. */ { OPT_LEVELS_ALL, OPT_freorder_blocks, NULL, 0 }, + /* Enable section anchors under -O1 or plus. This can avoid generating + excessive literal loading instructions to load addresses of globals. */ + { OPT_LEVELS_1_PLUS, OPT_fsection_anchors, NULL, 2 }, + /* Allocate uninitialized global variables in the data section of object + file, rather than generating them as common blocks. This is required + for section anchors to work on uninitialized globals. */ + { OPT_LEVELS_ALL, OPT_fcommon, NULL, 0 }, { OPT_LEVELS_NONE, 0, NULL, 0 } }; Index: gcc/config/xtensa/xtensa.c =================================================================== --- gcc/config/xtensa/xtensa.c (revision 206599) +++ gcc/config/xtensa/xtensa.c (working copy) @@ -290,6 +290,12 @@ static const int reg_nonleaf_alloc_order[FIRST_PSE #undef TARGET_CANNOT_FORCE_CONST_MEM #define TARGET_CANNOT_FORCE_CONST_MEM xtensa_cannot_force_const_mem +#undef TARGET_MAX_ANCHOR_OFFSET +#define TARGET_MAX_ANCHOR_OFFSET 255 + +#undef TARGET_MIN_ANCHOR_OFFSET +#define TARGET_MIN_ANCHOR_OFFSET 0 + #undef TARGET_LEGITIMATE_ADDRESS_P #define TARGET_LEGITIMATE_ADDRESS_P xtensa_legitimate_address_p Cheers, Felix