This fixes PR52571, we should not align DECL_COMMON variables as they might be pre-empted by a definition with lower alignment.
At LTO/WPA level we might recover from missed optimizations by promoting DECL_COMMON variables to non-common. Not sure if we do that already. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2012-03-14 Richard Guenther <rguent...@suse.de> PR tree-optimization/52571 * tree-vect-data-refs.c (vect_compute_data_ref_alignment): Move flag_section_anchors check ... (vect_can_force_dr_alignment_p): ... here. Do not re-align DECL_COMMON variables. Index: gcc/tree-vect-data-refs.c =================================================================== *** gcc/tree-vect-data-refs.c (revision 185379) --- gcc/tree-vect-data-refs.c (working copy) *************** vect_compute_data_ref_alignment (struct *** 872,881 **** if (!base_aligned) { ! /* Do not change the alignment of global variables if ! flag_section_anchors is enabled. */ ! if (!vect_can_force_dr_alignment_p (base, TYPE_ALIGN (vectype)) ! || (TREE_STATIC (base) && flag_section_anchors)) { if (vect_print_dump_info (REPORT_DETAILS)) { --- 872,878 ---- if (!base_aligned) { ! if (!vect_can_force_dr_alignment_p (base, TYPE_ALIGN (vectype))) { if (vect_print_dump_info (REPORT_DETAILS)) { *************** vect_can_force_dr_alignment_p (const_tre *** 4546,4557 **** if (TREE_CODE (decl) != VAR_DECL) return false; ! if (DECL_EXTERNAL (decl)) return false; if (TREE_ASM_WRITTEN (decl)) return false; if (TREE_STATIC (decl)) return (alignment <= MAX_OFILE_ALIGNMENT); else --- 4543,4564 ---- if (TREE_CODE (decl) != VAR_DECL) return false; ! /* We cannot change alignment of common or external symbols as another ! translation unit may contain a definition with lower alignment. ! The rules of common symbol linking mean that the definition ! will override the common symbol. */ ! if (DECL_EXTERNAL (decl) ! || DECL_COMMON (decl)) return false; if (TREE_ASM_WRITTEN (decl)) return false; + /* Do not change the alignment of global variables if flag_section_anchors + is enabled. */ + if (TREE_STATIC (decl) && flag_section_anchors) + return false; + if (TREE_STATIC (decl)) return (alignment <= MAX_OFILE_ALIGNMENT); else