The vectorizer tracks alignment of datarefs with dr_aligned and dr_unaligned_supported but that's aligned with respect to the target alignment which can be less aligned than the mode used for the access. The following fixes this discrepancy for vectorizing loads and stores. The issue is visible for aarch64 SVE and risc-v where VLA vector modes have larger than element alignment but the target handles element alignment just fine.
Bootstrap and regtest ongoing on x86_64-unknown-linux-gnu. PR tree-optimization/118669 * tree-vect-stmts.cc (vectorizable_load): Emit loads with proper (element) alignment. (vectorizable_store): Likewise. --- gcc/tree-vect-stmts.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 29368c00c8d..c7e160fa29b 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -9682,7 +9682,8 @@ vectorizable_store (vec_info *vinfo, data_ref = fold_build2 (MEM_REF, vectype, dataref_ptr, dataref_offset ? dataref_offset : build_int_cst (ref_type, 0)); - if (alignment_support_scheme == dr_aligned) + if (alignment_support_scheme == dr_aligned + && align >= TYPE_ALIGN_UNIT (vectype)) ; else TREE_TYPE (data_ref) @@ -11715,7 +11716,8 @@ vectorizable_load (vec_info *vinfo, { data_ref = fold_build2 (MEM_REF, ltype, dataref_ptr, offset); - if (alignment_support_scheme == dr_aligned) + if (alignment_support_scheme == dr_aligned + && align >= TYPE_ALIGN_UNIT (ltype)) ; else TREE_TYPE (data_ref) -- 2.43.0