[polly] r219503 - Relax the condition on the jsop accesses regarding the alignment.

Johannes Doerfert doerfert at cs.uni-saarland.de
Fri Oct 10 08:14:29 PDT 2014


Author: jdoerfert
Date: Fri Oct 10 10:14:29 2014
New Revision: 219503

URL: http://llvm.org/viewvc/llvm-project?rev=219503&view=rev
Log:
Relax the condition on the jsop accesses regarding the alignment.

  We restricted the new access functions to be a subset of the old one
  because we want to keep the alignment, however if the alignment is
  "not special", thus the default for the type, we can allow any access.


Differential Revision: http://reviews.llvm.org/D5680

Added:
    polly/trunk/test/Isl/CodeGen/MemAccess/default_aligned_new_access_function.ll
    polly/trunk/test/Isl/CodeGen/MemAccess/simple_stride___%for.cond---%for.end.jscop
Modified:
    polly/trunk/lib/Exchange/JSONExporter.cpp

Modified: polly/trunk/lib/Exchange/JSONExporter.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Exchange/JSONExporter.cpp?rev=219503&r1=219502&r2=219503&view=diff
==============================================================================
--- polly/trunk/lib/Exchange/JSONExporter.cpp (original)
+++ polly/trunk/lib/Exchange/JSONExporter.cpp Fri Oct 10 10:14:29 2014
@@ -185,6 +185,7 @@ bool JSONImporter::runOnScop(Scop &scop)
   S = &scop;
   Region &R = S->getRegion();
   Dependences *D = &getAnalysis<Dependences>();
+  const DataLayout &DL = getAnalysis<DataLayoutPass>().getDataLayout();
 
   std::string FileName = ImportDir + "/" + getFileName(S);
 
@@ -281,18 +282,33 @@ bool JSONImporter::runOnScop(Scop &scop)
       newAccessMap = isl_map_set_tuple_id(newAccessMap, isl_dim_out, OutId);
 
       // We keep the old alignment, thus we cannot allow accesses to memory
-      // locations that were not accessed before.
-      isl_set *newAccessSet = isl_map_range(isl_map_copy(newAccessMap));
-      isl_set *currentAccessSet = isl_map_range(isl_map_copy(currentAccessMap));
-      bool isSubset = isl_set_is_subset(newAccessSet, currentAccessSet);
-      isl_set_free(newAccessSet);
-      isl_set_free(currentAccessSet);
-
-      if (!isSubset) {
-        errs() << "JScop file changes the accessed memory\n";
-        isl_map_free(currentAccessMap);
-        isl_map_free(newAccessMap);
-        return false;
+      // locations that were not accessed before if the alignment of the access
+      // is not the default alignment.
+      bool SpecialAlignment = true;
+      if (LoadInst *LoadI = dyn_cast<LoadInst>(MA->getAccessInstruction())) {
+        SpecialAlignment =
+            DL.getABITypeAlignment(LoadI->getType()) != LoadI->getAlignment();
+      } else if (StoreInst *StoreI =
+                     dyn_cast<StoreInst>(MA->getAccessInstruction())) {
+        SpecialAlignment =
+            DL.getABITypeAlignment(StoreI->getValueOperand()->getType()) !=
+            StoreI->getAlignment();
+      }
+
+      if (SpecialAlignment) {
+        isl_set *newAccessSet = isl_map_range(isl_map_copy(newAccessMap));
+        isl_set *currentAccessSet =
+            isl_map_range(isl_map_copy(currentAccessMap));
+        bool isSubset = isl_set_is_subset(newAccessSet, currentAccessSet);
+        isl_set_free(newAccessSet);
+        isl_set_free(currentAccessSet);
+
+        if (!isSubset) {
+          errs() << "JScop file changes the accessed memory\n";
+          isl_map_free(currentAccessMap);
+          isl_map_free(newAccessMap);
+          return false;
+        }
       }
 
       // We need to copy the isl_ids for the parameter dimensions to the new
@@ -342,6 +358,7 @@ bool JSONImporter::runOnScop(Scop &scop)
 void JSONImporter::getAnalysisUsage(AnalysisUsage &AU) const {
   ScopPass::getAnalysisUsage(AU);
   AU.addRequired<Dependences>();
+  AU.addRequired<DataLayoutPass>();
 }
 Pass *polly::createJSONImporterPass() { return new JSONImporter(); }
 
@@ -360,6 +377,7 @@ INITIALIZE_PASS_BEGIN(JSONImporter, "pol
                       " (Reads a .jscop file for each Scop)",
                       false, false);
 INITIALIZE_PASS_DEPENDENCY(Dependences)
+INITIALIZE_PASS_DEPENDENCY(DataLayoutPass)
 INITIALIZE_PASS_END(JSONImporter, "polly-import-jscop",
                     "Polly - Import Scops from JSON"
                     " (Reads a .jscop file for each Scop)",

Added: polly/trunk/test/Isl/CodeGen/MemAccess/default_aligned_new_access_function.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/MemAccess/default_aligned_new_access_function.ll?rev=219503&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/MemAccess/default_aligned_new_access_function.ll (added)
+++ polly/trunk/test/Isl/CodeGen/MemAccess/default_aligned_new_access_function.ll Fri Oct 10 10:14:29 2014
@@ -0,0 +1,41 @@
+; RUN: opt %loadPolly -basicaa -polly-import-jscop -polly-import-jscop-dir=%S -analyze < %s | FileCheck %s
+;
+; Check that we allow the new access functions even though they access
+; different locations than the original ones (but the alignment is the
+; default, thus there is no problem).
+;
+; CHECK-DAG: New access function '{ Stmt_for_body[i0] -> MemRef_B[0] }'detected in JSCOP file
+; CHECK-DAG: New access function '{ Stmt_for_body[i0] -> MemRef_A[i0] }'detected in JSCOP file
+;
+;    void simple_stride(int *restrict A, int *restrict B) {
+;      for (int i = 0; i < 16; i++)
+;        A[i * 2] = B[i * 2];
+;    }
+;
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @simple_stride(i32* noalias %A, i32* noalias %B) {
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %for.inc, %entry
+  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
+  %exitcond = icmp ne i64 %indvars.iv, 16
+  br i1 %exitcond, label %for.body, label %for.end
+
+for.body:                                         ; preds = %for.cond
+  %tmp = shl nsw i64 %indvars.iv, 1
+  %arrayidx = getelementptr inbounds i32* %B, i64 %tmp
+  %tmp4 = load i32* %arrayidx, align 4
+  %tmp5 = shl nsw i64 %indvars.iv, 1
+  %arrayidx3 = getelementptr inbounds i32* %A, i64 %tmp5
+  store i32 %tmp4, i32* %arrayidx3, align 4
+  br label %for.inc
+
+for.inc:                                          ; preds = %for.body
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  br label %for.cond
+
+for.end:                                          ; preds = %for.cond
+  ret void
+}

Added: polly/trunk/test/Isl/CodeGen/MemAccess/simple_stride___%for.cond---%for.end.jscop
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/MemAccess/simple_stride___%25for.cond---%25for.end.jscop?rev=219503&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/MemAccess/simple_stride___%for.cond---%for.end.jscop (added)
+++ polly/trunk/test/Isl/CodeGen/MemAccess/simple_stride___%for.cond---%for.end.jscop Fri Oct 10 10:14:29 2014
@@ -0,0 +1,21 @@
+{
+   "context" : "{  :  }",
+   "name" : "for.cond => for.end",
+   "statements" : [
+      {
+         "accesses" : [
+            {
+               "kind" : "read",
+               "relation" : "{ Stmt_for_body[i0] -> MemRef_B[0] }"
+            },
+            {
+               "kind" : "write",
+               "relation" : "{ Stmt_for_body[i0] -> MemRef_A[i0] }"
+            }
+         ],
+         "domain" : "{ Stmt_for_body[i0] : i0 >= 0 and i0 <= 15 }",
+         "name" : "Stmt_for_body",
+         "schedule" : "{ Stmt_for_body[i0] -> scattering[0, i0, 0] }"
+      }
+   ]
+}





More information about the llvm-commits mailing list