isl_ast_codegen.c: update_unrolling_lower_bound: check for overflow
authorSven Verdoolaege <skimo@kotnet.org>
Mon, 15 Apr 2013 10:55:59 +0000 (12:55 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Mon, 15 Apr 2013 12:03:39 +0000 (14:03 +0200)
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 <tobias@grosser.es>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_ast_codegen.c
test_inputs/codegen/unroll6.c [new file with mode: 0644]
test_inputs/codegen/unroll6.in [new file with mode: 0644]

index 9d94bce..aae71b4 100644 (file)
@@ -7,6 +7,7 @@
  * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
  */
 
+#include <limits.h>
 #include <isl/aff.h>
 #include <isl/set.h>
 #include <isl/ilp.h>
@@ -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 (file)
index 0000000..f5e6982
--- /dev/null
@@ -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 (file)
index 0000000..b4338e3
--- /dev/null
@@ -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] }