From f7f38c2aca61e13373581df7a2194ccc94ebda75 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 15 Apr 2013 12:55:59 +0200 Subject: [PATCH] isl_ast_codegen.c: update_unrolling_lower_bound: check for overflow If the number of slices along a given lower bound exceeds the maximal value of an integer, then it would mistakenly be replaced by its least signficant bits, resulting in slices being dropped if the lower bound ends up being selected as the best (based on the wrong number). If the number of slices really exceeds the maximal value of an integer, then we do not want to honor the request of the user anyway. We should probably set an even smaller limit. Reported-by: Tobias Grosser Signed-off-by: Sven Verdoolaege --- isl_ast_codegen.c | 4 +++- test_inputs/codegen/unroll6.c | 8 ++++++++ test_inputs/codegen/unroll6.in | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test_inputs/codegen/unroll6.c create mode 100644 test_inputs/codegen/unroll6.in diff --git a/isl_ast_codegen.c b/isl_ast_codegen.c index 9d94bce8..aae71b45 100644 --- a/isl_ast_codegen.c +++ b/isl_ast_codegen.c @@ -7,6 +7,7 @@ * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France */ +#include #include #include #include @@ -2090,7 +2091,8 @@ static int update_unrolling_lower_bound(struct isl_find_unroll_data *data, return 0; } - if (!data->lower || isl_int_cmp_si(data->tmp, *data->n) < 0) { + if (isl_int_cmp_si(data->tmp, INT_MAX) <= 0 && + (!data->lower || isl_int_cmp_si(data->tmp, *data->n) < 0)) { isl_aff_free(data->lower); data->lower = lower; *data->n = isl_int_get_si(data->tmp); diff --git a/test_inputs/codegen/unroll6.c b/test_inputs/codegen/unroll6.c new file mode 100644 index 00000000..f5e6982c --- /dev/null +++ b/test_inputs/codegen/unroll6.c @@ -0,0 +1,8 @@ +{ + if (((-t1 + 128) % 128) + nn >= 128 * g + 130 && 128 * g + 127 >= (-t1 + 128) % 128 && nn >= 128 * g + 6) + for (int c1 = 393214; c1 < nn - 1; c1 += 393216) + A(c1, ((t1 + 127) % 128) + 128 * g + 1, ((t1 + 127) % 128) + 1); + if (nn >= t1 + 128 * g + 130 && t1 + 128 * g + 127 >= 0 && t1 <= 2 && t1 >= 1) + for (int c1 = 393214; c1 < nn - 1; c1 += 393216) + A(c1, t1 + 128 * g + 128, t1 + 128); +} diff --git a/test_inputs/codegen/unroll6.in b/test_inputs/codegen/unroll6.in new file mode 100644 index 00000000..b4338e33 --- /dev/null +++ b/test_inputs/codegen/unroll6.in @@ -0,0 +1,7 @@ +# Check that the right lower bound is chosen for unrolling. +# Older versions of isl would pick a lower bound that resulted +# in a number of slices that exceeds the maximal value of an integer +# and then only generated code for a truncated number (zero) of slices. +[nn, t1, g] -> { A[a, b, c] -> [c] : exists (e0 = [(2 + a)/393216], e1 = [(t1 - c)/128]: 128g = b - c and 393216e0 = 2 + a and 128e1 = t1 - c and c <= 130 and c >= 6 - nn + b and c <= 128 + b and nn >= 137 and t1 >= 0 and c >= 1 and a <= -2 + nn and a >= 1 and nn <= 9223372036854775807 and b >= 1 and b <= -2 + nn and t1 <= 127) } +[nn, t1, g] -> { : nn <= 9223372036854775807 and nn >= 137 and t1 >= 0 and t1 <= 127 } +{ [c] -> unroll[x] } -- 2.11.4.GIT