isl_pw_multi_aff_drop_dims: fix dropping of output dimensions
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 14 Feb 2013 17:53:43 +0000 (18:53 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 14 Feb 2013 20:39:00 +0000 (21:39 +0100)
Most isl_pw_*_drop_dims functions don't support dropping of output dimensions
because their pieces have a fixed single output dimension.
However, the pieces of isl_pw_multi_* objects do support dropping of output
dimensions and therefore so should the isl_pw_multi_*_drop_dims functions.

We simply need to skip dropping dimensions from the domains.
The original code would leave the result in an inconsistent state.

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

index f112fc0..3993974 100644 (file)
@@ -983,12 +983,14 @@ __isl_give PW *FN(PW,drop_dims)(__isl_take PW *pw,
        if (!pw->dim)
                goto error;
        for (i = 0; i < pw->n; ++i) {
-               pw->p[i].set = isl_set_drop(pw->p[i].set, set_type, first, n);
-               if (!pw->p[i].set)
-                       goto error;
                pw->p[i].FIELD = FN(EL,drop_dims)(pw->p[i].FIELD, type, first, n);
                if (!pw->p[i].FIELD)
                        goto error;
+               if (type == isl_dim_out)
+                       continue;
+               pw->p[i].set = isl_set_drop(pw->p[i].set, set_type, first, n);
+               if (!pw->p[i].set)
+                       goto error;
        }
 
        return pw;
index f0aee84..82fa8d2 100644 (file)
@@ -3750,10 +3750,40 @@ static int test_ast_gen(isl_ctx *ctx)
        return 0;
 }
 
+/* Check if dropping output dimensions from an isl_pw_multi_aff
+ * works properly.
+ */
+static int test_pw_multi_aff(isl_ctx *ctx)
+{
+       const char *str;
+       isl_pw_multi_aff *pma1, *pma2;
+       int equal;
+
+       str = "{ [i,j] -> [i+j, 4i-j] }";
+       pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
+       str = "{ [i,j] -> [4i-j] }";
+       pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
+
+       pma1 = isl_pw_multi_aff_drop_dims(pma1, isl_dim_out, 0, 1);
+
+       equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
+
+       isl_pw_multi_aff_free(pma1);
+       isl_pw_multi_aff_free(pma2);
+       if (equal < 0)
+               return -1;
+       if (!equal)
+               isl_die(ctx, isl_error_unknown,
+                       "expressions not equal", return -1);
+
+       return 0;
+}
+
 struct {
        const char *name;
        int (*fn)(isl_ctx *ctx);
 } tests [] = {
+       { "piecewise multi affine expressions", &test_pw_multi_aff },
        { "conversion", &test_conversion },
        { "list", &test_list },
        { "align parameters", &test_align_parameters },