isl_aff.c: extract out isl_basic_map_try_find_output_div_mod
authorSven Verdoolaege <sven@cerebras.net>
Thu, 9 Feb 2023 21:38:57 +0000 (9 22:38 +0100)
committerSven Verdoolaege <sven@cerebras.net>
Sat, 11 May 2024 13:06:58 +0000 (11 15:06 +0200)
This will be reused by isl_tab_basic_map_partial_lexopt*
in an upcoming commit.

Signed-off-by: Sven Verdoolaege <sven@cerebras.net>
isl_aff.c

index 5173ee4..683e3f3 100644 (file)
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -5413,6 +5413,22 @@ error:
        return res;
 }
 
+/* Look for a combination of constraints in "bmap" that ensure
+ * that output dimension "pos" is equal to some integer division or
+ * modulo expression in the parameters and input dimensions and
+ * return this expression if found.
+ */
+__isl_give isl_maybe_isl_aff isl_basic_map_try_find_output_div_mod(
+       __isl_keep isl_basic_map *bmap, int pos)
+{
+       isl_maybe_isl_aff div;
+
+       div = isl_basic_map_try_find_output_div(bmap, pos);
+       if (div.valid < 0 || div.valid)
+               return div;
+       return isl_basic_map_try_find_output_mod(bmap, pos);
+}
+
 /* Try and create an isl_pw_multi_aff that is equivalent to the given isl_map.
  *
  * As a special case, we first check if there is any pair of constraints,
@@ -5440,9 +5456,7 @@ static __isl_give isl_pw_multi_aff *pw_multi_aff_from_map_check_div_mod(
        for (d = 0; d < dim; ++d) {
                isl_maybe_isl_aff sub;
 
-               sub = isl_basic_map_try_find_output_div(hull, d);
-               if (sub.valid >= 0 && !sub.valid)
-                       sub = isl_basic_map_try_find_output_mod(hull, d);
+               sub = isl_basic_map_try_find_output_div_mod(hull, d);
                if (sub.valid < 0)
                        goto error;
                if (!sub.valid)