[polly] r212198 - Derive run-time conditions for delinearization
Tobias Grosser
tobias at grosser.es
Sun Aug 3 02:56:48 PDT 2014
On 03/08/2014 11:21, Johannes Doerfert wrote:
> What about the patch?
>
> I just replied to an automatic mail to the list when you pushed the patch.
Do you think the attached patch fixes the problem you reported?
Tobias
>
>
> On 08/03, Tobias Grosser wrote:
>> On 03/08/2014 04:20, Johannes Doerfert wrote:
>>> Hey Tobias,
>>>
>>> I think this change introduces an unwanted effect.
>>>
>>> For one dimensional parametric array accesses we add assumptions about the
>>> parameters to ensure we access the array only in a positive range. Is this
>>> intended? I see the point for multidimensional array accesses but why do we
>>> enforce this for one dimensional accesses too?
>>
>> What about the attached patch?
>>
>> Tobias
>>
>
>> From fa0bb6d3c91730219e0bc6b5a8dcbd2a8b06bb19 Mon Sep 17 00:00:00 2001
>> From: Tobias Grosser <tobias at grosser.es>
>> Date: Sun, 3 Aug 2014 09:00:50 +0200
>> Subject: [PATCH] Do allow negative offsets in the outermost array dimension
>>
>> There is no needed for neither 1-dimensional nor higher dimensional arrays to
>> require positive offsets in the outermost array dimension.
>>
>> We originally introduced this assumption with the support for delinearizing
>> multi-dimensional arrays.
>> ---
>> lib/Analysis/ScopInfo.cpp | 35 ++++++--------
>> test/Isl/Ast/simple-run-time-condition.ll | 2 +-
>> .../ScopInfo/multidim_2d_outer_larger_than_zero.ll | 53 ----------------------
>> .../multidim_2d_outer_parametric_offset.ll | 53 ++++++++++++++++++++++
>> .../multidim_ivs_and_parameteric_offsets_3d.ll | 2 +-
>> 5 files changed, 70 insertions(+), 75 deletions(-)
>> delete mode 100644 test/ScopInfo/multidim_2d_outer_larger_than_zero.ll
>> create mode 100644 test/ScopInfo/multidim_2d_outer_parametric_offset.ll
>>
>> diff --git a/lib/Analysis/ScopInfo.cpp b/lib/Analysis/ScopInfo.cpp
>> index aa63e24..1382c1d 100644
>> --- a/lib/Analysis/ScopInfo.cpp
>> +++ b/lib/Analysis/ScopInfo.cpp
>> @@ -366,9 +366,9 @@ isl_basic_map *MemoryAccess::createBasicAccessMap(ScopStmt *Statement) {
>> // expression of each array evaluates for each statement instance that is
>> // executed to a value that is larger than zero and strictly smaller than the
>> // size of the corresponding dimension). The only exception is the outermost
>> -// dimension for which we do not assume any upper bound. At this point we
>> -// formalize this assumption to ensure that at code generation time the relevant
>> -// run-time checks can be generated.
>> +// dimension for which we do not need to assume any upper bound. At this point
>> +// we formalize this assumption to ensure that at code generation time the
>> +// relevant run-time checks can be generated.
>> //
>> // To find the set of constraints necessary to avoid out of bound accesses, we
>> // first build the set of data locations that are not within array bounds. We
>> @@ -383,7 +383,7 @@ isl_basic_map *MemoryAccess::createBasicAccessMap(ScopStmt *Statement) {
>> void MemoryAccess::assumeNoOutOfBound(const IRAccess &Access) {
>> isl_space *Space = isl_space_range(getAccessRelationSpace());
>> isl_set *Outside = isl_set_empty(isl_space_copy(Space));
>> - for (int i = 0, Size = Access.Subscripts.size(); i < Size; ++i) {
>> + for (int i = 1, Size = Access.Subscripts.size(); i < Size; ++i) {
>> isl_local_space *LS = isl_local_space_from_space(isl_space_copy(Space));
>> isl_pw_aff *Var =
>> isl_pw_aff_var_on_domain(isl_local_space_copy(LS), isl_dim_set, i);
>> @@ -391,22 +391,17 @@ void MemoryAccess::assumeNoOutOfBound(const IRAccess &Access) {
>>
>> isl_set *DimOutside;
>>
>> - if (i == 0) {
>> - DimOutside = isl_pw_aff_lt_set(Var, Zero);
>> - } else {
>> - DimOutside = isl_pw_aff_lt_set(isl_pw_aff_copy(Var), Zero);
>> - isl_pw_aff *SizeE =
>> - SCEVAffinator::getPwAff(Statement, Access.Sizes[i - 1]);
>> -
>> - SizeE = isl_pw_aff_drop_dims(SizeE, isl_dim_in, 0,
>> - Statement->getNumIterators());
>> - SizeE = isl_pw_aff_add_dims(SizeE, isl_dim_in,
>> - isl_space_dim(Space, isl_dim_set));
>> - SizeE = isl_pw_aff_set_tuple_id(
>> - SizeE, isl_dim_in, isl_space_get_tuple_id(Space, isl_dim_set));
>> -
>> - DimOutside = isl_set_union(DimOutside, isl_pw_aff_le_set(SizeE, Var));
>> - }
>> + DimOutside = isl_pw_aff_lt_set(isl_pw_aff_copy(Var), Zero);
>> + isl_pw_aff *SizeE = SCEVAffinator::getPwAff(Statement, Access.Sizes[i - 1]);
>> +
>> + SizeE = isl_pw_aff_drop_dims(SizeE, isl_dim_in, 0,
>> + Statement->getNumIterators());
>> + SizeE = isl_pw_aff_add_dims(SizeE, isl_dim_in,
>> + isl_space_dim(Space, isl_dim_set));
>> + SizeE = isl_pw_aff_set_tuple_id(SizeE, isl_dim_in,
>> + isl_space_get_tuple_id(Space, isl_dim_set));
>> +
>> + DimOutside = isl_set_union(DimOutside, isl_pw_aff_le_set(SizeE, Var));
>>
>> Outside = isl_set_union(Outside, DimOutside);
>> }
>> diff --git a/test/Isl/Ast/simple-run-time-condition.ll b/test/Isl/Ast/simple-run-time-condition.ll
>> index 592a72b..8eff8be 100644
>> --- a/test/Isl/Ast/simple-run-time-condition.ll
>> +++ b/test/Isl/Ast/simple-run-time-condition.ll
>> @@ -18,7 +18,7 @@ target triple = "x86_64-unknown-linux-gnu"
>> ; for the delinearization is simplified such that conditions that would not
>> ; cause any code to be executed are not generated.
>>
>> -; CHECK: if ((q == 100 && o <= 0 && p >= 0) || (q == 0 && o >= 1 && p >= 0) ? 1 : 0)
>> +; CHECK: if ((q == 100 && o <= 0) || (q == 0 && o >= 1) ? 1 : 0)
>>
>> ; CHECK: if (o >= 1) {
>> ; CHECK: for (int c1 = 0; c1 < n; c1 += 1)
>> diff --git a/test/ScopInfo/multidim_2d_outer_larger_than_zero.ll b/test/ScopInfo/multidim_2d_outer_larger_than_zero.ll
>> deleted file mode 100644
>> index 0735446..0000000
>> --- a/test/ScopInfo/multidim_2d_outer_larger_than_zero.ll
>> +++ /dev/null
>> @@ -1,53 +0,0 @@
>> -; RUN: opt %loadPolly -polly-scops -analyze -polly-delinearize < %s | 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"
>> -target triple = "x86_64-unknown-linux-gnu"
>> -
>> -; Derived from the following code:
>> -;
>> -; void foo(long n, long m, long p, double A[n][m]) {
>> -; for (long i = 0; i < 100; i++)
>> -; for (long j = 0; j < m; j++)
>> -; A[i+p][j] = 1.0;
>> -; }
>> -
>> -; CHECK: Assumed Context:
>> -; CHECK: [m, p] -> { : p >= 0 }
>> -; CHECK: p0: %m
>> -; CHECK: p1: %p
>> -; CHECK: Statements {
>> -; CHECK: Stmt_for_j
>> -; CHECK: Domain :=
>> -; CHECK: [m, p] -> { Stmt_for_j[i0, i1] : i0 >= 0 and i0 <= 99 and i1 >= 0 and i1 <= -1 + m };
>> -; CHECK: Scattering :=
>> -; CHECK: [m, p] -> { Stmt_for_j[i0, i1] -> scattering[0, i0, 0, i1, 0] };
>> -; CHECK: MustWriteAccess := [Reduction Type: NONE]
>> -; CHECK: [m, p] -> { Stmt_for_j[i0, i1] -> MemRef_A[p + i0, i1] };
>> -; CHECK: }
>> -
>> -define void @foo(i64 %n, i64 %m, i64 %p, double* %A) {
>> -entry:
>> - br label %for.i
>> -
>> -for.i:
>> - %i = phi i64 [ 0, %entry ], [ %i.inc, %for.i.inc ]
>> - %add = add nsw i64 %i, %p
>> - %tmp = mul nsw i64 %add, %m
>> - br label %for.j
>> -
>> -for.j:
>> - %j = phi i64 [ 0, %for.i ], [ %j.inc, %for.j ]
>> - %vlaarrayidx.sum = add i64 %j, %tmp
>> - %arrayidx = getelementptr inbounds double* %A, i64 %vlaarrayidx.sum
>> - store double 1.0, double* %arrayidx
>> - %j.inc = add nsw i64 %j, 1
>> - %j.exitcond = icmp eq i64 %j.inc, %m
>> - br i1 %j.exitcond, label %for.i.inc, label %for.j
>> -
>> -for.i.inc:
>> - %i.inc = add nsw i64 %i, 1
>> - %i.exitcond = icmp eq i64 %i.inc, 100
>> - br i1 %i.exitcond, label %end, label %for.i
>> -
>> -end:
>> - ret void
>> -}
>> diff --git a/test/ScopInfo/multidim_2d_outer_parametric_offset.ll b/test/ScopInfo/multidim_2d_outer_parametric_offset.ll
>> new file mode 100644
>> index 0000000..2c281d0
>> --- /dev/null
>> +++ b/test/ScopInfo/multidim_2d_outer_parametric_offset.ll
>> @@ -0,0 +1,53 @@
>> +; RUN: opt %loadPolly -polly-scops -analyze -polly-delinearize < %s | 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"
>> +target triple = "x86_64-unknown-linux-gnu"
>> +
>> +; Derived from the following code:
>> +;
>> +; void foo(long n, long m, long p, double A[n][m]) {
>> +; for (long i = 0; i < 100; i++)
>> +; for (long j = 0; j < m; j++)
>> +; A[i+p][j] = 1.0;
>> +; }
>> +
>> +; CHECK: Assumed Context:
>> +; CHECK: [m, p] -> { : }
>> +; CHECK: p0: %m
>> +; CHECK: p1: %p
>> +; CHECK: Statements {
>> +; CHECK: Stmt_for_j
>> +; CHECK: Domain :=
>> +; CHECK: [m, p] -> { Stmt_for_j[i0, i1] : i0 >= 0 and i0 <= 99 and i1 >= 0 and i1 <= -1 + m };
>> +; CHECK: Scattering :=
>> +; CHECK: [m, p] -> { Stmt_for_j[i0, i1] -> scattering[0, i0, 0, i1, 0] };
>> +; CHECK: MustWriteAccess := [Reduction Type: NONE]
>> +; CHECK: [m, p] -> { Stmt_for_j[i0, i1] -> MemRef_A[p + i0, i1] };
>> +; CHECK: }
>> +
>> +define void @foo(i64 %n, i64 %m, i64 %p, double* %A) {
>> +entry:
>> + br label %for.i
>> +
>> +for.i:
>> + %i = phi i64 [ 0, %entry ], [ %i.inc, %for.i.inc ]
>> + %add = add nsw i64 %i, %p
>> + %tmp = mul nsw i64 %add, %m
>> + br label %for.j
>> +
>> +for.j:
>> + %j = phi i64 [ 0, %for.i ], [ %j.inc, %for.j ]
>> + %vlaarrayidx.sum = add i64 %j, %tmp
>> + %arrayidx = getelementptr inbounds double* %A, i64 %vlaarrayidx.sum
>> + store double 1.0, double* %arrayidx
>> + %j.inc = add nsw i64 %j, 1
>> + %j.exitcond = icmp eq i64 %j.inc, %m
>> + br i1 %j.exitcond, label %for.i.inc, label %for.j
>> +
>> +for.i.inc:
>> + %i.inc = add nsw i64 %i, 1
>> + %i.exitcond = icmp eq i64 %i.inc, 100
>> + br i1 %i.exitcond, label %end, label %for.i
>> +
>> +end:
>> + ret void
>> +}
>> diff --git a/test/ScopInfo/multidim_ivs_and_parameteric_offsets_3d.ll b/test/ScopInfo/multidim_ivs_and_parameteric_offsets_3d.ll
>> index 7acb778..d77eb9c 100644
>> --- a/test/ScopInfo/multidim_ivs_and_parameteric_offsets_3d.ll
>> +++ b/test/ScopInfo/multidim_ivs_and_parameteric_offsets_3d.ll
>> @@ -15,7 +15,7 @@ target triple = "x86_64-unknown-linux-gnu"
>> ; (8 * %o)}<%for.j>,+,8}<%for.k>
>>
>> ; CHECK: Assumed Context:
>> -; CHECK: [n, m, o, p, q, r] -> { : q = 0 and r = 0 and p >= 0 }
>> +; CHECK: [n, m, o, p, q, r] -> { : q = 0 and r = 0 }
>> ;
>> ; CHECK: p0: %n
>> ; CHECK: p1: %m
>> --
>> 1.8.3.2
>>
>
>
More information about the llvm-commits
mailing list