isl_tab_basic_map_partial_lexopt: don't normalize intermediate div expressions
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 9 Jun 2012 13:10:04 +0000 (15:10 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Sat, 9 Jun 2012 13:29:36 +0000 (15:29 +0200)
The function get_row_parameter_div would call normalize_div before finishing
the construction of the div expression.  In particular, it would call
normalize_div before negating the coefficients.  Since normalize_div may round
down the constant term, the result of first normalizing and then negating
may result in a different div than first negating and then normalizing.
Call normalize_div only after negating the coefficients.

Reported-by: Alexandre Isoard <alexandre.isoard@ens-lyon.fr>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_tab_pip.c
isl_test.c

index 74564db..dd95d88 100644 (file)
@@ -789,8 +789,8 @@ static struct isl_vec *get_row_parameter_div(struct isl_tab *tab, int row)
 
        isl_int_set(div->el[0], tab->mat->row[row][0]);
        get_row_parameter_line(tab, row, div->el + 1);
-       normalize_div(div);
        isl_seq_neg(div->el + 1, div->el + 1, div->size - 1);
+       normalize_div(div);
        isl_seq_fdiv_r(div->el + 1, div->el + 1, div->el[0], div->size - 1);
 
        return div;
index b81bd94..8bf31f3 100644 (file)
@@ -310,10 +310,12 @@ void test_dim(struct isl_ctx *ctx)
        isl_map_free(map2);
 }
 
-void test_div(struct isl_ctx *ctx)
+static int test_div(isl_ctx *ctx)
 {
+       const char *str;
        isl_int v;
        isl_space *dim;
+       isl_set *set;
        isl_local_space *ls;
        struct isl_basic_set *bset;
        struct isl_constraint *c;
@@ -606,6 +608,16 @@ void test_div(struct isl_ctx *ctx)
        isl_basic_set_free(bset);
 
        isl_int_clear(v);
+
+       str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
+           "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
+       set = isl_set_read_from_str(ctx, str);
+       set = isl_set_compute_divs(set);
+       isl_set_free(set);
+       if (!set)
+               return -1;
+
+       return 0;
 }
 
 void test_application_case(struct isl_ctx *ctx, const char *name)
@@ -2955,6 +2967,7 @@ struct {
        const char *name;
        int (*fn)(isl_ctx *ctx);
 } tests [] = {
+       { "div", &test_div },
        { "slice", &test_slice },
        { "fixed power", &test_fixed_power },
        { "sample", &test_sample },
@@ -3002,7 +3015,6 @@ int main()
        test_bounded(ctx);
        test_construction(ctx);
        test_dim(ctx);
-       test_div(ctx);
        test_application(ctx);
        test_convex_hull(ctx);
        test_gist(ctx);