isl_basic_map_drop_redundant_divs: don't drop divs that appear in other divs
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 22 Aug 2012 12:41:43 +0000 (14:41 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 3 Sep 2012 13:43:16 +0000 (15:43 +0200)
Divs that appear in the definition of other divs usually occur in at least
4 constraints, so they normally wouldn't get dropped by this function.
However, the div constraints of the other div(s) may have been simplified
or eliminated.  This happens in particular on the new test case
due to the optimization introduced in 2592280 (isl_basic_map_simplify:
eliminate known divs that appear with unit coefficient,
Wed May 16 13:51:16 2012 +0200).

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

index d926859..c209867 100644 (file)
@@ -2598,7 +2598,7 @@ static struct isl_basic_map *coalesce_or_drop_more_redundant_divs(
 /* Remove divs that are not strictly needed.
  * In particular, if a div only occurs positively (or negatively)
  * in constraints, then it can simply be dropped.
- * Also, if a div occurs only occurs in two constraints and if moreover
+ * Also, if a div occurs in only two constraints and if moreover
  * those two constraints are opposite to each other, except for the constant
  * term and if the sum of the constant terms is such that for any value
  * of the other values, there is always at least one integer value of the
@@ -2606,6 +2606,10 @@ static struct isl_basic_map *coalesce_or_drop_more_redundant_divs(
  * the (absolute value) of the coefficent of the div in the constraints,
  * then we can also simply drop the div.
  *
+ * We skip divs that appear in equalities or in the definition of other divs.
+ * Divs that appear in the definition of other divs usually occur in at least
+ * 4 constraints, but the constraints may have been simplified.
+ *
  * If any divs are left after these simple checks then we move on
  * to more complicated cases in drop_more_redundant_divs.
  */
@@ -2632,6 +2636,11 @@ struct isl_basic_map *isl_basic_map_drop_redundant_divs(
                int defined;
 
                defined = !isl_int_is_zero(bmap->div[i][0]);
+               for (j = i; j < bmap->n_div; ++j)
+                       if (!isl_int_is_zero(bmap->div[j][1 + 1 + off + i]))
+                               break;
+               if (j < bmap->n_div)
+                       continue;
                for (j = 0; j < bmap->n_eq; ++j)
                        if (!isl_int_is_zero(bmap->eq[j][1 + off + i]))
                                break;
index 931459c..9e8f155 100644 (file)
@@ -2019,6 +2019,16 @@ struct {
          "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
                "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
                "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
+       { "{ [65] }",
+         "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
+               "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
+               "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
+                   "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
+                   "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
+                   "256e0 <= 255i and 256e0 >= -255 + 255i and "
+                   "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
+                   "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
+                   "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
 };
 
 static int test_subset(isl_ctx *ctx)