isl_qpolynomial: properly merge identical nested divs
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 2 Dec 2010 16:56:09 +0000 (17:56 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 7 Dec 2010 09:40:16 +0000 (10:40 +0100)
When sort_divs encounters two identical that appear nested
inside some other div, it would simply drop one of the identical
divs, instead of summing the coefficients of both divs.

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

index 8acfa98..92e8b2f 100644 (file)
@@ -1142,6 +1142,8 @@ static __isl_give isl_qpolynomial *sort_divs(__isl_take isl_qpolynomial *qp)
                    isl_seq_eq(qp->div->row[i - skip - 1],
                               qp->div->row[i - skip], qp->div->n_col)) {
                        qp->div = isl_mat_drop_rows(qp->div, i - skip, 1);
+                       isl_mat_col_add(qp->div, 2 + div_pos + i - skip - 1,
+                                                2 + div_pos + i - skip);
                        qp->div = isl_mat_drop_cols(qp->div,
                                                    2 + div_pos + i - skip, 1);
                        skip++;
@@ -1700,6 +1702,8 @@ __isl_give isl_qpolynomial *isl_qpolynomial_div_pow(__isl_take isl_div *div,
 
        isl_div_free(div);
 
+       qp = sort_divs(qp);
+
        return qp;
 error:
        isl_qpolynomial_free(qp);
index e64ef43..858a902 100644 (file)
@@ -1480,6 +1480,17 @@ void test_pwqp(struct isl_ctx *ctx)
        assert(isl_pw_qpolynomial_is_zero(pwqp1));
 
        isl_pw_qpolynomial_free(pwqp1);
+
+       str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
+       pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
+       str = "{ [i] -> ([(2 * [i/2])/5]) }";
+       pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
+
+       pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
+
+       assert(isl_pw_qpolynomial_is_zero(pwqp1));
+
+       isl_pw_qpolynomial_free(pwqp1);
 }
 
 void test_split_periods(isl_ctx *ctx)