+/* Exploit the equalities in the domain of piece "i" of "pw"
+ * to simplify the associated function.
+ * If the domain of piece "i" is empty, then remove it entirely,
+ * replacing it with the final piece.
+ */
+static int FN(PW,exploit_equalities_and_remove_if_empty)(__isl_keep PW *pw,
+ int i)
+{
+ isl_basic_set *aff;
+ int empty = isl_set_plain_is_empty(pw->p[i].set);
+
+ if (empty < 0)
+ return -1;
+ if (empty) {
+ isl_set_free(pw->p[i].set);
+ FN(EL,free)(pw->p[i].FIELD);
+ if (i != pw->n - 1)
+ pw->p[i] = pw->p[pw->n - 1];
+ pw->n--;
+
+ return 0;
+ }
+
+ aff = isl_set_affine_hull(isl_set_copy(pw->p[i].set));
+ pw->p[i].FIELD = FN(EL,substitute_equalities)(pw->p[i].FIELD, aff);
+ if (!pw->p[i].FIELD)
+ return -1;
+
+ return 0;
+}
+