From c292a3c9e8eaaae427abdfb0964c86767f3a390a Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 13 Aug 2012 18:42:04 +0200 Subject: [PATCH] isl_map_subtract: handle duplicate divs in subtrahend A simplified basic map is not expected to have duplicate divs, but it may still happen if a div is discovered by isl_basic_map_gauss without subsequently being compared to other divs. Signed-off-by: Sven Verdoolaege --- isl_map_subtract.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/isl_map_subtract.c b/isl_map_subtract.c index d43cf3d0..f5ed8d65 100644 --- a/isl_map_subtract.c +++ b/isl_map_subtract.c @@ -14,6 +14,17 @@ #include "isl_tab.h" #include +/* Expand the constraint "c" into "v". The initial "dim" dimensions + * are the same, but "v" may have more divs than "c" and the divs of "c" + * may appear in different positions in "v". + * The number of divs in "c" is given by "n_div" and the mapping + * of divs in "c" to divs in "v" is given by "div_map". + * + * Although it shouldn't happen in practice, it is theoretically + * possible that two or more divs in "c" are mapped to the same div in "v". + * These divs are then necessarily the same, so we simply add their + * coefficients. + */ static void expand_constraint(isl_vec *v, unsigned dim, isl_int *c, int *div_map, unsigned n_div) { @@ -22,8 +33,10 @@ static void expand_constraint(isl_vec *v, unsigned dim, isl_seq_cpy(v->el, c, 1 + dim); isl_seq_clr(v->el + 1 + dim, v->size - (1 + dim)); - for (i = 0; i < n_div; ++i) - isl_int_set(v->el[1 + dim + div_map[i]], c[1 + dim + i]); + for (i = 0; i < n_div; ++i) { + int pos = 1 + dim + div_map[i]; + isl_int_add(v->el[pos], v->el[pos], c[1 + dim + i]); + } } /* Add all constraints of bmap to tab. The equalities of bmap -- 2.11.4.GIT