diff mbox

[PR46761] graphite: fix testing of boundary wrapping

Message ID alpine.LNX.2.00.1012131624320.5687@monoid.intra.ispras.ru
State New
Headers show

Commit Message

Alexander Monakov Dec. 13, 2010, 1:40 p.m. UTC
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  <amonakov@ispras.ru>

	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.

Comments

Sebastian Pop Dec. 13, 2010, 3:39 p.m. UTC | #1
On Mon, Dec 13, 2010 at 07:40, Alexander Monakov <amonakov@ispras.ru> wrote:
> 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  <amonakov@ispras.ru>
>
>        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.
>

Ok.  Thanks for fixing this,
Sebastian
Richard Biener Dec. 13, 2010, 5:14 p.m. UTC | #2
2010/12/13 Sebastian Pop <sebpop@gmail.com>:
> On Mon, Dec 13, 2010 at 07:40, Alexander Monakov <amonakov@ispras.ru> wrote:
>> 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  <amonakov@ispras.ru>
>>
>>        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.
>>
>
> Ok.  Thanks for fixing this,

Hmm, I don't like new uses of TREE_OVERFLOW checking.  And for
unsigned types it won't be set anyway.

Richard.

> Sebastian
>
diff mbox

Patch

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;
+}