[PATCH] D20789: Consecutive memory access in Loop Vectorizer - fixed and simplified

Elena Demikhovsky via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 31 04:23:05 PDT 2016


delena added a comment.

Hi, I have a question about LoopAccessAnalysis.

The current patch enables vectorization of this loop:

  void IncrementalCopyFastPath(const char* src, char* op, int len) {
    while (len > 0) {
      *(reinterpret_cast<long long*>(op)) = *(reinterpret_cast<const long long*>(src));
      src += 8;
      op += 8;
      len -= 8;
    }
  }

And the result is incorrect because the distance between "src" and "op" is not big enough.
And there is no run-time check between load and store pointers.
This is the loop before vectorization:

  while.body:                                       ; preds = %while.body.preheader, %while.body
    %len.addr.07 = phi i32 [ %sub, %while.body ], [ %len, %while.body.preheader ]
    %op.addr.06 = phi i8* [ %add.ptr1, %while.body ], [ %op, %while.body.preheader ]
    %src.addr.05 = phi i8* [ %add.ptr, %while.body ], [ %src, %while.body.preheader ]
    %0 = bitcast i8* %src.addr.05 to i64*
    %1 = load i64, i64* %0, align 8
    %2 = bitcast i8* %op.addr.06 to i64*
    store i64 %1, i64* %2, align 8
    %add.ptr = getelementptr inbounds i8, i8* %src.addr.05, i64 8
    %add.ptr1 = getelementptr inbounds i8, i8* %op.addr.06, i64 8
    %sub = add nsw i32 %len.addr.07, -8
    %cmp = icmp sgt i32 %len.addr.07, 8
    br i1 %cmp, label %while.body, label %while.end.loopexit
  
    while.end.loopexit:                               ; preds = %while.body

I looked at MemoryDepChecker::areDepsSafe(). It checks pointers with same "Leader", like A[i] and A[i+2]. 
What function should check distance between A and B in order to say that A[i] = B[i] are safe for vectorization?
Thank you.


Repository:
  rL LLVM

https://reviews.llvm.org/D20789





More information about the llvm-commits mailing list