[PATCH] D80622: [LAA] Do not set CanDoRT to false for AS that do not need RT checks.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 27 04:17:19 PDT 2020


fhahn created this revision.
fhahn added reviewers: Ayal, anemet, hfinkel, dmgreen.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

Alternative approach to D80570 <https://reviews.llvm.org/D80570>.

canCheckPtrAtRT already contains checks the figure out for which alias
sets runtime checks are needed. But it currently sets CanDoRT to false
for alias sets for which we cannot do RT checks but also do not need
any.

If we know that we do not need RT checks based on the number of
reads/writes in the alias set, we can skip processing the AS.

This patch also adds an assertion to ensure that DepCands does not
contain more than one write from the alias set.

This patch still needs a test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80622

Files:
  llvm/lib/Analysis/LoopAccessAnalysis.cpp


Index: llvm/lib/Analysis/LoopAccessAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -712,11 +712,12 @@
 
   // We assign a consecutive id to access from different alias sets.
   // Accesses between different groups doesn't need to be checked.
-  unsigned ASId = 1;
+  unsigned ASId = 0;
   for (auto &AS : AST) {
     int NumReadPtrChecks = 0;
     int NumWritePtrChecks = 0;
     bool CanDoAliasSetRT = true;
+    ++ASId;
 
     // We assign consecutive id to access from different dependence sets.
     // Accesses within the same set don't need a runtime check.
@@ -752,9 +753,25 @@
     // for which we couldn't find the bounds but we don't actually need to emit
     // any checks so it does not matter.
     bool NeedsAliasSetRTCheck = false;
-    if (!(IsDepCheckNeeded && CanDoAliasSetRT && RunningDepId == 2))
+    if (!(IsDepCheckNeeded && CanDoAliasSetRT && RunningDepId == 2)) {
       NeedsAliasSetRTCheck = (NumWritePtrChecks >= 2 ||
                              (NumReadPtrChecks >= 1 && NumWritePtrChecks >= 1));
+      // For alias sets without at least 2 writes or 1 write and 1 read, there
+      // is no need to generate RT checks and CanDoAliasSetRT for this alias set
+      // does not impact whether runtime checks can be generated.
+      if (!NeedsAliasSetRTCheck) {
+        assert(AS.size() <= 1 ||
+               all_of(AS,
+                      [this](auto AC) {
+                        MemAccessInfo AccessWrite(AC.getValue(), true);
+                        return DepCands.findValue(AccessWrite) ==
+                               DepCands.end();
+                      }) &&
+                   "Can only skip updating CanDoRT below, if all entries in AS "
+                   "are reads or there is at most 1 entry");
+        continue;
+      }
+    }
 
     // We need to perform run-time alias checks, but some pointers had bounds
     // that couldn't be checked.
@@ -774,7 +791,6 @@
 
     CanDoRT &= CanDoAliasSetRT;
     NeedRTCheck |= NeedsAliasSetRTCheck;
-    ++ASId;
   }
 
   // If the pointers that we would use for the bounds comparison have different


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80622.266483.patch
Type: text/x-patch
Size: 2231 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200527/0cfde00f/attachment.bin>


More information about the llvm-commits mailing list