[polly][PATCH] Derive run-time conditions for delinearization
Sebastian Pop
sebpop at gmail.com
Fri Jun 27 06:01:15 PDT 2014
> --- 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?
> +
> +; 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.
> +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);
> + 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);
...
}
> + Outside = isl_set_union(Outside, DimOutside);
> + }
> +
> + Outside = isl_set_apply(Outside, isl_map_reverse(getAccessRelation()));
> + Outside = isl_set_intersect(Outside, Statement->getDomain());
> + Outside = isl_set_params(Outside);
> + Outside = isl_set_complement(Outside);
> + Statement->getParent()->addAssumption(Outside);
> + isl_space_free(Space);
> +}
More information about the llvm-commits
mailing list