[PATCH] D132490: [LoopVectorize] Emit runtime checks correctly for nested loops

Pavel Kosov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 24 11:29:35 PDT 2022


kpdev42 updated this revision to Diff 455303.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132490/new/

https://reviews.llvm.org/D132490

Files:
  llvm/include/llvm/Analysis/LoopAccessAnalysis.h
  llvm/lib/Analysis/LoopAccessAnalysis.cpp
  llvm/test/Transforms/LoopVectorize/nested-loop.ll


Index: llvm/test/Transforms/LoopVectorize/nested-loop.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopVectorize/nested-loop.ll
@@ -0,0 +1,35 @@
+; RUN: opt -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s -o - | FileCheck %s
+; CHECK:       vector.memcheck:
+; CHECK-NEXT:    %bound0 = icmp ult ptr
+; CHECK-NEXT:    %bound1 = icmp ult ptr
+; CHECK-NEXT:    %found.conflict = and i1 %bound0, %bound1
+
+define dso_local void @array_magick(ptr nocapture noundef %a, ptr nocapture noundef readonly %b, i64 noundef %len) local_unnamed_addr {
+entry:
+  br label %outer.header
+
+outer.header:                              ; preds = %entry, %outer.latch
+  %iv28 = phi i64 [ %iv.next29, %outer.latch ], [ 0, %entry ]
+  %arrayidx = getelementptr inbounds i32, ptr %a, i64 %iv28
+  %.pre = load i32, ptr %arrayidx, align 4
+  br label %inner.body
+
+inner.body:                                        ; preds = %outer.header, %inner.body
+  %0 = phi i32 [ %.pre, %outer.header ], [ %sub, %inner.body ]
+  %iv = phi i64 [ 0, %outer.header ], [ %iv.next, %inner.body ]
+  %arrayidx8 = getelementptr inbounds i32, ptr %b, i64 %iv
+  %1 = load i32, ptr %arrayidx8, align 4
+  %sub = sub i32 %0, %1
+  store i32 %sub, ptr %arrayidx, align 4
+  %iv.next = add nuw nsw i64 %iv, 1
+  %exitcond.not = icmp eq i64 %iv.next, %len
+  br i1 %exitcond.not, label %outer.latch, label %inner.body
+
+outer.latch:                    ; preds = %inner.body
+  %iv.next29 = add nuw nsw i64 %iv28, 1
+  %exitcond31.not = icmp eq i64 %iv.next29, %len
+  br i1 %exitcond31.not, label %exit, label %outer.header
+
+exit:                                             ; preds = %outer.latch
+  ret void
+}
Index: llvm/lib/Analysis/LoopAccessAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -281,7 +281,8 @@
 
   auto *SrcAR = dyn_cast<SCEVAddRecExpr>(Src->Expr);
   auto *SinkAR = dyn_cast<SCEVAddRecExpr>(Sink->Expr);
-  if (!SrcAR || !SinkAR) {
+  if (!SrcAR || !SinkAR || SrcAR->getLoop() != DC.getInnermostLoop() ||
+      SinkAR->getLoop() != DC.getInnermostLoop()) {
     CanUseDiffCheck = false;
     return;
   }
Index: llvm/include/llvm/Analysis/LoopAccessAnalysis.h
===================================================================
--- llvm/include/llvm/Analysis/LoopAccessAnalysis.h
+++ llvm/include/llvm/Analysis/LoopAccessAnalysis.h
@@ -253,6 +253,8 @@
     return {};
   }
 
+  const Loop *getInnermostLoop() const { return InnermostLoop; }
+
 private:
   /// A wrapper around ScalarEvolution, used to add runtime SCEV checks, and
   /// applies dynamic knowledge to simplify SCEV expressions and convert them


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132490.455303.patch
Type: text/x-patch
Size: 2807 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220824/1bd48750/attachment.bin>


More information about the llvm-commits mailing list