From patchwork Mon Dec 13 13:40:26 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [PR46761] graphite: fix testing of boundary wrapping From: Alexander Monakov X-Patchwork-Id: 75353 Message-Id: To: gcc-patches@gcc.gnu.org Cc: Sebastian Pop Date: Mon, 13 Dec 2010 16:40:26 +0300 (MSK) Hi, As indicated by the testcase, sometimes Graphite would generate wrong region guards if UB_ONE overflows, but does not become zero (i.e. it is signed). The patch changes the corresponding test to use TREE_OVERFLOW flag. Bootstrapped and regtested on x86_64-linux, OK for trunk? 2010-12-13 Alexander Monakov PR middle-end/46761 * graphite-clast-to-gimple.c (graphite_create_new_loop_guard): Use TREE_OVERFLOW_P to test overflow. testsuite: * gcc.dg/graphite/pr46761.c: New. diff --git a/gcc/graphite-clast-to-gimple.c b/gcc/graphite-clast-to-gimple.c index 4894b52..183dde7 100644 --- a/gcc/graphite-clast-to-gimple.c +++ b/gcc/graphite-clast-to-gimple.c @@ -985,7 +985,7 @@ graphite_create_new_loop_guard (sese region, edge entry_edge, : PLUS_EXPR, type, ub, one); /* When ub + 1 wraps around, use lb <= ub. */ - if (integer_zerop (ub_one)) + if (TREE_OVERFLOW_P (ub_one)) cond_expr = fold_build2 (LE_EXPR, boolean_type_node, lb, ub); else cond_expr = fold_build2 (LT_EXPR, boolean_type_node, lb, ub_one); diff --git a/gcc/testsuite/gcc.dg/graphite/pr46761.c b/gcc/testsuite/gcc.dg/graphite/pr46761.c new file mode 100644 index 0000000..f45398a --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/pr46761.c @@ -0,0 +1,22 @@ +/* { dg-do run } */ +/* { dg-options "-O -fgraphite-identity" } */ + +#define N 128 + +int +main () +{ + int arr[N], i, s = 0; + for (i = 0; i < N; i++) + arr[i] = i; + + for (i = 0; i < N; i++) + if (arr[i] != i) + __builtin_abort (); + + for (i = 0; i < N; i++) + s += arr[i]; + if (s != (N * (N - 1)) / 2) + __builtin_abort (); + return 0; +}