Merge branch 'maint'
[platform/upstream/isl.git] / isl_pw_templ.c
index ed19733..6a941c5 100644 (file)
@@ -371,14 +371,14 @@ static __isl_give PW *FN(PW,union_add_aligned)(__isl_take PW *pw1,
                for (j = 0; j < pw2->n; ++j) {
                        struct isl_set *common;
                        EL *sum;
-                       set = isl_set_subtract(set,
-                                       isl_set_copy(pw2->p[j].set));
                        common = isl_set_intersect(isl_set_copy(pw1->p[i].set),
                                                isl_set_copy(pw2->p[j].set));
                        if (isl_set_plain_is_empty(common)) {
                                isl_set_free(common);
                                continue;
                        }
+                       set = isl_set_subtract(set,
+                                       isl_set_copy(pw2->p[j].set));
 
                        sum = FN(EL,add_on_domain)(common,
                                                   FN(EL,copy)(pw1->p[i].FIELD),
@@ -554,6 +554,7 @@ static __isl_give PW *FN(PW,on_shared_domain)(__isl_take PW *pw1,
 
                        res_ij = fn(FN(EL,copy)(pw1->p[i].FIELD),
                                    FN(EL,copy)(pw2->p[j].FIELD));
+                       res_ij = FN(EL,gist)(res_ij, isl_set_copy(common));
 
                        res = FN(PW,add_piece)(res, common, res_ij);
                }
@@ -1303,6 +1304,11 @@ error:
 }
 #endif
 
+int FN(PW,n_piece)(__isl_keep PW *pw)
+{
+       return pw ? pw->n : 0;
+}
+
 int FN(PW,foreach_piece)(__isl_keep PW *pw,
        int (*fn)(__isl_take isl_set *set, __isl_take EL *el, void *user),
        void *user)