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

            Bug ID: 98674
           Summary: [10/11] Regression vectorizer failed for compilation
                    time alias
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: crazylht at gmail dot com
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu

Cat test.c, refer to https://godbolt.org/z/fx9cMq
---
void swap(short *p, int cnt) {
    cnt = 1000;
    while (cnt-- > 0) {
        *p = ((*p << 8) & 0xFF00) |
             ((*p >> 8) & 0x00FF);
        ++p;
    }
}
----


test.c:3:16: missed: couldn't vectorize loop
test.c:4:8: missed: not vectorized: compilation time alias: load_dst_23 =
MEM[(short int *)p_21];
*p_21 = _8;

but they have the same address, and of course they alias.

---
  <bb 3> [local count: 1063004409]:
  # p_21 = PHI <p_16(5), p_12(D)(2)>
  # cnt_24 = PHI <cnt_14(5), 999(2)>
  # ivtmp_26 = PHI <ivtmp_2(5), 1000(2)>
  load_dst_23 = MEM[(short int *)p_21];
  bswapdst_11 = load_dst_23 r>> 8;
  _8 = (short int) bswapdst_11;
  *p_21 = _8;
  p_16 = p_21 + 2;
  cnt_14 = cnt_24 + -1;
  ivtmp_2 = ivtmp_26 - 1;
  if (ivtmp_2 != 0)
----

So does vectorizer assume there won't be 2 DRs with same reference?

Successfully vectorized with below hack
---
modified   gcc/tree-vect-data-refs.c
@@ -3302,6 +3302,10 @@ vect_compile_time_alias (dr_vec_info *a, dr_vec_info *b,
   const_length_a += access_size_a;
   const_length_b += access_size_b;

+  /* It's ok for the same reference.  */
+  if (known_eq (const_length_a, const_length_b))
+    return 0;
+
   if (ranges_known_overlap_p (offset_a, const_length_a,
                              offset_b, const_length_b))
     return 1;

---

Reply via email to