isl_basic_map_plain_unshifted_simple_hull: drop gauss calls
authorSven Verdoolaege <sven@cerebras.net>
Thu, 13 Feb 2020 14:28:11 +0000 (13 15:28 +0100)
committerSven Verdoolaege <sven@cerebras.net>
Sat, 11 Apr 2020 14:58:34 +0000 (11 16:58 +0200)
It is not clear why those calls were introduced in the first place,
but they may result in some of the integer divisions copied
from the other basic map getting simplified using the equality
constraints.  The integer division expressions in the two basic maps
may therefore no longer be the same.
In particular, a constraint involving the simplified integer division
may appear in the result, while it is not obvious that this constraint
also hold for the other basic map.
In practice, for a constraint involving such an integer division
to appear in the result, it would have to be implied by
one of the two div constraints as those are the only constraints
in the basic map to which the integer division was added that
involve that integer division.
This means only redundant constraints could be added to the result
in this way.  Even though this should be harmless, it is confusing and
it is better not to add such constraints to the result.
Drop the gauss calls to avoid them getting added.

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

index e85d114..44e4ae7 100644 (file)
@@ -2620,8 +2620,6 @@ __isl_give isl_basic_map *isl_basic_map_plain_unshifted_simple_hull(
        bmap2 = isl_basic_map_drop_constraints_involving_unknown_divs(bmap2);
        bmap2 = isl_basic_map_align_divs(bmap2, bmap1);
        bmap1 = isl_basic_map_align_divs(bmap1, bmap2);
-       bmap1 = isl_basic_map_gauss(bmap1, NULL);
-       bmap2 = isl_basic_map_gauss(bmap2, NULL);
        bmap1 = isl_basic_map_sort_constraints(bmap1);
        bmap2 = isl_basic_map_sort_constraints(bmap2);
 
index ae4ae47..16faf73 100644 (file)
@@ -1374,6 +1374,34 @@ int test_affine_hull(struct isl_ctx *ctx)
        return 0;
 }
 
+/* Test a special case of isl_set_plain_unshifted_simple_hull
+ * where older versions of isl would include a redundant constraint
+ * in the result.
+ * Check that the result does not have any constraints.
+ */
+static isl_stat test_plain_unshifted_simple_hull_special(isl_ctx *ctx)
+{
+       const char *str;
+       isl_bool is_universe;
+       isl_set *set;
+       isl_basic_set *bset;
+
+       str = "{[x, y] : x = 0 or 2*((x+y)//2) <= y + 2 }";
+       set = isl_set_read_from_str(ctx, str);
+       bset = isl_set_plain_unshifted_simple_hull(set);
+       is_universe = isl_basic_set_plain_is_universe(bset);
+       isl_basic_set_free(bset);
+
+       if (is_universe < 0)
+               return isl_stat_error;
+       if (!is_universe)
+               isl_die(ctx, isl_error_unknown,
+                       "hull should not have any constraints",
+                       return isl_stat_error);
+
+       return isl_stat_ok;
+}
+
 /* Pairs of maps and the corresponding expected results of
  * isl_map_plain_unshifted_simple_hull.
  */
@@ -1478,6 +1506,8 @@ static int test_simple_hull(struct isl_ctx *ctx)
                isl_die(ctx, isl_error_unknown, "Empty set should be detected",
                        return -1);
 
+       if (test_plain_unshifted_simple_hull_special(ctx) < 0)
+               return -1;
        if (test_plain_unshifted_simple_hull(ctx) < 0)
                return -1;
        if (test_unshifted_simple_hull(ctx) < 0)