]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/118669 - fixup wrongly aligned loads/stores
authorRichard Biener <rguenther@suse.de>
Wed, 2 Jul 2025 07:30:05 +0000 (09:30 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 9 Jul 2025 06:29:35 +0000 (08:29 +0200)
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.

PR tree-optimization/118669
* tree-vect-stmts.cc (vectorizable_load): Emit loads
with proper (element) alignment.
(vectorizable_store): Likewise.

(cherry picked from commit 37bf13adcda564dfdb28c3aa736f2cac71c73d09)

gcc/tree-vect-stmts.cc

index 978a4626b35b945bcac35243252bb245505f55dd..89ac5f611276f66becc546ea477af9e3f4430f55 100644 (file)
@@ -10062,7 +10062,8 @@ vectorizable_store (vec_info *vinfo,
                = 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)
@@ -12254,7 +12255,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)