isl_map_{min,max}_multi_pw_aff: set explicit domain to complete domain
authorSven Verdoolaege <sven@cerebras.net>
Fri, 16 Oct 2020 12:40:15 +0000 (16 14:40 +0200)
committerSven Verdoolaege <sven@cerebras.net>
Fri, 30 Oct 2020 20:22:11 +0000 (30 21:22 +0100)
The original code would only take into account the constraints
on the parameters.  This is sufficient for isl_set_{min,max}_multi_pw_aff,
but not for isl_map_{min,max}_multi_pw_aff.
Take into account the complete domain.

Signed-off-by: Sven Verdoolaege <sven@cerebras.net>
isl_opt_mpa_templ.c
isl_test.c

index 84382d3..e424543 100644 (file)
@@ -19,8 +19,8 @@
  * for a single dimension.
  *
  * If the resulting multi piecewise affine expression has
- * an explicit domain, then assign it the parameter domain of the input.
- * In other cases, the parameter domain is stored in the individual elements.
+ * an explicit domain, then assign it the (parameter) domain of the input.
+ * In other cases, the (parameter) domain is stored in the individual elements.
  */
 static __isl_give isl_multi_pw_aff *FN(BASE,opt_mpa)(__isl_take TYPE *obj,
        __isl_give isl_pw_aff *(*opt)(__isl_take TYPE *obj, int pos))
@@ -42,8 +42,8 @@ static __isl_give isl_multi_pw_aff *FN(BASE,opt_mpa)(__isl_take TYPE *obj,
        if (isl_multi_pw_aff_has_explicit_domain(mpa)) {
                isl_set *dom;
 
-               dom = FN(TYPE,params)(FN(TYPE,copy)(obj));
-               mpa = isl_multi_pw_aff_intersect_params(mpa, dom);
+               dom = FN(TYPE,domain)(FN(TYPE,copy)(obj));
+               mpa = isl_multi_pw_aff_intersect_domain(mpa, dom);
        }
        FN(TYPE,free)(obj);
 
index 784ab2e..9b40228 100644 (file)
@@ -10095,6 +10095,48 @@ static isl_stat test_multi_pw_aff_3(isl_ctx *ctx)
        return isl_stat_ok;
 }
 
+/* String descriptions of boxes that
+ * are used for reconstructing box maps from their lower and upper bounds.
+ */
+static const char *multi_pw_aff_box_tests[] = {
+       "{ A[x, y] -> [] : x + y >= 0 }",
+       "[N] -> { A[x, y] -> [x] : x + y <= N }",
+       "[N] -> { A[x, y] -> [x : y] : x + y <= N }",
+};
+
+/* Check that map representations of boxes can be reconstructed
+ * from their lower and upper bounds.
+ */
+static isl_stat test_multi_pw_aff_box(isl_ctx *ctx)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(multi_pw_aff_box_tests); ++i) {
+               const char *str;
+               isl_bool equal;
+               isl_map *map, *box;
+               isl_multi_pw_aff *min, *max;
+
+               str = multi_pw_aff_box_tests[i];
+               map = isl_map_read_from_str(ctx, str);
+               min = isl_map_min_multi_pw_aff(isl_map_copy(map));
+               max = isl_map_max_multi_pw_aff(isl_map_copy(map));
+               box = isl_map_universe(isl_map_get_space(map));
+               box = isl_map_lower_bound_multi_pw_aff(box, min);
+               box = isl_map_upper_bound_multi_pw_aff(box, max);
+               equal = isl_map_is_equal(map, box);
+               isl_map_free(map);
+               isl_map_free(box);
+               if (equal < 0)
+                       return isl_stat_error;
+               if (!equal)
+                       isl_die(ctx, isl_error_unknown,
+                               "unexpected result", return isl_stat_error);
+       }
+
+       return isl_stat_ok;
+}
+
 /* Perform some tests on multi piecewise affine expressions.
  */
 static int test_multi_pw_aff(isl_ctx *ctx)
@@ -10105,6 +10147,8 @@ static int test_multi_pw_aff(isl_ctx *ctx)
                return -1;
        if (test_multi_pw_aff_3(ctx) < 0)
                return -1;
+       if (test_multi_pw_aff_box(ctx) < 0)
+               return -1;
        return 0;
 }