isl_ast_build_ast_from_schedule: also add stride guard in generic case
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 19 Apr 2013 08:08:11 +0000 (10:08 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 22 Apr 2013 07:38:19 +0000 (09:38 +0200)
Any guard implied by the stride constraint in the AST build domain
needs to be enforced by the generated AST and may not necessarily
be implied by the strided loop itself.
We were already adding this guard to the graft in the degenerate case,
but not in the generic case.

The implied guard is usually already available in loop bounds constraints,
so it is not clear if this fixes any bug that can appear in practice,
However, this may just be a consequence of the internal representation of sets
and we should not depend too much on this internal representation.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_ast_codegen.c

index 8398adb..c09b2e4 100644 (file)
@@ -1148,6 +1148,28 @@ static __isl_give isl_ast_graft *refine_generic_split(
        return graft;
 }
 
+/* Add the guard implied by the current stride constraint (if any),
+ * but not (necessarily) enforced by the generated AST to "graft".
+ */
+static __isl_give isl_ast_graft *add_stride_guard(
+       __isl_take isl_ast_graft *graft, __isl_keep isl_ast_build *build)
+{
+       int depth;
+       isl_set *dom;
+
+       depth = isl_ast_build_get_depth(build);
+       if (!isl_ast_build_has_stride(build, depth))
+               return graft;
+
+       dom = isl_ast_build_get_stride_constraint(build);
+       dom = isl_set_eliminate(dom, isl_dim_set, depth, 1);
+       dom = isl_ast_build_compute_gist(build, dom);
+
+       graft = isl_ast_graft_add_guard(graft, dom, build);
+
+       return graft;
+}
+
 /* Update "graft" based on "bounds" and "domain" for the generic,
  * non-degenerate, case.
  *
@@ -1174,6 +1196,7 @@ static __isl_give isl_ast_graft *refine_generic(
        list = isl_constraint_list_from_basic_set(bounds);
 
        graft = refine_generic_split(graft, list, domain, build);
+       graft = add_stride_guard(graft, build);
 
        isl_constraint_list_free(list);
        return graft;