isl_pw_aff_non_zero_set: don't assume isl_pw_aff is total
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 17 Jan 2012 12:52:09 +0000 (13:52 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 18 Jan 2012 17:40:11 +0000 (18:40 +0100)
Before, we would return the domain where the function is not zero
or undefined, whereas we should only return the domain where the function
is not zero.

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

index 42000ce..ca86174 100644 (file)
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -1478,9 +1478,11 @@ __isl_give isl_set *isl_pw_aff_nonneg_set(__isl_take isl_pw_aff *pwaff)
 }
 
 /* Return a set containing those elements in the domain
- * of pwaff where it is zero.
+ * of pwaff where it is zero (if complement is 0) or not zero
+ * (if complement is 1).
  */
-__isl_give isl_set *isl_pw_aff_zero_set(__isl_take isl_pw_aff *pwaff)
+static __isl_give isl_set *pw_aff_zero_set(__isl_take isl_pw_aff *pwaff,
+       int complement)
 {
        int i;
        isl_set *set;
@@ -1492,11 +1494,15 @@ __isl_give isl_set *isl_pw_aff_zero_set(__isl_take isl_pw_aff *pwaff)
 
        for (i = 0; i < pwaff->n; ++i) {
                isl_basic_set *bset;
-               isl_set *set_i;
+               isl_set *set_i, *zero;
 
                bset = isl_aff_zero_basic_set(isl_aff_copy(pwaff->p[i].aff));
-               set_i = isl_set_from_basic_set(bset);
-               set_i = isl_set_intersect(set_i, isl_set_copy(pwaff->p[i].set));
+               zero = isl_set_from_basic_set(bset);
+               set_i = isl_set_copy(pwaff->p[i].set);
+               if (complement)
+                       set_i = isl_set_subtract(set_i, zero);
+               else
+                       set_i = isl_set_intersect(set_i, zero);
                set = isl_set_union_disjoint(set, set_i);
        }
 
@@ -1506,11 +1512,19 @@ __isl_give isl_set *isl_pw_aff_zero_set(__isl_take isl_pw_aff *pwaff)
 }
 
 /* Return a set containing those elements in the domain
+ * of pwaff where it is zero.
+ */
+__isl_give isl_set *isl_pw_aff_zero_set(__isl_take isl_pw_aff *pwaff)
+{
+       return pw_aff_zero_set(pwaff, 0);
+}
+
+/* Return a set containing those elements in the domain
  * of pwaff where it is not zero.
  */
 __isl_give isl_set *isl_pw_aff_non_zero_set(__isl_take isl_pw_aff *pwaff)
 {
-       return isl_set_complement(isl_pw_aff_zero_set(pwaff));
+       return pw_aff_zero_set(pwaff, 1);
 }
 
 /* Return a set containing those elements in the shared domain