From 4446cc0da947cb19650a94df233e4ec063301707 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 16 Jul 2015 20:01:20 +0200 Subject: [PATCH] AST generation: use consistent set of pending constraints The constraints that determine the part of the schedule space for which a (possibly degenerate) loop is generated are first checked to see if they assign a single value in isl_ast_build_set_loop_bounds. This function is also used to keep track of the subset of constraints that do not involve the loop iterator in the "pending" constraints such that they can be added in the guard on the loop after it has been generated. The other constraints are stored in the "generated" constraints. During the actual construction of the for loop, i.e., its initial value and its condition, the constraints not involving the loop iterator are ignored because they are handled by the pending constraints. However, the constraints from which the loop is constructed are simplified before the construction (and after they have been split into pending and generated). This simplification process may not only remove constraints, but may also simplify individual constraints, potentially turning them from "generated" constraints (i.e., those that involve the current loop iterator) to "pending" constraints (i.e., those that do not). The update of pending and generated constraints has been split off into a isl_ast_build_set_pending_generated function in the previous commit. Move the simplification of the constraints before this update such that the same set of pending constraints is used. The fix in 1314871 (AST generation: remove redundant constraints before determining loop bounds, Fri Jul 3 19:05:08 2015 +0200), was essentially dealing with the same problem, but it was only a partial fix. The present fix makes that partial fix redundant, but it does not harm to keep it in. Although the effect of the bug fixed by this commit has been seen in the wild, it is difficult to extract a test case that does not involve extension nodes while extension nodes are not handled by the output verification in pet. Reported-by: Tobias Grosser Signed-off-by: Sven Verdoolaege --- isl_ast_codegen.c | 8 ++++---- test_inputs/codegen/cloog/faber.c | 2 +- test_inputs/codegen/separate2.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/isl_ast_codegen.c b/isl_ast_codegen.c index 0e2a3a3a..e358e121 100644 --- a/isl_ast_codegen.c +++ b/isl_ast_codegen.c @@ -1453,12 +1453,14 @@ static __isl_give isl_ast_graft *create_node_scaled( bounds = isl_ast_build_specialize_basic_set(sub_build, bounds); sub_build = isl_ast_build_set_loop_bounds(sub_build, isl_basic_set_copy(bounds)); - sub_build = isl_ast_build_set_pending_generated(sub_build, - isl_basic_set_copy(bounds)); degenerate = isl_ast_build_has_value(sub_build); eliminated = isl_ast_build_has_affine_value(sub_build, depth); if (degenerate < 0 || eliminated < 0) executed = isl_union_map_free(executed); + if (!degenerate) + bounds = isl_ast_build_compute_gist_basic_set(build, bounds); + sub_build = isl_ast_build_set_pending_generated(sub_build, + isl_basic_set_copy(bounds)); if (eliminated) executed = plug_in_values(executed, sub_build); else @@ -1484,8 +1486,6 @@ static __isl_give isl_ast_graft *create_node_scaled( graft = isl_ast_graft_alloc_from_children(children, isl_set_copy(guard), enforced, build, sub_build); - if (!degenerate) - bounds = isl_ast_build_compute_gist_basic_set(build, bounds); if (!eliminated) { isl_ast_build *for_build; diff --git a/test_inputs/codegen/cloog/faber.c b/test_inputs/codegen/cloog/faber.c index b100b7b3..958a8978 100644 --- a/test_inputs/codegen/cloog/faber.c +++ b/test_inputs/codegen/cloog/faber.c @@ -85,7 +85,7 @@ for (int c2 = max(c1 + 24, -2 * c1 + 30); c2 <= c1 - (3 * c0 + 17) / 14 + 56; c2 += 1) S1(c0, c1, c2); } - if (c0 >= 79 && c0 % 14 >= 9) { + if (c0 >= 70 && c0 % 14 >= 9) { for (int c2 = max((c0 - 70) / 14 + 24, (c0 - 70) / 14 - (3 * c0 + 14) / 14 + 49); c2 <= (c0 - 70) / 14 - (3 * c0 + 17) / 14 + 56; c2 += 1) S1(c0, c0 / 14 - 5, c2); } else if (c0 <= 69 && c0 % 14 >= 9) { diff --git a/test_inputs/codegen/separate2.c b/test_inputs/codegen/separate2.c index 81668215..0fba4f1f 100644 --- a/test_inputs/codegen/separate2.c +++ b/test_inputs/codegen/separate2.c @@ -2,7 +2,7 @@ if ((length - 1) % 16 <= 14) for (int c0 = 0; c0 <= 1; c0 += 1) for (int c5 = 0; c5 <= 31; c5 += 1) for (int c6 = max(0, 2 * ((length - 1) % 16) + 2 * c5 - 60); c6 <= 30; c6 += 1) { - if (length + c5 >= ((length - 1) % 32) + 2 && (length - 1) % 32 >= c5 && 2 * ((length - 1) % 32) + c6 >= 2 * c5 && 2 * c5 + 30 >= 2 * ((length - 1) % 32) + c6 && 2 * ((length - 1) % 32) + c6 == 2 * ((length - 1) % 16) + 2 * c5 && (2 * c5 - c6) % 32 == 0) + if (2 * length + c6 >= 2 * ((length - 1) % 16) + 4 && 2 * ((length - 1) % 16) >= c6 && 2 * ((length - 1) % 16) + 2 * c5 >= c6 && c6 + 62 >= 2 * ((length - 1) % 16) + 2 * c5 && 2 * ((length - 1) % 16) + 2 * c5 == 2 * ((length - 1) % 32) + c6 && (2 * c5 - c6) % 32 == 0) S_3(c0, 0, (c6 / 2) - ((length - 1) % 16) + length - 1); if (length <= 16 && length >= c5 + 1 && c6 >= 1 && length >= c6) S_0(c0, c5, c6 - 1); -- 2.11.4.GIT