From 351876525a22320b32e435f6af950a779f7f1aee Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 29 Apr 2015 13:56:42 +0200 Subject: [PATCH] isl_ast_build_expr_from_set_internal: exploit earlier disjuncts When generating constraints for subsequent disjuncts, constraints that only serve to exclude earlier disjuncts do not need to be generated. We currently take the basic sets as they come. We may want to sort them first at some point. Signed-off-by: Sven Verdoolaege --- isl_ast_build_expr.c | 16 ++++++++++++++++ test_inputs/codegen/omega/iter9-0.c | 2 +- test_inputs/codegen/unroll4.c | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/isl_ast_build_expr.c b/isl_ast_build_expr.c index b208b5ab..29eb53fd 100644 --- a/isl_ast_build_expr.c +++ b/isl_ast_build_expr.c @@ -1487,6 +1487,12 @@ __isl_give isl_ast_expr *isl_ast_build_expr_from_basic_set( * * If "set" is an (obviously) empty set, then return the expression "0". * + * If there are multiple disjuncts in the description of the set, + * then subsequent disjuncts are simplified in a context where + * the previous disjuncts have been removed from build->domain. + * In particular, constraints that ensure that there is no overlap + * with these previous disjuncts, can be removed. + * * "set" lives in the internal schedule space. */ __isl_give isl_ast_expr *isl_ast_build_expr_from_set_internal( @@ -1495,6 +1501,7 @@ __isl_give isl_ast_expr *isl_ast_build_expr_from_set_internal( int i, n; isl_basic_set *bset; isl_basic_set_list *list; + isl_set *domain; isl_ast_expr *res; list = isl_set_get_basic_set_list(set); @@ -1509,17 +1516,26 @@ __isl_give isl_ast_expr *isl_ast_build_expr_from_set_internal( return isl_ast_expr_from_val(isl_val_zero(ctx)); } + domain = isl_ast_build_get_domain(build); + bset = isl_basic_set_list_get_basic_set(list, 0); + set = isl_set_from_basic_set(isl_basic_set_copy(bset)); res = isl_ast_build_expr_from_basic_set(build, bset); for (i = 1; i < n; ++i) { isl_ast_expr *expr; + domain = isl_set_subtract(domain, set); bset = isl_basic_set_list_get_basic_set(list, i); + set = isl_set_from_basic_set(isl_basic_set_copy(bset)); + bset = isl_basic_set_gist(bset, + isl_set_simple_hull(isl_set_copy(domain))); expr = isl_ast_build_expr_from_basic_set(build, bset); res = isl_ast_expr_or(res, expr); } + isl_set_free(domain); + isl_set_free(set); isl_basic_set_list_free(list); return res; } diff --git a/test_inputs/codegen/omega/iter9-0.c b/test_inputs/codegen/omega/iter9-0.c index 9b8522ba..4f268a6a 100644 --- a/test_inputs/codegen/omega/iter9-0.c +++ b/test_inputs/codegen/omega/iter9-0.c @@ -6,6 +6,6 @@ for (int c0 = 1; c0 <= 15; c0 += 1) { s2(c0); s1(c0); } - if (((-exprVar1 + 15) % 8) + c0 <= 15 || (c0 >= exprVar1 + 1 && (exprVar1 - c0 + 1) % 8 == 0)) + if (((-exprVar1 + 15) % 8) + c0 <= 15 || (c0 >= 9 && (exprVar1 - c0 + 1) % 8 == 0)) s5(c0); } diff --git a/test_inputs/codegen/unroll4.c b/test_inputs/codegen/unroll4.c index 8e2ac05c..c5dea636 100644 --- a/test_inputs/codegen/unroll4.c +++ b/test_inputs/codegen/unroll4.c @@ -4,7 +4,7 @@ write_shared_A(3, (-t1 / 3) + 4, t2 + 32); { int c3 = t2 >= 2 && ((t1 + 3) % 4) + 1 >= t2 ? t2 + 32 : ((t2 + 30) % 32) + 2; - if (c3 == t2 + 32 || (c3 == t2 && t2 >= ((t1 + 3) % 4) + ((t2 - 1) % 2) + 2)) + if (c3 == t2 + 32 || t2 >= ((t1 + 3) % 4) + ((t2 + 1) % 2) + 2) write_shared_A(3, ((t1 + 3) % 4) + 5, c3); } if (t1 >= 1 && t2 >= t1 + 1 && t2 <= 4) @@ -14,7 +14,7 @@ write_shared_A(4, (-t1 / 3) + 4, t2 + 32); { int c3 = t2 >= 2 && ((t1 + 3) % 4) + 1 >= t2 ? t2 + 32 : ((t2 + 30) % 32) + 2; - if (c3 == t2 + 32 || (c3 == t2 && t2 >= ((t1 + 3) % 4) + ((t2 - 1) % 2) + 2)) + if (c3 == t2 + 32 || t2 >= ((t1 + 3) % 4) + ((t2 + 1) % 2) + 2) write_shared_A(4, ((t1 + 3) % 4) + 5, c3); } if (t1 >= 1 && t2 >= t1 + 1 && t2 <= 4) -- 2.11.4.GIT