[polly] r296679 - [ScopInfo] Disable memory folding in case it results in multi-disjunct relations

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 1 13:11:28 PST 2017


Author: grosser
Date: Wed Mar  1 15:11:27 2017
New Revision: 296679

URL: http://llvm.org/viewvc/llvm-project?rev=296679&view=rev
Log:
[ScopInfo] Disable memory folding in case it results in multi-disjunct relations

Multi-disjunct access maps can easily result in inbound assumptions which
explode in case of many memory accesses and many parameters. This change reduces
compilation time of some larger kernel from over 15 minutes to less than 16
seconds.

Interesting is the test case test/ScopInfo/multidim_param_in_subscript.ll
which has a memory access

  [n] -> { Stmt_for_body3[i0, i1] -> MemRef_A[i0, -1 + n - i1] }

which requires folding, but where only a single disjunct remains. We can still
model this test case even when only using limited memory folding.

For people only reading commit messages, here the comment that explains what
memory folding is:

To recover memory accesses with array size parameters in the subscript
expression we post-process the delinearization results.

We would normally recover from an access A[exp0(i) * N + exp1(i)] into an
array A[][N] the 2D access A[exp0(i)][exp1(i)]. However, another valid
delinearization is A[exp0(i) - 1][exp1(i) + N] which - depending on the
range of exp1(i) - may be preferrable. Specifically, for cases where we
know exp1(i) is negative, we want to choose the latter expression.

As we commonly do not have any information about the range of exp1(i),
we do not choose one of the two options, but instead create a piecewise
access function that adds the (-1, N) offsets as soon as exp1(i) becomes
negative. For a 2D array such an access function is created by applying
the piecewise map:

[i,j] -> [i, j] :      j >= 0
[i,j] -> [i-1, j+N] :  j <  0

After this patch we generate only the first case, except for situations where
we can proove the first case to be invalid and can consequently select the
second without introducing disjuncts.

Modified:
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/test/Isl/Ast/simple-run-time-condition.ll
    polly/trunk/test/ScopInfo/multidim_fortran_2d_params.ll
    polly/trunk/test/ScopInfo/multidim_ivs_and_parameteric_offsets_3d.ll
    polly/trunk/test/ScopInfo/multidim_param_in_subscript-2.ll

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=296679&r1=296678&r2=296679&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Wed Mar  1 15:11:27 2017
@@ -142,6 +142,11 @@ static cl::opt<bool> PollyPreciseInbound
     cl::desc("Take more precise inbounds assumptions (do not scale well)"),
     cl::Hidden, cl::init(false), cl::cat(PollyCategory));
 
+static cl::opt<bool> PollyPreciseFoldAccesses(
+    "polly-precise-fold-accesses",
+    cl::desc("Fold memory accesses to modele more possible delinearizations "
+             "(do not scale well)"),
+    cl::Hidden, cl::init(false), cl::cat(PollyCategory));
 //===----------------------------------------------------------------------===//
 
 // Create a sequence of two schedules. Either argument may be null and is
@@ -790,6 +795,8 @@ void MemoryAccess::foldAccessRelation()
 
   int Size = Subscripts.size();
 
+  isl_map *OldAccessRelation = isl_map_copy(AccessRelation);
+
   for (int i = Size - 2; i >= 0; --i) {
     isl_space *Space;
     isl_map *MapOne, *MapTwo;
@@ -841,6 +848,18 @@ void MemoryAccess::foldAccessRelation()
   AccessRelation =
       isl_map_set_tuple_id(AccessRelation, isl_dim_out, BaseAddrId);
   AccessRelation = isl_map_gist_domain(AccessRelation, Statement->getDomain());
+
+  // Access dimension folding might in certain cases increase the number of
+  // disjuncts in the memory access, which can possibly complicate the generated
+  // run-time checks and can lead to costly compilation.
+  if (!PollyPreciseFoldAccesses && isl_map_n_basic_map(AccessRelation) >
+                                       isl_map_n_basic_map(OldAccessRelation)) {
+    isl_map_free(AccessRelation);
+    AccessRelation = OldAccessRelation;
+  } else {
+    isl_map_free(OldAccessRelation);
+  }
+
   isl_space_free(Space);
 }
 

Modified: polly/trunk/test/Isl/Ast/simple-run-time-condition.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/Ast/simple-run-time-condition.ll?rev=296679&r1=296678&r2=296679&view=diff
==============================================================================
--- polly/trunk/test/Isl/Ast/simple-run-time-condition.ll (original)
+++ polly/trunk/test/Isl/Ast/simple-run-time-condition.ll Wed Mar  1 15:11:27 2017
@@ -1,4 +1,5 @@
 ; RUN: opt %loadPolly -polly-ast -analyze -polly-precise-inbounds < %s \
+; RUN:                -polly-precise-fold-accesses \
 ; RUN:   | FileCheck %s
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"

Modified: polly/trunk/test/ScopInfo/multidim_fortran_2d_params.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/multidim_fortran_2d_params.ll?rev=296679&r1=296678&r2=296679&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/multidim_fortran_2d_params.ll (original)
+++ polly/trunk/test/ScopInfo/multidim_fortran_2d_params.ll Wed Mar  1 15:11:27 2017
@@ -1,4 +1,5 @@
 ; RUN: opt %loadPolly -polly-scops -analyze \
+; RUN: -polly-precise-fold-accesses \
 ; RUN: -polly-invariant-load-hoisting=true < %s | FileCheck %s
 
 ;   subroutine init_array(ni, nj, pi, pj, a)

Modified: polly/trunk/test/ScopInfo/multidim_ivs_and_parameteric_offsets_3d.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/multidim_ivs_and_parameteric_offsets_3d.ll?rev=296679&r1=296678&r2=296679&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/multidim_ivs_and_parameteric_offsets_3d.ll (original)
+++ polly/trunk/test/ScopInfo/multidim_ivs_and_parameteric_offsets_3d.ll Wed Mar  1 15:11:27 2017
@@ -1,4 +1,5 @@
-; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-scops -analyze < %s \
+; RUN:     -polly-precise-fold-accesses | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
 
 ; void foo(long n, long m, long o, double A[n][m][o], long p, long q, long r) {

Modified: polly/trunk/test/ScopInfo/multidim_param_in_subscript-2.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/multidim_param_in_subscript-2.ll?rev=296679&r1=296678&r2=296679&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/multidim_param_in_subscript-2.ll (original)
+++ polly/trunk/test/ScopInfo/multidim_param_in_subscript-2.ll Wed Mar  1 15:11:27 2017
@@ -1,4 +1,5 @@
-; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-scops -analyze \
+; RUN:  -polly-precise-fold-accesses  < %s | FileCheck %s
 ;
 ;    void foo(long n, long m, float A[][n][m]) {
 ;      for (long i = 0; i < 100; i++)




More information about the llvm-commits mailing list