https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111970

--- Comment #17 from Richard Biener <rguenth at gcc dot gnu.org> ---
OK, so for RISC-V with the testcase from the description there's the
following issue:

  _179 = &MEM <vector(64) unsigned char> [(uint8_t *)_618];
  _225 = BIT_FIELD_REF <MEM <vector(64) unsigned char> [(uint8_t *)_179], 8,
16>;
...
  vect__8.9_405 = {_218, _224, _230, _236, _242, _248, _254, _260, _266, _272,
_278, _284, _290, _296, _302, _308, _314, _320, _326, _332, _338, _344, _350,
_356, _362, _368, _374, _380, _386, _392, _398, _404};
  vect__11.11_599 = vect__8.9_405 + { 1.0e+0, 2.0e+0, 1.0e+0, 2.0e+0, 1.0e+0,
2.0e+0, 1.0e+0, 2.0e+0, 1.0e+0, 2.0e+0, 1.0e+0, 2.0e+0, 1.0e+0, 2.0e+0, 1.0e+0,
2.0e+0, 1.0e+0, 2.0e+0, 1.0e+0, 2.0e+0, 1.0e+0, 2.0e+0, 1.0e+0, 2.0e+0, 1.0e+0,
2.0e+0, 1.0e+0, 2.0e+0, 1.0e+0, 2.0e+0, 1.0e+0, 2.0e+0 };
  _609 = (void *) ivtmp.31_622;
  MEM <vector(32) float> [(float *)_609] = vect__11.11_599;
  _1 = _609 + 128;
  MEM <vector(32) float> [(float *)_1] = vect__11.11_599;

I think the following fixes it:

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));

Reply via email to