[PATCH] [LoopVectorize]Teach Loop Vectorizer about interleaved memory access

Hao Liu Hao.Liu at arm.com
Thu May 14 01:03:14 PDT 2015


I find it could break the Write After Write dependeces for cases like:

  void waw(int *A) {
    short *T = (short *)A;
    T++;
    int *B = (int *)T;
    for (unsigned i = 0; i < 1024; i+=2)  {
      A[i+1] = i + 1;      // (1)
      B[i] = i;            // (2)
      A[i] = i;            // (3)
    }
  }

The combine of "(1) + (3)" will be inserted after (2). As pointer B and A can calculate the distance, and all Writes are the same size and share the same stride, it can indeed pass the memory dependence check.

I'll fix this in the new patch.

Thanks,
-Hao


================
Comment at: include/llvm/Analysis/LoopAccessAnalysis.h:401-414
@@ +400,16 @@
+    bool insertMember(Instruction *Inst, int Index, unsigned Alignment) {
+      unsigned AbsIdx = std::abs(Index);
+      if (Index < 0) {
+        unsigned LIndex = Members.back().second;
+        // Break rule 1. Doesn't belong to this group.
+        if (LIndex + AbsIdx >= Stride)
+          return false;
+
+        for (auto &I : Members)
+          I.second += AbsIdx;
+
+        Members.insert(Members.begin(), std::make_pair(Inst, 0));
+        Align = std::min(Align, Alignment);
+        return true;
+      }
+
----------------
mzolotukhin wrote:
> A couple of comments regarding this code:
> 1) Let's consistently use either `Idx` or `Index`.
> 2) Do we need `AbsIdx` at all? Under the if we can use `-Index` instead of it, after the if - just `Index`.
> 3) In the paper you mentioned it was stated that the grouping algorithm is linear in the number of accesses. In your current implementation it's quadratic, and the complexity seems to come from two factors: 1) we recalculate indexes after adding a new member, 2) we explicitly check if the group already contains a member with the same index. Could we do anything about that? E.g. I think that recalculating isn't necessary at all, and the check for duplicates can be done faster if we use a hash-table for it.
Reasonable.

http://reviews.llvm.org/D9368

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list