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

Hao Liu Hao.Liu at arm.com
Wed May 27 23:19:52 PDT 2015


Updated a new patch with slight modifications.

Review please.

Thanks,
-Hao


================
Comment at: lib/Analysis/LoopAccessAnalysis.cpp:795-806
@@ -786,16 +794,14 @@
 
-  // The distance must be bigger than the size needed for a vectorized version
-  // of the operation and the size of the vectorized operation must not be
-  // bigger than the currrent maximum size.
-  if (Distance < 2*TypeByteSize ||
-      2*TypeByteSize > MaxSafeDepDistBytes ||
-      Distance < TypeByteSize * ForcedUnroll * ForcedFactor) {
-    DEBUG(dbgs() << "LAA: Failure because of Positive distance "
-        << Val.getSExtValue() << '\n');
+  // Safe when positive distance is not greater than the max safe distance.
+  if (Distance > MaxSafeDepDistBytes) {
+    DEBUG(dbgs() << "LAA: Failure because positive distance "
+                 << Val.getSExtValue() << " is greater than max safe distance "
+                 << MaxSafeDepDistBytes << "\n");
     return Dependence::Backward;
   }
 
-  // Positive distance bigger than max vectorization factor.
-  MaxSafeDepDistBytes = Distance < MaxSafeDepDistBytes ?
-    Distance : MaxSafeDepDistBytes;
+  // If Distance < Stride * TypeByteSize, it is always safe. just keep the
+  // current MaxSafeDepDistBytes. Otherwise, update the MaxSafeDepDistBytes.
+  if (Distance >= Stride * TypeByteSize)
+    MaxSafeDepDistBytes = Distance;
 
----------------
HaoLiu wrote:
> anemet wrote:
> > I am not sure I follow why you change the structure of the MaxSafeDepDistBytes logic here.  Why aren't you simply comparing MaxSafeDepDistBytes with TypeByteSize * NumIter * Stride?
> > 
> > Looks like this will modify the existing behavior for stride=1 which is probably not what you intend.
> I think preivous logic is not correct. If "Distance > MaxSafeDepDistBytes", it is not safe to do vectorization.
Sorry, previously I misunderstood the MaxSafeDepDistBytes. The new patch follows the meaning of MaxSafeDepDistBytes, it also has the same logic for stride = 1. 

I also found a problem with MaxSafeDepDistBytes. It cannot handdle cases with different kinds of types. like:
       void foo(int *A, char *B) {
           for (unsigned i = 0; i < 1024; i++) {
               A[i+2] = A[i] + 1;
               B[i+2] = B[i] + 1;
           }
       }

I think we should use MaxFactor, which stands for the maximum number of iterations to be vectorized & unrolled. I've added a FIXME in the patch.

http://reviews.llvm.org/D9368

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






More information about the llvm-commits mailing list