isl_map_simplify.c: normalize_divs: fix use of variable compression
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 27 Jan 2009 09:48:32 +0000 (10:48 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 4 Feb 2009 11:36:51 +0000 (12:36 +0100)
When there is a div that depends on another div, then we need
to be careful not to look for the other div in the variable
compression matrix.

isl_map_simplify.c
isl_test.c

index b6d891a..b1f874e 100644 (file)
@@ -629,7 +629,8 @@ out:
  *     x'' = T(x') = x_0 + G x'
  *
  * and in constructing the new divs and the corresponding equalities,
- * we have to replace each x'' by the corresponding row from C_2.
+ * we have to replace each x'', i.e., the x'_k with (g_kk = 1),
+ * by the corresponding row from C_2.
  */
 static struct isl_basic_map *normalize_divs(
        struct isl_basic_map *bmap, int *progress)
@@ -758,7 +759,7 @@ static struct isl_basic_map *normalize_divs(
                for (j = 0; j < i; ++j) {
                        if (isl_int_is_zero(T->row[i][j]))
                                continue;
-                       if (C2)
+                       if (pos[j] < T->n_row && C2)
                                isl_seq_submul(bmap->div[k] + 1, T->row[i][j],
                                                C2->row[pos[j]], 1 + total);
                        else
index 8db04a4..9ec4a8a 100644 (file)
@@ -266,6 +266,35 @@ void test_div(struct isl_ctx *ctx)
        assert(bset->n_div == 1);
        isl_basic_set_free(bset);
 
+       /* test 8 */
+       dim = isl_dim_set_alloc(ctx, 0, 4);
+       bset = isl_basic_set_universe(dim);
+
+       c = isl_equality_alloc(isl_dim_copy(bset->dim));
+       isl_int_set_si(v, -1);
+       isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
+       isl_int_set_si(v, -3);
+       isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
+       isl_int_set_si(v, -3);
+       isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
+       div = isl_div_alloc(isl_dim_copy(bset->dim));
+       c = isl_constraint_add_div(c, div, &pos);
+       isl_int_set_si(v, 6);
+       isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
+       bset = isl_basic_set_add_constraint(bset, c);
+
+       c = isl_equality_alloc(isl_dim_copy(bset->dim));
+       isl_int_set_si(v, -1);
+       isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
+       isl_int_set_si(v, 1);
+       isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
+       isl_int_set_si(v, 1);
+       isl_constraint_set_constant(c, v);
+       bset = isl_basic_set_add_constraint(bset, c);
+
+       assert(bset->n_div == 1);
+       isl_basic_set_free(bset);
+
        isl_int_clear(v);
 }