Skip to content

Commit

Permalink
isl_map_simplify.c: remove_redundant_divs: drop div constraints of re…
Browse files Browse the repository at this point in the history
…dundant div

The constraints are now being removed by isl_basic_map_drop_div.
Performing the removal directly inside remove_redundant_divs
allows isl_basic_map_drop_div to be simplified and subsequently
merged with the core of isl_basic_map_drop.

isl_basic_map_drop_constraints_involving drops constraints in the
opposite order from isl_basic_map_drop_div, so this can result
in changes because the resulting order of the remaining constraints
may be different.

Signed-off-by: Sven Verdoolaege <[email protected]>
  • Loading branch information
Sven Verdoolaege authored and Sven Verdoolaege committed Aug 28, 2018
1 parent dfc4fe2 commit bb78067
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions isl_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -2833,6 +2833,9 @@ isl_bool isl_set_involves_dims(__isl_keep isl_set *set,
/* Drop all constraints in bmap that involve any of the dimensions
* first to first+n-1.
* This function only performs the actual removal of constraints.
*
* This function should not call finalize since it is used by
* remove_redundant_divs, which in turn is called by isl_basic_map_finalize.
*/
__isl_give isl_basic_map *isl_basic_map_drop_constraints_involving(
__isl_take isl_basic_map *bmap, unsigned first, unsigned n)
Expand Down
8 changes: 6 additions & 2 deletions isl_map_simplify.c
Original file line number Diff line number Diff line change
Expand Up @@ -1463,9 +1463,11 @@ static __isl_give isl_basic_map *remove_redundant_divs(
__isl_take isl_basic_map *bmap)
{
int i;
int v_div;

if (!bmap)
return NULL;
v_div = isl_basic_map_var_offset(bmap, isl_dim_div);
if (v_div < 0)
return isl_basic_map_free(bmap);

for (i = bmap->n_div-1; i >= 0; --i) {
isl_bool redundant;
Expand All @@ -1475,6 +1477,8 @@ static __isl_give isl_basic_map *remove_redundant_divs(
return isl_basic_map_free(bmap);
if (!redundant)
continue;
bmap = isl_basic_map_drop_constraints_involving(bmap,
v_div + i, 1);
bmap = isl_basic_map_drop_div(bmap, i);
}
return bmap;
Expand Down
4 changes: 2 additions & 2 deletions test_inputs/codegen/unroll4.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
write_shared_A(3, ((t1 + 3) % 4) + 1, ((t2 + 31) % 32) + 1);
if (t2 >= 1 && t2 <= 2 && t1 % 3 == 0)
write_shared_A(3, (-t1 / 3) + 4, t2 + 32);
if (((-((t1 + 3) % 4) + t2 + 30) % 32) + t1 >= ((t1 + 3) % 4) + ((t2 + 1) % 2) - 4 * ((-t1 + 4) / 4) + 1)
if (((t1 + 3) % 4) + 1 >= t2 || t2 >= ((t1 + 3) % 4) + ((t2 + 1) % 2) + 2)
write_shared_A(3, ((t1 + 3) % 4) + 5, -((((t1 + 3) % 4) - t2 + 33) % 32) + t1 + 4 * ((-t1 + 4) / 4) + 32);
if (t1 >= 1 && t2 >= t1 + 1 && t2 <= 4)
write_shared_A(3, t1 + 4, t2 + 32);
write_shared_A(4, ((t1 + 3) % 4) + 1, ((t2 + 31) % 32) + 1);
if (t2 >= 1 && t2 <= 2 && t1 % 3 == 0)
write_shared_A(4, (-t1 / 3) + 4, t2 + 32);
if (((-((t1 + 3) % 4) + t2 + 30) % 32) + t1 >= ((t1 + 3) % 4) + ((t2 + 1) % 2) - 4 * ((-t1 + 4) / 4) + 1)
if (((t1 + 3) % 4) + 1 >= t2 || t2 >= ((t1 + 3) % 4) + ((t2 + 1) % 2) + 2)
write_shared_A(4, ((t1 + 3) % 4) + 5, -((((t1 + 3) % 4) - t2 + 33) % 32) + t1 + 4 * ((-t1 + 4) / 4) + 32);
if (t1 >= 1 && t2 >= t1 + 1 && t2 <= 4)
write_shared_A(4, t1 + 4, t2 + 32);
Expand Down

0 comments on commit bb78067

Please sign in to comment.