[PATCH] D145616: [LV] Use speculatability within entire loop to avoid strided load predication

Anna Thomas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 8 14:26:19 PST 2023


anna created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
anna requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead.
Herald added a project: LLVM.

Use existing functionality for identifying total access size by strided
loads. If we can speculate the load across all vector iterations, we can
avoid predication for these strided loads (or masked gathers in
architectures which support it).

TODO: Precommit tests and update patch with test


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145616

Files:
  llvm/lib/Analysis/Loads.cpp


Index: llvm/lib/Analysis/Loads.cpp
===================================================================
--- llvm/lib/Analysis/Loads.cpp
+++ llvm/lib/Analysis/Loads.cpp
@@ -286,15 +286,22 @@
   auto* Step = dyn_cast<SCEVConstant>(AddRec->getStepRecurrence(SE));
   if (!Step)
     return false;
-  // TODO: generalize to access patterns which have gaps
-  if (Step->getAPInt() != EltSize)
-    return false;
 
   auto TC = SE.getSmallConstantMaxTripCount(L);
   if (!TC)
     return false;
 
-  const APInt AccessSize = TC * EltSize;
+  // For now, just ignore overlapping accesses.
+  // TODO: We should be taking max(Step,EltSize) for computing AccessSize
+  // below.
+  if (EltSize.sgt(Step->getAPInt()))
+    return false;
+  // Compute the total access size for access patterns with unit stride and
+  // patterns with gaps. For patterns with unit stride, Step and EltSize are the
+  // same.
+  // For patterns with gaps (i.e. non unit stride), we are
+  // accessing EltSize bytes at every Step.
+  const APInt AccessSize = TC * Step->getAPInt();
 
   auto *StartS = dyn_cast<SCEVUnknown>(AddRec->getStart());
   if (!StartS)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145616.503523.patch
Type: text/x-patch
Size: 1132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230308/42e8ed20/attachment.bin>


More information about the llvm-commits mailing list