There's a missed index adjustment for the SLP vector number when
computing the index/data vectors for emulated gather/scatter with SLP.
The following fixes this.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

        PR tree-optimization/111970
        * tree-vect-stmts.cc (vectorizable_load): Fix offset calculation
        for SLP gather load.
        (vectorizable_store): Likewise for SLP scatter store.
---
 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 96e4a6cffad..bf8c99779ae 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -9188,7 +9188,8 @@ vectorizable_store (vec_info *vinfo,
                  unsigned HOST_WIDE_INT factor
                    = const_offset_nunits / const_nunits;
                  vec_offset = vec_offsets[(vec_num * j + i) / factor];
-                 unsigned elt_offset = (j % factor) * const_nunits;
+                 unsigned elt_offset
+                   = ((vec_num * j + i) % factor) * const_nunits;
                  tree idx_type = TREE_TYPE (TREE_TYPE (vec_offset));
                  tree scale = size_int (gs_info.scale);
                  align = get_object_alignment (DR_REF (first_dr_info->dr));
@@ -11150,7 +11151,8 @@ vectorizable_load (vec_info *vinfo,
                  unsigned HOST_WIDE_INT factor
                    = const_offset_nunits / const_nunits;
                  vec_offset = vec_offsets[(vec_num * j + i) / factor];
-                 unsigned elt_offset = (j % factor) * const_nunits;
+                 unsigned elt_offset
+                   = ((vec_num * j + i) % factor) * const_nunits;
                  tree idx_type = TREE_TYPE (TREE_TYPE (vec_offset));
                  tree scale = size_int (gs_info.scale);
                  align = get_object_alignment (DR_REF (first_dr_info->dr));
-- 
2.35.3

Reply via email to