From e0a28847a0015ecc1103e6fe4ba00248aff1fda8 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 21 Apr 2015 16:42:04 +0200 Subject: [PATCH] isl_map_subtract: special case obviously equal inputs Signed-off-by: Sven Verdoolaege --- isl_map_subtract.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/isl_map_subtract.c b/isl_map_subtract.c index 4d10cab8..67e78c55 100644 --- a/isl_map_subtract.c +++ b/isl_map_subtract.c @@ -491,16 +491,32 @@ static __isl_give isl_map *basic_map_subtract(__isl_take isl_basic_map *bmap, return sdc.diff; } +/* Return an empty map living in the same space as "map1" and "map2". + */ +static __isl_give isl_map *replace_pair_by_empty( __isl_take isl_map *map1, + __isl_take isl_map *map2) +{ + isl_space *space; + + space = isl_map_get_space(map1); + isl_map_free(map1); + isl_map_free(map2); + return isl_map_empty(space); +} + /* Return the set difference between map1 and map2. * (U_i A_i) \ (U_j B_j) is computed as U_i (A_i \ (U_j B_j)) * + * If "map1" and "map2" are obviously equal to each other, + * then return an empty map in the same space. + * * If "map1" and "map2" are disjoint, then simply return "map1". */ static __isl_give isl_map *map_subtract( __isl_take isl_map *map1, __isl_take isl_map *map2) { int i; - int disjoint; + int equal, disjoint; struct isl_map *diff; if (!map1 || !map2) @@ -508,6 +524,12 @@ static __isl_give isl_map *map_subtract( __isl_take isl_map *map1, isl_assert(map1->ctx, isl_space_is_equal(map1->dim, map2->dim), goto error); + equal = isl_map_plain_is_equal(map1, map2); + if (equal < 0) + goto error; + if (equal) + return replace_pair_by_empty(map1, map2); + disjoint = isl_map_is_disjoint(map1, map2); if (disjoint < 0) goto error; -- 2.11.4.GIT