[PATCH] D66803: [LV] Tail-folding with runtime memory checks

Sjoerd Meijer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 07:41:50 PDT 2019


SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: Ayal, dorit, hsaito, fhahn, dcaballe.
Herald added subscribers: rkruppe, hiraditya.
Herald added a project: LLVM.

The loop vectorizer is running in an assert when it has to emit
runtime memory disambiguation checks. This happens as soon as you try
to do something like:

      
  #pragma clang loop predicate(enable)
  for (int i=0; i < N; i++)
    A[i] = B[i] + C[i];
      

where A, B, and C are integer pointers, not annotated with e.g. the restrict
type qualifier.

      

However, it looks like the logic to deal with this is all in place, so this
simply removes the assert.


https://reviews.llvm.org/D66803

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Transforms/LoopVectorize/X86/tail-folding-memcheck.ll


Index: llvm/test/Transforms/LoopVectorize/X86/tail-folding-memcheck.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopVectorize/X86/tail-folding-memcheck.ll
@@ -0,0 +1,38 @@
+; RUN: opt < %s  -loop-vectorize -mcpu=core-avx2 -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define dso_local void @_Z1GPiS_S_(i32* nocapture %A, i32* nocapture readonly %B, i32* nocapture readonly %C) local_unnamed_addr #0 {
+; CHECK-LABEL: @_Z1GPiS_S_
+; CHECK: vector.memcheck:
+; CHECK: vector.body:
+; CHECK: @llvm.masked.load.v8i32.p0v8i32
+; CHECK: @llvm.masked.load.v8i32.p0v8i32
+; CHECK: @llvm.masked.store.v8i32.p0v8i32
+; CHECK: br i1 %12, label %middle.block, label %vector.body
+entry:
+  br label %for.body
+
+for.cond.cleanup:
+  ret void
+
+for.body:
+  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+  %arrayidx = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
+  %0 = load i32, i32* %arrayidx, align 4
+  %arrayidx2 = getelementptr inbounds i32, i32* %C, i64 %indvars.iv
+  %1 = load i32, i32* %arrayidx2, align 4
+  %add = add nsw i32 %1, %0
+  %arrayidx4 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
+  store i32 %add, i32* %arrayidx4, align 4
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond = icmp eq i64 %indvars.iv.next, 430
+  br i1 %exitcond, label %for.cond.cleanup, label %for.body, !llvm.loop !6
+}
+
+attributes #0 = { nofree norecurse nounwind uwtable }
+
+!6 = distinct !{!6, !7, !8}
+!7 = !{!"llvm.loop.vectorize.predicate.enable", i1 true}
+!8 = !{!"llvm.loop.vectorize.enable", i1 true}
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2729,7 +2729,6 @@
   if (!MemRuntimeCheck)
     return;
 
-  assert(!Cost->foldTailByMasking() && "Cannot check memory when folding tail");
   // Create a new block containing the memory check.
   BB->setName("vector.memcheck");
   auto *NewBB = BB->splitBasicBlock(BB->getTerminator(), "vector.ph");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66803.217401.patch
Type: text/x-patch
Size: 2234 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190827/92ff330d/attachment.bin>


More information about the llvm-commits mailing list