[polly][PATCH] Derive run-time conditions for delinearization

Tobias Grosser tobias at grosser.es
Fri Jun 27 11:22:15 PDT 2014


On 27/06/2014 15:01, Sebastian Pop wrote:
>> --- a/test/ScopInfo/multidim_ivs_and_parameteric_offsets_3d.ll
>> +++ b/test/ScopInfo/multidim_ivs_and_parameteric_offsets_3d.ll
>> @@ -13,3 +13,14 @@ target triple = "x86_64-unknown-linux-gnu"
>>   ; Access function:
>>   ;    {{{((8 * ((((%m * %p) + %q) * %o) + %r)) + %A),+,(8 * %m * %o)}<%for.i>,+,
>>   ;        (8 * %o)}<%for.j>,+,8}<%for.k>
>> +
>> +
>> +; The context constraints generated here are correct, but rather verbose.
>> +; Specifically, cases like 'o <= 0' mean that in case we do not execute
>> +; any statement iteration we obviously do not break any bound checks. However,
>> +; as we anyway don't execute any code in this case, there is no need to
>> +; create a check here that pontentially slows down the common case where o is
>> +; actually positive.
>
> Agreed: Can we filter out all these o <= 0 constraints?

I now gist simplify with the parameter domain of the iteration spaces. 
This removes all unnecessary checks. As it took me some time to get some 
degree of confidence that this is correct, I would appreciate if you 
look again over my code and the related comments.

>> +
>> +; CHECK: Assumed Context:
>> +; CHECK: [o, m, n, r, q, p] -> { : m <= 0 or (m >= 1 and n <= 0 and p <= -1) or (o <= 0 and m >= 1 and p >= 0) or (o >= 1 and m >= 1 and n <= 0 and p >= 0) or (o <= 0 and m >= 1 and n >= 1 and p <= -1) or (r = 0 and q = 0 and o >= 1 and m >= 1 and n >= 1 and p >= 0) }
>
> Also, we should add a bound on the number of run-time checks we insert.
> The size of the generated checks should be linear in number of parameters.

As the constraints are now very simple, I did not do this yet. Let's get 
back to this if we actually find cases that cause complicated constraints.

>> +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) {
>> +    isl_local_space *LS = isl_local_space_from_space(isl_space_copy(Space));
>> +    isl_pw_aff *Var = isl_pw_aff_from_aff(
>> +        isl_aff_var_on_domain(isl_local_space_copy(LS), isl_dim_set, i));
>
> Why not just
>    isl_pw_aff *Var = isl_pw_aff_var_on_domain(
>        isl_local_space_copy(LS), isl_dim_set, i);

Fixed.

>> +    isl_pw_aff *Zero = isl_pw_aff_zero_on_domain(LS);
>> +
>> +    isl_set *DimOutside;
>> +    DimOutside = isl_pw_aff_lt_set(isl_pw_aff_copy(Var), Zero);
>> +    if (i > 0) {
>> +      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));
>> +    } else {
>> +      isl_pw_aff_free(Var);
>> +    }
>
> Turn the if clauses around to have the shortest then clause,
> and avoid one copy/free of Var:
>
> if (i == 0) {
>    DimOutside = isl_pw_aff_lt_set(Var, Zero);
> } else {
>    DimOutside = isl_pw_aff_lt_set(isl_pw_aff_copy(Var), Zero);
>    ...
> }

Fixed.

Cheers,
Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Derive-run-time-conditions-for-delinearization.patch
Type: text/x-patch
Size: 33804 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140627/cbfe078a/attachment.bin>


More information about the llvm-commits mailing list