isl_map_intersect: add special cases for empty input maps
authorSven Verdoolaege <skimo@kotnet.org>
Mon, 5 Apr 2010 17:57:27 +0000 (19:57 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 7 Apr 2010 16:42:31 +0000 (18:42 +0200)
In particular, if both input maps consist of a single basic map
and that of the first map turns out to be empty, then we need
to take into account that after cowing the map, it may not
have any basic maps anymore.

isl_map.c

index 491287a..2992282 100644 (file)
--- a/isl_map.c
+++ b/isl_map.c
@@ -1882,6 +1882,10 @@ static __isl_give isl_map *map_intersect_add_constraint(
        map1 = isl_map_cow(map1);
        if (!map1)
                goto error;
+       if (isl_map_fast_is_empty(map1)) {
+               isl_map_free(map2);
+               return map1;
+       }
        map1->p[0] = isl_basic_map_cow(map1->p[0]);
        if (map2->p[0]->n_eq == 1)
                map1->p[0] = isl_basic_map_add_eq(map1->p[0], map2->p[0]->eq[0]);
@@ -1917,6 +1921,15 @@ struct isl_map *isl_map_intersect(struct isl_map *map1, struct isl_map *map2)
        if (!map1 || !map2)
                goto error;
 
+       if (isl_map_fast_is_empty(map1)) {
+               isl_map_free(map2);
+               return map1;
+       }
+       if (isl_map_fast_is_empty(map2)) {
+               isl_map_free(map1);
+               return map2;
+       }
+
        if (map1->n == 1 && map2->n == 1 &&
            map1->p[0]->n_div == 0 && map2->p[0]->n_div == 0 &&
            isl_dim_equal(map1->dim, map2->dim) &&