isl_schedule_node_order_{before,after}: return original node on empty filters
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 4 Feb 2016 11:29:25 +0000 (4 12:29 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 8 Feb 2016 10:46:07 +0000 (8 11:46 +0100)
isl_schedule_node_order_before and isl_schedule_node_order_after are
documented as returning the original node when the filter turns out
to be empty.  In case the node is part of a sequence, the parent
would get returned instead.  Fix this to always return the original
node in case of an empty filter.

As a side-effect, the domain that is used to compute the complement
of the filter is now obtained from the original node instead
of the parent (in case the original is part of a sequence).
This reduces the risk of running into an unfiltered extension node
while extracting the domain.

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

index 6674c5b..49c739e 100644 (file)
@@ -4308,7 +4308,7 @@ static __isl_give isl_schedule_node *isl_schedule_node_order_before_or_after(
 {
        enum isl_schedule_node_type ancestors[] =
                { isl_schedule_node_filter, isl_schedule_node_sequence };
-       isl_union_set *node_domain, *node_filter = NULL;
+       isl_union_set *node_domain, *node_filter = NULL, *parent_filter;
        isl_schedule_node *node2;
        isl_schedule_tree *tree1, *tree2;
        int empty1, empty2;
@@ -4322,8 +4322,6 @@ static __isl_give isl_schedule_node *isl_schedule_node_order_before_or_after(
        in_seq = has_ancestors(node, 2, ancestors);
        if (in_seq < 0)
                goto error;
-       if (in_seq)
-               node = isl_schedule_node_parent(node);
        node_domain = isl_schedule_node_get_domain(node);
        filter = isl_union_set_gist(filter, isl_union_set_copy(node_domain));
        node_filter = isl_union_set_copy(node_domain);
@@ -4340,6 +4338,14 @@ static __isl_give isl_schedule_node *isl_schedule_node_order_before_or_after(
                return node;
        }
 
+       if (in_seq) {
+               node = isl_schedule_node_parent(node);
+               parent_filter = isl_schedule_node_filter_get_filter(node);
+               node_filter = isl_union_set_intersect(node_filter,
+                                           isl_union_set_copy(parent_filter));
+               filter = isl_union_set_intersect(filter, parent_filter);
+       }
+
        node2 = isl_schedule_node_copy(node);
        node = isl_schedule_node_gist(node, isl_union_set_copy(node_filter));
        node2 = isl_schedule_node_gist(node2, isl_union_set_copy(filter));