isl_map_gist: special case universal and equal inputs
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 14 Sep 2012 07:49:58 +0000 (09:49 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Fri, 14 Sep 2012 09:18:07 +0000 (11:18 +0200)
In both these cases, the solution is trivial and we do not need to
go into the regular computation.
Moreover, if the inputs are equal but not convex, then the original
code would not be able to come to the conclusion that the gist
is the universe.

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

index 2a36652..90b36f4 100644 (file)
@@ -2016,11 +2016,49 @@ error:
        return NULL;
 }
 
+/* Return a map that has the same intersection with "context" as "map"
+ * and that as "simple" as possible.
+ *
+ * If "map" is already the universe, then we cannot make it any simpler.
+ * Similarly, if "context" is the universe, then we cannot exploit it
+ * to simplify "map"
+ * If "map" and "context" are identical to each other, then we can
+ * return the corresponding universe.
+ *
+ * If none of these cases apply, we have to work a bit harder.
+ */
 static __isl_give isl_map *map_gist(__isl_take isl_map *map,
        __isl_take isl_map *context)
 {
+       int equal;
+       int is_universe;
+
+       is_universe = isl_map_plain_is_universe(map);
+       if (is_universe >= 0 && !is_universe)
+               is_universe = isl_map_plain_is_universe(context);
+       if (is_universe < 0)
+               goto error;
+       if (is_universe) {
+               isl_map_free(context);
+               return map;
+       }
+
+       equal = isl_map_plain_is_equal(map, context);
+       if (equal < 0)
+               goto error;
+       if (equal) {
+               isl_map *res = isl_map_universe(isl_map_get_space(map));
+               isl_map_free(map);
+               isl_map_free(context);
+               return res;
+       }
+
        context = isl_map_compute_divs(context);
        return isl_map_gist_basic_map(map, isl_map_simple_hull(context));
+error:
+       isl_map_free(map);
+       isl_map_free(context);
+       return NULL;
 }
 
 __isl_give isl_map *isl_map_gist(__isl_take isl_map *map,