From: Sven Verdoolaege Date: Mon, 15 Apr 2013 10:55:59 +0000 (+0200) Subject: isl_ast_codegen.c: update_unrolling_lower_bound: check for overflow X-Git-Tag: isl-0.12~14^2~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f7f38c2aca61e13373581df7a2194ccc94ebda75;p=platform%2Fupstream%2Fisl.git 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 --- diff --git a/isl_ast_codegen.c b/isl_ast_codegen.c index 9d94bce..aae71b4 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 0000000..f5e6982 --- /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 0000000..b4338e3 --- /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] }