From 72b82fadc9c81c43d3e34f93fd7f84d7b8c1348b Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 23 Jun 2011 08:59:26 +0200 Subject: [PATCH] isl_qpolynomial_is_equal: also compare spaces and divs Before, isl_qpolynomial_is_equal would only consider the "shape" of the polynomial, meaning that two polynomial living in different spaces could be considered equal. Worse, expressions in terms of different integer divisions could also be considered equal. We now take into account both space and divs so that we no longer produce false positives. Signed-off-by: Sven Verdoolaege --- isl_polynomial.c | 10 ++++++++++ isl_test.c | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/isl_polynomial.c b/isl_polynomial.c index d8beffc..efc6974 100644 --- a/isl_polynomial.c +++ b/isl_polynomial.c @@ -1718,9 +1718,19 @@ error: int isl_qpolynomial_is_equal(__isl_keep isl_qpolynomial *qp1, __isl_keep isl_qpolynomial *qp2) { + int equal; + if (!qp1 || !qp2) return -1; + equal = isl_dim_equal(qp1->dim, qp2->dim); + if (equal < 0 || !equal) + return equal; + + equal = isl_mat_is_equal(qp1->div, qp2->div); + if (equal < 0 || !equal) + return equal; + return isl_upoly_is_equal(qp1->upoly, qp2->upoly); } diff --git a/isl_test.c b/isl_test.c index 01839c3..7e22279 100644 --- a/isl_test.c +++ b/isl_test.c @@ -1635,6 +1635,14 @@ void test_pwqp(struct isl_ctx *ctx) assert(isl_pw_qpolynomial_is_zero(pwqp1)); isl_pw_qpolynomial_free(pwqp1); + + str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }"; + pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str); + pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str); + pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1); + 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) -- 2.7.4